widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #07234
[Merge] lp:~widelands-dev/widelands/bug-1545243-plnum-lua into lp:widelands
GunChleoc has proposed merging lp:~widelands-dev/widelands/bug-1545243-plnum-lua into lp:widelands.
Commit message:
Some data type improvements:
- Fixed PlayerNumber datatype in Lua interface.
- New named datatype "Quantity" for ware/worker quantity.
- More consistent use of DescriptionIndex and ResourceAmount.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1545243 in widelands: "Change player number datatype in scripting/lua_game"
https://bugs.launchpad.net/widelands/+bug/1545243
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1545243-plnum-lua/+merge/291481
See commit message.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1545243-plnum-lua into lp:widelands.
=== modified file 'src/ai/ai_help_structs.cc'
--- src/ai/ai_help_structs.cc 2016-04-01 07:38:04 +0000
+++ src/ai/ai_help_structs.cc 2016-04-11 06:48:15 +0000
@@ -136,7 +136,7 @@
// Looking only for mines-capable fields nearby
// of specific type
-FindNodeMineable::FindNodeMineable(Game& g, int32_t r) : game(g), res(r) {}
+FindNodeMineable::FindNodeMineable(Game& g, DescriptionIndex r) : game(g), res(r) {}
bool FindNodeMineable::accept(const Map&, const FCoords& fc) const {
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h 2016-04-01 08:50:56 +0000
+++ src/ai/ai_help_structs.h 2016-04-11 06:48:15 +0000
@@ -154,7 +154,7 @@
// Looking only for mines-capable fields nearby
// of specific type
struct FindNodeMineable {
- FindNodeMineable(Game& g, int32_t r);
+ FindNodeMineable(Game& g, DescriptionIndex r);
bool accept(const Map&, const FCoords& fc) const;
@@ -245,7 +245,7 @@
int16_t distant_water;
int8_t fish_nearby;
int8_t critters_nearby;
- int8_t ground_water; // used by wells
+ ResourceAmount ground_water; // used by wells
uint8_t space_consumers_nearby;
uint8_t rangers_nearby;
// to manage the military better following variables exists:
@@ -346,7 +346,7 @@
uint16_t unconnected_count; // to any warehouse (count of such buildings)
- int32_t mines; // type of resource it mines_
+ DescriptionIndex mines; // type of resource it mines_
uint16_t mines_percent; // % of res it can mine
uint32_t current_stats;
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2016-04-01 12:22:09 +0000
+++ src/ai/defaultai.cc 2016-04-11 06:48:15 +0000
@@ -4572,8 +4572,8 @@
if (other_player_accessible(
vision + 4, &unused1, &unused2, ms->get_position(), WalkSearch::kEnemy)) {
- uint32_t const total_capacity = ms->max_soldier_capacity();
- uint32_t const target_capacity = ms->soldier_capacity();
+ Quantity const total_capacity = ms->max_soldier_capacity();
+ Quantity const target_capacity = ms->soldier_capacity();
game().send_player_change_soldier_capacity(*ms, total_capacity - target_capacity);
changed = true;
=== modified file 'src/economy/economy.cc'
--- src/economy/economy.cc 2016-04-01 08:08:24 +0000
+++ src/economy/economy.cc 2016-04-11 06:48:15 +0000
@@ -333,7 +333,7 @@
*/
void Economy::set_ware_target_quantity
(DescriptionIndex const ware_type,
- uint32_t const permanent,
+ Quantity const permanent,
Time const mod_time)
{
TargetQuantity & tq = ware_target_quantities_[ware_type];
@@ -344,7 +344,7 @@
void Economy::set_worker_target_quantity
(DescriptionIndex const ware_type,
- uint32_t const permanent,
+ Quantity const permanent,
Time const mod_time)
{
TargetQuantity & tq = worker_target_quantities_[ware_type];
@@ -359,14 +359,14 @@
* This is also called when a ware is added to the economy through trade or
* a merger.
*/
-void Economy::add_wares(DescriptionIndex const id, uint32_t const count)
+void Economy::add_wares(DescriptionIndex const id, Quantity const count)
{
wares_.add(id, count);
start_request_timer();
// TODO(unknown): add to global player inventory?
}
-void Economy::add_workers(DescriptionIndex const id, uint32_t const count)
+void Economy::add_workers(DescriptionIndex const id, Quantity const count)
{
workers_.add(id, count);
start_request_timer();
@@ -380,7 +380,7 @@
* This is also called when a ware is removed from the economy through trade or
* a split of the Economy.
*/
-void Economy::remove_wares(DescriptionIndex const id, uint32_t const count)
+void Economy::remove_wares(DescriptionIndex const id, Quantity const count)
{
assert(owner_.egbase().tribes().ware_exists(id));
wares_.remove(id, count);
@@ -393,7 +393,7 @@
* This is also called when a worker is removed from the economy through
* a split of the Economy.
*/
-void Economy::remove_workers(DescriptionIndex const id, uint32_t const count)
+void Economy::remove_workers(DescriptionIndex const id, Quantity const count)
{
workers_.remove(id, count);
@@ -497,11 +497,11 @@
bool Economy::needs_ware(DescriptionIndex const ware_type) const {
- uint32_t const t = ware_target_quantity(ware_type).permanent;
+ Quantity const t = ware_target_quantity(ware_type).permanent;
// we have a target quantity set
if (t > 0) {
- uint32_t quantity = 0;
+ Quantity quantity = 0;
for (const Warehouse * wh : warehouses_) {
quantity += wh->get_wares().stock(ware_type);
if (t <= quantity)
@@ -523,11 +523,11 @@
bool Economy::needs_worker(DescriptionIndex const worker_type) const {
- uint32_t const t = worker_target_quantity(worker_type).permanent;
+ Quantity const t = worker_target_quantity(worker_type).permanent;
// we have a target quantity set
if (t > 0) {
- uint32_t quantity = 0;
+ Quantity quantity = 0;
for (const Warehouse * wh : warehouses_) {
quantity += wh->get_workers().stock(worker_type);
if (t <= quantity)
@@ -917,8 +917,8 @@
// Find warehouses where we can create the required workers,
// and collect stats about existing build prerequisites
const WorkerDescr::Buildcost & cost = w_desc.buildcost();
- std::vector<uint32_t> total_available;
- uint32_t total_planned = 0;
+ std::vector<Quantity> total_available;
+ Quantity total_planned = 0;
total_available.insert(total_available.begin(), cost.size(), 0);
@@ -934,11 +934,11 @@
return;
}
- std::vector<uint32_t> wh_available =
+ std::vector<Quantity> wh_available =
wh->calc_available_for_worker(game, index);
assert(wh_available.size() == total_available.size());
- for (uint32_t idx = 0; idx < total_available.size(); ++idx)
+ for (Quantity idx = 0; idx < total_available.size(); ++idx)
total_available[idx] += wh_available[idx];
}
=== modified file 'src/economy/economy.h'
--- src/economy/economy.h 2016-02-09 16:29:48 +0000
+++ src/economy/economy.h 2016-04-11 06:48:15 +0000
@@ -89,7 +89,7 @@
/// economies are merged. The setting that was modified most recently will
/// be used for the merged economy.
struct TargetQuantity {
- uint32_t permanent;
+ Quantity permanent;
Time last_modified;
};
@@ -121,14 +121,14 @@
// (i.e. an Expedition ship).
Flag* get_arbitrary_flag();
- void set_ware_target_quantity (DescriptionIndex, uint32_t, Time);
- void set_worker_target_quantity(DescriptionIndex, uint32_t, Time);
-
- void add_wares (DescriptionIndex, uint32_t count = 1);
- void remove_wares (DescriptionIndex, uint32_t count = 1);
-
- void add_workers(DescriptionIndex, uint32_t count = 1);
- void remove_workers(DescriptionIndex, uint32_t count = 1);
+ void set_ware_target_quantity (DescriptionIndex, Quantity, Time);
+ void set_worker_target_quantity(DescriptionIndex, Quantity, Time);
+
+ void add_wares (DescriptionIndex, Quantity count = 1);
+ void remove_wares (DescriptionIndex, Quantity count = 1);
+
+ void add_workers(DescriptionIndex, Quantity count = 1);
+ void remove_workers(DescriptionIndex, Quantity count = 1);
void add_warehouse(Warehouse &);
void remove_warehouse(Warehouse &);
@@ -141,10 +141,10 @@
void remove_supply(Supply &);
/// information about this economy
- WareList::WareCount stock_ware (DescriptionIndex const i) {
+ Quantity stock_ware (DescriptionIndex const i) {
return wares_ .stock(i);
}
- WareList::WareCount stock_worker(DescriptionIndex const i) {
+ Quantity stock_worker(DescriptionIndex const i) {
return workers_.stock(i);
}
=== modified file 'src/economy/request.h'
--- src/economy/request.h 2016-02-07 06:10:47 +0000
+++ src/economy/request.h 2016-04-11 06:48:15 +0000
@@ -72,7 +72,7 @@
PlayerImmovable & target() const {return target_;}
DescriptionIndex get_index() const {return index_;}
WareWorker get_type() const {return type_;}
- uint32_t get_count() const {return count_;}
+ Quantity get_count() const {return count_;}
uint32_t get_open_count() const {return count_ - transfers_.size();}
bool is_open() const {return transfers_.size() < count_;}
Economy * get_economy() const {return economy_;}
@@ -85,7 +85,7 @@
Flag & target_flag() const;
void set_economy(Economy *);
- void set_count(uint32_t);
+ void set_count(Quantity);
void set_required_time(int32_t time);
void set_required_interval(int32_t interval);
@@ -127,7 +127,7 @@
Economy * economy_;
DescriptionIndex index_; // the index of the ware descr
- uint32_t count_; // how many do we need in total
+ Quantity count_; // how many do we need in total
CallbackFn callbackfn_; // called on request success
=== modified file 'src/economy/warehousesupply.h'
--- src/economy/warehousesupply.h 2016-02-07 06:10:47 +0000
+++ src/economy/warehousesupply.h 2016-04-11 06:48:15 +0000
@@ -41,16 +41,16 @@
const WareList & get_wares () const {return wares_;}
const WareList & get_workers() const {return workers_;}
- uint32_t stock_wares (DescriptionIndex const i) const {
+ Quantity stock_wares (DescriptionIndex const i) const {
return wares_ .stock(i);
}
- uint32_t stock_workers(DescriptionIndex const i) const {
+ Quantity stock_workers(DescriptionIndex const i) const {
return workers_.stock(i);
}
- void add_wares (DescriptionIndex, uint32_t count);
- void remove_wares (DescriptionIndex, uint32_t count);
- void add_workers (DescriptionIndex, uint32_t count);
- void remove_workers(DescriptionIndex, uint32_t count);
+ void add_wares (DescriptionIndex, Quantity count);
+ void remove_wares (DescriptionIndex, Quantity count);
+ void add_workers (DescriptionIndex, Quantity count);
+ void remove_workers(DescriptionIndex, Quantity count);
// Supply implementation
PlayerImmovable * get_position(Game &) override;
=== modified file 'src/economy/wares_queue.cc'
--- src/economy/wares_queue.cc 2016-02-09 16:29:48 +0000
+++ src/economy/wares_queue.cc 2016-04-11 06:48:15 +0000
@@ -171,9 +171,9 @@
/**
* Change size of the queue.
*/
-void WaresQueue::set_max_size(const uint32_t size)
+void WaresQueue::set_max_size(const Quantity size)
{
- uint32_t old_size = max_size_;
+ Quantity old_size = max_size_;
max_size_ = size;
// make sure that max fill is reduced as well if the max size is decreased
@@ -192,7 +192,7 @@
* but if there are more wares than that in the queue, they will not get
* lost (the building should drop them).
*/
-void WaresQueue::set_max_fill(uint32_t size)
+void WaresQueue::set_max_fill(Quantity size)
{
if (size > max_size_)
size = max_size_;
@@ -205,7 +205,7 @@
/**
* Change fill status of the queue.
*/
-void WaresQueue::set_filled(const uint32_t filled) {
+void WaresQueue::set_filled(const Quantity filled) {
if (owner_.get_economy()) {
if (filled > filled_)
owner_.get_economy()->add_wares(ware_, filled - filled_);
=== modified file 'src/economy/wares_queue.h'
--- src/economy/wares_queue.h 2016-02-07 06:10:47 +0000
+++ src/economy/wares_queue.h 2016-04-11 06:48:15 +0000
@@ -49,9 +49,9 @@
#endif
DescriptionIndex get_ware() const {return ware_;}
- uint32_t get_max_fill() const {return max_fill_;}
- uint32_t get_max_size() const {return max_size_;}
- uint32_t get_filled() const {return filled_;}
+ Quantity get_max_fill() const {return max_fill_;}
+ Quantity get_max_size() const {return max_size_;}
+ Quantity get_filled() const {return filled_;}
void cleanup();
@@ -60,9 +60,9 @@
void remove_from_economy(Economy &);
void add_to_economy(Economy &);
- void set_max_size (uint32_t);
- void set_max_fill (uint32_t);
- void set_filled (uint32_t);
+ void set_max_size (Quantity);
+ void set_max_fill (Quantity);
+ void set_filled (Quantity);
void set_consume_interval(uint32_t);
Player & owner() const {return owner_.owner();}
@@ -77,9 +77,9 @@
PlayerImmovable & owner_;
DescriptionIndex ware_; ///< ware ID
- uint32_t max_size_; ///< nr of items that fit into the queue maximum
- uint32_t max_fill_; ///< nr of wares that should be ideally in this queue
- uint32_t filled_; ///< nr of items that are currently in the queue
+ Quantity max_size_; ///< nr of items that fit into the queue maximum
+ Quantity max_fill_; ///< nr of wares that should be ideally in this queue
+ Quantity filled_; ///< nr of items that are currently in the queue
///< time in ms between consumption at full speed
uint32_t consume_interval_;
=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc 2016-04-06 09:23:04 +0000
+++ src/editor/map_generator.cc 2016-04-11 06:48:15 +0000
@@ -130,9 +130,9 @@
const auto set_resource_helper = [this, &world, &terrain_description, &fc] (
const uint32_t random_value, const int valid_resource_index) {
const DescriptionIndex res_idx = terrain_description.get_valid_resource(valid_resource_index);
- const uint32_t max_amount = world.get_resource(res_idx)->max_amount();
- uint8_t res_val = static_cast<uint8_t>(random_value / (kMaxElevation / max_amount));
- res_val *= static_cast<uint8_t>(map_info_.resource_amount) + 1;
+ const ResourceAmount max_amount = world.get_resource(res_idx)->max_amount();
+ ResourceAmount res_val = static_cast<ResourceAmount>(random_value / (kMaxElevation / max_amount));
+ res_val *= static_cast<ResourceAmount>(map_info_.resource_amount) + 1;
res_val /= 3;
if (map_.is_resource_valid(world, fc, res_idx)) {
map_.initialize_resources(fc, res_idx, res_val);
=== modified file 'src/editor/tools/action_args.h'
--- src/editor/tools/action_args.h 2016-04-06 09:23:04 +0000
+++ src/editor/tools/action_args.h 2016-04-11 06:48:15 +0000
@@ -50,18 +50,19 @@
int32_t change_by; // resources, change height tools
std::list<Widelands::Field::Height> original_heights; // change height tool
- uint8_t current_resource, set_to; // resources change tools
+ Widelands::DescriptionIndex current_resource; // resources change tools
+ Widelands::ResourceAmount set_to; // resources change tools
struct ResourceState {
Widelands::FCoords location;
- uint8_t idx;
- uint8_t amount;
+ Widelands::DescriptionIndex idx;
+ Widelands::ResourceAmount amount;
};
std::list<ResourceState> original_resource; // resources set tool
std::list<const Widelands::BobDescr *> old_bob_type, new_bob_type; // bob change tools
std::list<std::string> old_immovable_types; // immovable change tools
- std::list<int32_t> new_immovable_types; // immovable change tools
+ std::list<Widelands::DescriptionIndex> new_immovable_types; // immovable change tools
Widelands::HeightInterval interval; // noise height tool
std::list<Widelands::DescriptionIndex> terrain_type, original_terrain_type; // set terrain tool
=== modified file 'src/editor/tools/decrease_resources_tool.cc'
--- src/editor/tools/decrease_resources_tool.cc 2016-04-06 09:23:04 +0000
+++ src/editor/tools/decrease_resources_tool.cc 2016-04-11 06:48:15 +0000
@@ -44,11 +44,9 @@
Widelands::Area<Widelands::FCoords>
(map->get_fcoords(center.node), args->sel_radius));
do {
- int32_t amount = mr.location().field->get_resources_amount();
+ Widelands::ResourceAmount amount = mr.location().field->get_resources_amount();
- amount -= args->change_by;
- if (amount < 0)
- amount = 0;
+ amount = (amount > args->change_by) ? amount - args->change_by : 0;
if (mr.location().field->get_resources() == args->current_resource &&
map->is_resource_valid(world, mr.location(), args->current_resource) &&
=== modified file 'src/editor/tools/increase_resources_tool.cc'
--- src/editor/tools/increase_resources_tool.cc 2016-04-06 09:23:04 +0000
+++ src/editor/tools/increase_resources_tool.cc 2016-04-11 06:48:15 +0000
@@ -39,8 +39,8 @@
Widelands::Area<Widelands::FCoords>
(map->get_fcoords(center.node), args->sel_radius));
do {
- int32_t amount = mr.location().field->get_resources_amount();
- int32_t max_amount = args->current_resource != Widelands::kNoResource ?
+ Widelands::ResourceAmount amount = mr.location().field->get_resources_amount();
+ Widelands::ResourceAmount max_amount = args->current_resource != Widelands::kNoResource ?
world.get_resource(args->current_resource)->max_amount() : 0;
amount += args->change_by;
=== modified file 'src/editor/tools/info_tool.cc'
--- src/editor/tools/info_tool.cc 2016-04-06 09:23:04 +0000
+++ src/editor/tools/info_tool.cc 2016-04-11 06:48:15 +0000
@@ -123,13 +123,14 @@
buf += std::string("\n") + _("Resources:") + "\n";
Widelands::DescriptionIndex ridx = f.get_resources();
- int ramount = f.get_resources_amount();
+ Widelands::ResourceAmount ramount = f.get_resources_amount();
if (ramount > 0) {
buf += "• " + (boost::format(
_("Resource name: %s")) % world.get_resource(ridx)->name().c_str()
).str() + "\n";
- buf += "• " + (boost::format(_("Resource amount: %i")) % ramount).str() + "\n";
+ buf += "• " + (boost::format(_("Resource amount: %i")) % static_cast<unsigned int>(ramount)).str()
+ + "\n";
}
else {
buf += "• " + std::string(_("No resources")) + "\n";
=== modified file 'src/editor/tools/place_immovable_tool.cc'
--- src/editor/tools/place_immovable_tool.cc 2016-04-06 09:23:04 +0000
+++ src/editor/tools/place_immovable_tool.cc 2016-04-11 06:48:15 +0000
@@ -60,7 +60,7 @@
(*map,
Widelands::Area<Widelands::FCoords>
(map->get_fcoords(center.node), radius));
- std::list<int32_t>::iterator i = args->new_immovable_types.begin();
+ std::list<Widelands::DescriptionIndex>::iterator i = args->new_immovable_types.begin();
do {
if
(!mr.location().field->get_immovable()
=== modified file 'src/editor/tools/set_resources_tool.cc'
--- src/editor/tools/set_resources_tool.cc 2016-04-06 09:23:04 +0000
+++ src/editor/tools/set_resources_tool.cc 2016-04-11 06:48:15 +0000
@@ -38,8 +38,8 @@
Widelands::Area<Widelands::FCoords>
(map->get_fcoords(center.node), args->sel_radius));
do {
- int32_t amount = args->set_to;
- int32_t max_amount = args->current_resource != Widelands::kNoResource ?
+ Widelands::ResourceAmount amount = args->set_to;
+ Widelands::ResourceAmount max_amount = args->current_resource != Widelands::kNoResource ?
world.get_resource(args->current_resource)->max_amount() : 0;
if (amount < 0)
amount = 0;
@@ -68,11 +68,9 @@
EditorActionArgs* args,
Widelands::Map* map) {
for (const auto & res : args->original_resource) {
- int32_t amount = res.amount;
- int32_t max_amount = world.get_resource(args->current_resource)->max_amount();
+ Widelands::ResourceAmount amount = res.amount;
+ Widelands::ResourceAmount max_amount = world.get_resource(args->current_resource)->max_amount();
- if (amount < 0)
- amount = 0;
if (amount > max_amount)
amount = max_amount;
=== modified file 'src/editor/tools/set_resources_tool.h'
--- src/editor/tools/set_resources_tool.h 2016-04-06 09:23:04 +0000
+++ src/editor/tools/set_resources_tool.h 2016-04-11 06:48:15 +0000
@@ -51,15 +51,15 @@
return "images/wui/editor/fsel_editor_set_resources.png";
}
- uint8_t get_set_to() const {return set_to_;}
- void set_set_to(uint8_t const n) {set_to_ = n;}
+ Widelands::ResourceAmount get_set_to() const {return set_to_;}
+ void set_set_to(Widelands::ResourceAmount const n) {set_to_ = n;}
Widelands::DescriptionIndex get_cur_res() const {return cur_res_;}
void set_cur_res(Widelands::DescriptionIndex const res)
{cur_res_ = res;}
private:
Widelands::DescriptionIndex cur_res_;
- uint8_t set_to_;
+ Widelands::ResourceAmount set_to_;
};
=== modified file 'src/logic/editor_game_base.cc'
--- src/logic/editor_game_base.cc 2016-03-19 11:47:00 +0000
+++ src/logic/editor_game_base.cc 2016-04-11 06:48:15 +0000
@@ -349,7 +349,7 @@
===============
*/
Immovable & EditorGameBase::create_immovable
- (Coords const c, uint32_t const idx, MapObjectDescr::OwnerType type)
+ (Coords const c, DescriptionIndex const idx, MapObjectDescr::OwnerType type)
{
const ImmovableDescr & descr =
*
=== modified file 'src/logic/editor_game_base.h'
--- src/logic/editor_game_base.h 2016-03-19 11:47:00 +0000
+++ src/logic/editor_game_base.h 2016-04-11 06:48:15 +0000
@@ -141,7 +141,7 @@
Bob& create_critter(Coords, DescriptionIndex bob_type_idx, Player* owner = nullptr);
Bob& create_critter(Coords, const std::string& name, Player* owner = nullptr);
Immovable& create_immovable(Coords,
- uint32_t idx,
+ DescriptionIndex idx,
MapObjectDescr::OwnerType = MapObjectDescr::OwnerType::kWorld);
Immovable& create_immovable(Coords,
const std::string& name,
=== modified file 'src/logic/field.h'
--- src/logic/field.h 2016-02-15 23:26:42 +0000
+++ src/logic/field.h 2016-04-11 06:48:15 +0000
@@ -156,10 +156,10 @@
// Resources can be set through Map::set_resources()
// TODO(unknown): This should return DescriptionIndex
- uint8_t get_resources() const {return resources;}
- uint8_t get_resources_amount() const {return res_amount;}
+ DescriptionIndex get_resources() const {return resources;}
+ ResourceAmount get_resources_amount() const {return res_amount;}
// TODO(unknown): This should return uint8_t
- int32_t get_initial_res_amount() const {return initial_res_amount;}
+ ResourceAmount get_initial_res_amount() const {return initial_res_amount;}
/// \note you must reset this field's + neighbor's brightness when you
/// change the height. Map::change_height does this. This function is not
@@ -212,8 +212,8 @@
OwnerInfoAndSelectionsType owner_info_and_selections;
DescriptionIndex resources; ///< Resource type on this field, if any
- uint8_t initial_res_amount; ///< Initial amount of resources
- uint8_t res_amount; ///< Current amount of resources
+ ResourceAmount initial_res_amount; ///< Initial amount of resources
+ ResourceAmount res_amount; ///< Current amount of resources
Terrains terrains;
};
=== modified file 'src/logic/findnode.h'
--- src/logic/findnode.h 2016-02-16 13:15:29 +0000
+++ src/logic/findnode.h 2016-04-11 06:48:15 +0000
@@ -24,6 +24,8 @@
#include <stdint.h>
+#include "logic/widelands.h"
+
namespace Widelands {
struct FCoords;
@@ -161,23 +163,23 @@
/// Accepts a node if it has at least one of the given resource.
struct FindNodeResource {
- FindNodeResource(uint8_t res) : resource(res) {}
+ FindNodeResource(DescriptionIndex res) : resource(res) {}
bool accept(const Map &, const FCoords &) const;
private:
- uint8_t resource;
+ DescriptionIndex resource;
};
/// Accepts a node if it has the given resource type and remaining capacity.
struct FindNodeResourceBreedable {
- FindNodeResourceBreedable(uint8_t res) : resource(res) {}
+ FindNodeResourceBreedable(DescriptionIndex res) : resource(res) {}
bool accept(const Map &, const FCoords &) const;
private:
- uint8_t resource;
+ DescriptionIndex resource;
};
/// Accepts a node if it is a shore node in the sense that it is walkable
=== modified file 'src/logic/map.cc'
--- src/logic/map.cc 2016-04-06 09:23:04 +0000
+++ src/logic/map.cc 2016-04-11 06:48:15 +0000
@@ -172,7 +172,7 @@
if (f.field->get_resources() != Widelands::kNoResource || f.field->get_resources_amount())
continue;
std::map<int32_t, int32_t> m;
- int32_t amount = 0;
+ ResourceAmount amount = 0;
// this node
{
@@ -192,8 +192,8 @@
get_neighbour(f, WALK_NW, &f1);
{
const TerrainDescription& terr = world.terrain_descr(f1.field->terrain_r());
- const int8_t resr = terr.get_default_resource();
- const int default_amount = terr.get_default_resource_amount();
+ const DescriptionIndex resr = terr.get_default_resource();
+ const ResourceAmount default_amount = terr.get_default_resource_amount();
if ((terr.get_is() & TerrainDescription::Is::kUnwalkable) && default_amount > 0)
m[resr] += 3;
else
@@ -202,8 +202,8 @@
}
{
const TerrainDescription& terd = world.terrain_descr(f1.field->terrain_d());
- const int8_t resd = terd.get_default_resource();
- const int default_amount = terd.get_default_resource_amount();
+ const DescriptionIndex resd = terd.get_default_resource();
+ const ResourceAmount default_amount = terd.get_default_resource_amount();
if ((terd.get_is() & TerrainDescription::Is::kUnwalkable) && default_amount > 0)
m[resd] += 3;
else
@@ -215,8 +215,8 @@
get_neighbour(f, WALK_NE, &f1);
{
const TerrainDescription& terd = world.terrain_descr(f1.field->terrain_d());
- const int8_t resd = terd.get_default_resource();
- const int default_amount = terd.get_default_resource_amount();
+ const DescriptionIndex resd = terd.get_default_resource();
+ const ResourceAmount default_amount = terd.get_default_resource_amount();
if ((terd.get_is() & TerrainDescription::Is::kUnwalkable) && default_amount > 0)
m[resd] += 3;
else
@@ -228,8 +228,8 @@
get_neighbour(f, WALK_W, &f1);
{
const TerrainDescription& terr = world.terrain_descr(f1.field->terrain_r());
- const int8_t resr = terr.get_default_resource();
- const int default_amount = terr.get_default_resource_amount();
+ const DescriptionIndex resr = terr.get_default_resource();
+ const ResourceAmount default_amount = terr.get_default_resource_amount();
if ((terr.get_is() & TerrainDescription::Is::kUnwalkable) && default_amount > 0)
m[resr] += 3;
else
@@ -1869,7 +1869,7 @@
}
bool Map::is_resource_valid
- (const Widelands::World& world, const TCoords<Widelands::FCoords>& c, int32_t const curres)
+ (const Widelands::World& world, const TCoords<Widelands::FCoords>& c, DescriptionIndex curres)
{
if (curres == Widelands::kNoResource)
return true;
@@ -1912,7 +1912,7 @@
void Map::initialize_resources(const FCoords& c,
const DescriptionIndex resource_type,
- uint8_t amount) {
+ ResourceAmount amount) {
// You cannot have an amount of nothing.
if (resource_type == Widelands::kNoResource) {
amount = 0;
@@ -1927,7 +1927,7 @@
Notifications::publish(note);
}
-void Map::set_resources(const FCoords& c, uint8_t amount) {
+void Map::set_resources(const FCoords& c, ResourceAmount amount) {
// You cannot change the amount of resources on a field without resources.
if (c.field->resources == Widelands::kNoResource) {
return;
=== modified file 'src/logic/map.h'
--- src/logic/map.h 2016-04-01 12:22:09 +0000
+++ src/logic/map.h 2016-04-11 06:48:15 +0000
@@ -82,8 +82,8 @@
FCoords fc;
DescriptionIndex old_resource;
- uint8_t old_initial_amount;
- uint8_t old_amount;
+ ResourceAmount old_initial_amount;
+ ResourceAmount old_amount;
};
struct ImmovableFound {
@@ -369,11 +369,11 @@
/// Initializes the 'initial_resources' on 'coords' to the 'resource_type'
/// with the given 'amount'.
- void initialize_resources(const FCoords& coords, DescriptionIndex resource_type, uint8_t amount);
+ void initialize_resources(const FCoords& coords, DescriptionIndex resource_type, ResourceAmount amount);
/// Sets the number of resources of the field to 'amount'. The type of the
/// resource on this field is not changed.
- void set_resources(const FCoords& coords, uint8_t amount);
+ void set_resources(const FCoords& coords, ResourceAmount amount);
/// Clears the resources, i.e. the amount will be set to 0 and the type of
/// resources will be kNoResource.
@@ -410,7 +410,7 @@
*/
bool is_resource_valid
(const Widelands::World& world, const Widelands::TCoords<Widelands::FCoords>& c,
- int32_t const curres);
+ DescriptionIndex curres);
// The objectives that are defined in this map if it is a scenario.
const Objectives& objectives() const {
=== modified file 'src/logic/map_objects/tribes/bill_of_materials.h'
--- src/logic/map_objects/tribes/bill_of_materials.h 2016-02-04 17:49:51 +0000
+++ src/logic/map_objects/tribes/bill_of_materials.h 2016-04-11 06:48:15 +0000
@@ -25,7 +25,7 @@
#include "logic/widelands.h"
namespace Widelands {
-using WareAmount = std::pair<DescriptionIndex, uint32_t>;
+using WareAmount = std::pair<DescriptionIndex, Widelands::Quantity>;
using BillOfMaterials = std::vector<WareAmount>;
// range structure for iterating ware range with index
=== modified file 'src/logic/map_objects/tribes/militarysite.cc'
--- src/logic/map_objects/tribes/militarysite.cc 2016-03-29 10:04:48 +0000
+++ src/logic/map_objects/tribes/militarysite.cc 2016-04-11 06:48:15 +0000
@@ -117,8 +117,8 @@
void MilitarySite::update_statistics_string(std::string* s)
{
s->clear();
- uint32_t present = present_soldiers().size();
- uint32_t stationed = stationed_soldiers().size();
+ Quantity present = present_soldiers().size();
+ Quantity stationed = stationed_soldiers().size();
if (present == stationed) {
if (capacity_ > stationed) {
@@ -400,7 +400,7 @@
void MilitarySite::update_normal_soldier_request()
{
std::vector<Soldier *> present = present_soldiers();
- uint32_t const stationed = stationed_soldiers().size();
+ Quantity const stationed = stationed_soldiers().size();
if (stationed < capacity_) {
if (!normal_soldier_request_) {
@@ -718,13 +718,13 @@
return soldiers;
}
-uint32_t MilitarySite::min_soldier_capacity() const {
+Quantity MilitarySite::min_soldier_capacity() const {
return 1;
}
-uint32_t MilitarySite::max_soldier_capacity() const {
+Quantity MilitarySite::max_soldier_capacity() const {
return descr().get_max_number_of_soldiers();
}
-uint32_t MilitarySite::soldier_capacity() const
+Quantity MilitarySite::soldier_capacity() const
{
return capacity_;
}
=== modified file 'src/logic/map_objects/tribes/militarysite.h'
--- src/logic/map_objects/tribes/militarysite.h 2016-02-08 17:25:17 +0000
+++ src/logic/map_objects/tribes/militarysite.h 2016-04-11 06:48:15 +0000
@@ -43,7 +43,7 @@
Building & create_object() const override;
uint32_t get_conquers() const override {return conquer_radius_;}
- uint32_t get_max_number_of_soldiers () const {
+ Quantity get_max_number_of_soldiers () const {
return num_soldiers_;
}
uint32_t get_heal_per_second () const {
@@ -60,7 +60,7 @@
private:
uint32_t conquer_radius_;
- uint32_t num_soldiers_;
+ Quantity num_soldiers_;
uint32_t heal_per_second_;
DISALLOW_COPY_AND_ASSIGN(MilitarySiteDescr);
};
@@ -93,10 +93,10 @@
// Begin implementation of SoldierControl
std::vector<Soldier *> present_soldiers() const override;
std::vector<Soldier *> stationed_soldiers() const override;
- uint32_t min_soldier_capacity() const override;
- uint32_t max_soldier_capacity() const override;
- uint32_t soldier_capacity() const override;
- void set_soldier_capacity(uint32_t capacity) override;
+ Quantity min_soldier_capacity() const override;
+ Quantity max_soldier_capacity() const override;
+ Quantity soldier_capacity() const override;
+ void set_soldier_capacity(Quantity capacity) override;
void drop_soldier(Soldier &) override;
int incorporate_soldier(EditorGameBase & game, Soldier & s) override;
@@ -158,7 +158,7 @@
std::unique_ptr<Request> normal_soldier_request_; // filling the site
std::unique_ptr<Request> upgrade_soldier_request_; // seeking for better soldiers
bool didconquer_;
- uint32_t capacity_;
+ Quantity capacity_;
/**
* Next gametime where we should heal something.
=== modified file 'src/logic/map_objects/tribes/production_program.cc'
--- src/logic/map_objects/tribes/production_program.cc 2016-04-05 07:51:48 +0000
+++ src/logic/map_objects/tribes/production_program.cc 2016-04-11 06:48:15 +0000
@@ -1243,9 +1243,9 @@
MapRegion<Area<FCoords> > mr
(map, Area<FCoords> (map.get_fcoords(ps.get_position()), distance_));
do {
- uint8_t fres = mr.location().field->get_resources();
- uint32_t amount = mr.location().field->get_resources_amount();
- uint32_t start_amount =
+ DescriptionIndex fres = mr.location().field->get_resources();
+ ResourceAmount amount = mr.location().field->get_resources_amount();
+ ResourceAmount start_amount =
mr.location().field->get_initial_res_amount();
if (fres != resource_) {
@@ -1291,8 +1291,8 @@
(map,
Area<FCoords>(map.get_fcoords(ps.get_position()), distance_));
do {
- uint8_t fres = mr.location().field->get_resources();
- uint32_t amount = mr.location().field->get_resources_amount();
+ DescriptionIndex fres = mr.location().field->get_resources();
+ ResourceAmount amount = mr.location().field->get_resources_amount();
if (fres != resource_)
amount = 0;
=== modified file 'src/logic/map_objects/tribes/ship.h'
--- src/logic/map_objects/tribes/ship.h 2016-03-19 12:51:22 +0000
+++ src/logic/map_objects/tribes/ship.h 2016-04-11 06:48:15 +0000
@@ -67,11 +67,11 @@
uint32_t movecaps() const override;
const DirAnimations & get_sail_anims() const {return sail_anims_;}
- uint32_t get_capacity() const {return capacity_;}
+ Quantity get_capacity() const {return capacity_;}
private:
DirAnimations sail_anims_;
- uint32_t capacity_;
+ Quantity capacity_;
DISALLOW_COPY_AND_ASSIGN(ShipDescr);
};
=== modified file 'src/logic/map_objects/tribes/soldiercontrol.h'
--- src/logic/map_objects/tribes/soldiercontrol.h 2015-11-28 22:29:26 +0000
+++ src/logic/map_objects/tribes/soldiercontrol.h 2016-04-11 06:48:15 +0000
@@ -22,6 +22,8 @@
#include <vector>
+#include "logic/widelands.h"
+
namespace Widelands {
class EditorGameBase;
@@ -54,19 +56,19 @@
* \return the minimum number of soldiers that this building can be
* configured to hold.
*/
- virtual uint32_t min_soldier_capacity() const = 0;
+ virtual Quantity min_soldier_capacity() const = 0;
/**
* \return the maximum number of soldiers that this building can be
* configured to hold.
*/
- virtual uint32_t max_soldier_capacity() const = 0;
+ virtual Quantity max_soldier_capacity() const = 0;
/**
* \return the number of soldiers this building is configured to hold
* right now.
*/
- virtual uint32_t soldier_capacity() const = 0;
+ virtual Quantity soldier_capacity() const = 0;
/**
* Sets the capacity for soldiers of this building.
@@ -74,13 +76,13 @@
* New soldiers will be requested and old soldiers will be evicted
* as necessary.
*/
- virtual void set_soldier_capacity(uint32_t capacity) = 0;
+ virtual void set_soldier_capacity(Quantity capacity) = 0;
void changeSoldierCapacity(int32_t const difference) {
- uint32_t const old_capacity = soldier_capacity();
- uint32_t const new_capacity =
+ Widelands::Quantity const old_capacity = soldier_capacity();
+ Widelands::Quantity const new_capacity =
std::min
- (static_cast<uint32_t>
+ (static_cast<Widelands::Quantity>
(std::max
(static_cast<int32_t>(old_capacity) + difference,
static_cast<int32_t>(min_soldier_capacity()))),
=== modified file 'src/logic/map_objects/tribes/trainingsite.cc'
--- src/logic/map_objects/tribes/trainingsite.cc 2016-04-01 07:43:42 +0000
+++ src/logic/map_objects/tribes/trainingsite.cc 2016-04-11 06:48:15 +0000
@@ -419,18 +419,18 @@
return soldiers_;
}
-uint32_t TrainingSite::min_soldier_capacity() const {
+Quantity TrainingSite::min_soldier_capacity() const {
return 0;
}
-uint32_t TrainingSite::max_soldier_capacity() const {
+Quantity TrainingSite::max_soldier_capacity() const {
return descr().get_max_number_of_soldiers();
}
-uint32_t TrainingSite::soldier_capacity() const
+Quantity TrainingSite::soldier_capacity() const
{
return capacity_;
}
-void TrainingSite::set_soldier_capacity(uint32_t const capacity) {
+void TrainingSite::set_soldier_capacity(Quantity const capacity) {
assert(min_soldier_capacity() <= capacity);
assert (capacity <= max_soldier_capacity());
assert(capacity_ != capacity);
=== modified file 'src/logic/map_objects/tribes/trainingsite.h'
--- src/logic/map_objects/tribes/trainingsite.h 2016-02-17 22:13:21 +0000
+++ src/logic/map_objects/tribes/trainingsite.h 2016-04-11 06:48:15 +0000
@@ -38,7 +38,7 @@
Building & create_object() const override;
- uint32_t get_max_number_of_soldiers() const {
+ Quantity get_max_number_of_soldiers() const {
return num_soldiers_;
}
bool get_train_health () const {return train_health_;}
@@ -85,7 +85,7 @@
// struct and there should be a vector, indexed by Soldier_Index,
// with that struct structs as element type.
/** Maximum number of soldiers for a training site*/
- uint32_t num_soldiers_;
+ Quantity num_soldiers_;
/** Number of rounds w/o successful training, after which a soldier is kicked out.**/
uint32_t max_stall_;
/** Whether this site can train health*/
@@ -180,10 +180,10 @@
// Begin implementation of SoldierControl
std::vector<Soldier *> present_soldiers() const override;
std::vector<Soldier *> stationed_soldiers() const override;
- uint32_t min_soldier_capacity() const override;
- uint32_t max_soldier_capacity() const override;
- uint32_t soldier_capacity() const override;
- void set_soldier_capacity(uint32_t capacity) override;
+ Quantity min_soldier_capacity() const override;
+ Quantity max_soldier_capacity() const override;
+ Quantity soldier_capacity() const override;
+ void set_soldier_capacity(Quantity capacity) override;
void drop_soldier(Soldier &) override;
int incorporate_soldier(EditorGameBase &, Soldier &) override;
// End implementation of SoldierControl
@@ -226,7 +226,7 @@
* There is no guarantee there really are capacity_ soldiers in the
* building - some of them might still be under way or even not yet
* available*/
- uint32_t capacity_;
+ Quantity capacity_;
/** True, \b always upgrade already experienced soldiers first, when possible
* False, \b always upgrade inexperienced soldiers first, when possible */
=== modified file 'src/logic/map_objects/tribes/tribe_descr.cc'
--- src/logic/map_objects/tribes/tribe_descr.cc 2016-03-08 21:14:48 +0000
+++ src/logic/map_objects/tribes/tribe_descr.cc 2016-04-11 06:48:15 +0000
@@ -339,7 +339,7 @@
==============
*/
DescriptionIndex TribeDescr::get_resource_indicator
- (ResourceDescription const * const res, uint32_t const amount) const {
+ (ResourceDescription const * const res, const ResourceAmount amount) const {
if (!res || !amount) {
DescriptionIndex idx = immovable_index("resi_none");
if (!has_immovable(idx)) {
@@ -363,8 +363,8 @@
throw GameDataError("There is no resource indicator for resource %s", res->name().c_str());
}
- int32_t bestmatch =
- static_cast<int32_t>
+ ResourceAmount bestmatch =
+ static_cast<ResourceAmount>
((static_cast<float>(amount) / res->max_amount())
*
num_indicators);
@@ -372,10 +372,10 @@
throw GameDataError
("Amount of %s is %i but max amount is %i",
res->name().c_str(),
- amount,
- res->max_amount());
+ static_cast<unsigned int>(amount),
+ static_cast<unsigned int>(res->max_amount()));
}
- if (static_cast<int32_t>(amount) < res->max_amount()) {
+ if (amount < res->max_amount()) {
bestmatch += 1; // Resi start with 1, not 0
}
=== modified file 'src/logic/map_objects/tribes/tribe_descr.h'
--- src/logic/map_objects/tribes/tribe_descr.h 2016-02-09 07:42:38 +0000
+++ src/logic/map_objects/tribes/tribe_descr.h 2016-04-11 06:48:15 +0000
@@ -122,7 +122,7 @@
const RoadTextures& road_textures() const;
DescriptionIndex get_resource_indicator
- (const ResourceDescription * const res, const uint32_t amount) const;
+ (const ResourceDescription * const res, const ResourceAmount amount) const;
// Returns the initalization at 'index' (which must not be out of bounds).
const TribeBasicInfo::Initialization& initialization(const uint8_t index) const {
=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
--- src/logic/map_objects/tribes/warehouse.cc 2016-03-12 07:07:12 +0000
+++ src/logic/map_objects/tribes/warehouse.cc 2016-04-11 06:48:15 +0000
@@ -128,7 +128,7 @@
/// Add wares and update the economy.
-void WarehouseSupply::add_wares(DescriptionIndex const id, uint32_t const count)
+void WarehouseSupply::add_wares(DescriptionIndex const id, Quantity const count)
{
if (!count)
return;
@@ -779,14 +779,14 @@
/// Magically create wares in this warehouse. Updates the economy accordingly.
-void Warehouse::insert_wares(DescriptionIndex const id, uint32_t const count)
+void Warehouse::insert_wares(DescriptionIndex const id, Quantity const count)
{
supply_->add_wares(id, count);
}
/// Magically destroy wares.
-void Warehouse::remove_wares(DescriptionIndex const id, uint32_t const count)
+void Warehouse::remove_wares(DescriptionIndex const id, Quantity const count)
{
supply_->remove_wares(id, count);
}
@@ -832,10 +832,9 @@
* \return the number of workers that we can launch satisfying the given
* requirements.
*/
-uint32_t Warehouse::count_workers
- (const Game & /* game */, DescriptionIndex ware, const Requirements & req)
+Quantity Warehouse::count_workers(const Game & /* game */, DescriptionIndex ware, const Requirements & req)
{
- uint32_t sum = 0;
+ Quantity sum = 0;
do {
sum += supply_->stock_workers(ware);
@@ -1116,7 +1115,7 @@
* Return the number of workers of the given type that we plan to
* create in this warehouse.
*/
-uint32_t Warehouse::get_planned_workers(Game & /* game */, DescriptionIndex index) const
+Quantity Warehouse::get_planned_workers(Game & /* game */, DescriptionIndex index) const
{
for (const PlannedWorkers& pw : planned_workers_) {
if (pw.index == index)
@@ -1131,8 +1130,7 @@
*
* This is the current stock plus any incoming transfers.
*/
-std::vector<uint32_t> Warehouse::calc_available_for_worker
- (Game & /* game */, DescriptionIndex index) const
+std::vector<Quantity> Warehouse::calc_available_for_worker(Game & /* game */, DescriptionIndex index) const
{
const WorkerDescr & w_desc = *owner().tribe().get_worker_descr(index);
std::vector<uint32_t> available;
@@ -1171,7 +1169,7 @@
* Set the amount of workers we plan to create
* of the given \p index to \p amount.
*/
-void Warehouse::plan_workers(Game & game, DescriptionIndex index, uint32_t amount)
+void Warehouse::plan_workers(Game & game, DescriptionIndex index, Quantity amount)
{
PlannedWorkers * pw = nullptr;
@@ -1234,7 +1232,7 @@
for (const auto& buildcost : w_desc.buildcost()) {
const std::string & input_name = buildcost.first;
- uint32_t supply;
+ Quantity supply;
DescriptionIndex id_w = owner().tribe().ware_index(input_name);
if (owner().tribe().has_ware(id_w)) {
=== modified file 'src/logic/map_objects/tribes/warehouse.h'
--- src/logic/map_objects/tribes/warehouse.h 2016-02-18 18:27:52 +0000
+++ src/logic/map_objects/tribes/warehouse.h 2016-04-11 06:48:15 +0000
@@ -148,20 +148,20 @@
*/
Workers get_incorporated_workers();
- void insert_wares (DescriptionIndex, uint32_t count);
- void remove_wares (DescriptionIndex, uint32_t count);
- void insert_workers(DescriptionIndex, uint32_t count);
- void remove_workers(DescriptionIndex, uint32_t count);
+ void insert_wares (DescriptionIndex, Quantity count);
+ void remove_wares (DescriptionIndex, Quantity count);
+ void insert_workers(DescriptionIndex, Quantity count);
+ void remove_workers(DescriptionIndex, Quantity count);
/* SoldierControl implementation */
std::vector<Soldier *> present_soldiers() const override;
std::vector<Soldier *> stationed_soldiers() const override {
return present_soldiers();
}
- uint32_t min_soldier_capacity() const override {return 0;}
- uint32_t max_soldier_capacity() const override {return 4294967295U;}
- uint32_t soldier_capacity() const override {return max_soldier_capacity();}
- void set_soldier_capacity(uint32_t /* capacity */) override {
+ Quantity min_soldier_capacity() const override {return 0;}
+ Quantity max_soldier_capacity() const override {return 4294967295U;}
+ Quantity soldier_capacity() const override {return max_soldier_capacity();}
+ void set_soldier_capacity(Quantity /* capacity */) override {
throw wexception("Not implemented for a Warehouse!");
}
void drop_soldier(Soldier &) override {
@@ -172,7 +172,7 @@
bool fetch_from_flag(Game &) override;
- uint32_t count_workers(const Game &, DescriptionIndex, const Requirements &);
+ Quantity count_workers(const Game &, DescriptionIndex, const Requirements &);
Worker & launch_worker(Game &, DescriptionIndex worker, const Requirements &);
// Adds the worker to the inventory. Takes ownership and might delete
@@ -188,9 +188,9 @@
bool can_create_worker(Game &, DescriptionIndex) const;
void create_worker(Game &, DescriptionIndex);
- uint32_t get_planned_workers(Game &, DescriptionIndex index) const;
- void plan_workers(Game &, DescriptionIndex index, uint32_t amount);
- std::vector<uint32_t> calc_available_for_worker
+ Quantity get_planned_workers(Game &, DescriptionIndex index) const;
+ void plan_workers(Game &, DescriptionIndex index, Quantity amount);
+ std::vector<Quantity> calc_available_for_worker
(Game &, DescriptionIndex index) const;
void enable_spawn(Game &, uint8_t worker_types_without_cost_index);
@@ -240,7 +240,7 @@
DescriptionIndex index;
/// How many workers of this type are we supposed to create?
- uint32_t amount;
+ Quantity amount;
/// Requests to obtain the required build costs
std::vector<Request *> requests;
=== modified file 'src/logic/map_objects/tribes/warelist.cc'
--- src/logic/map_objects/tribes/warelist.cc 2016-02-09 07:42:38 +0000
+++ src/logic/map_objects/tribes/warelist.cc 2016-04-11 06:48:15 +0000
@@ -42,7 +42,7 @@
/**
* Add the given number of items (default = 1) to the storage.
*/
-void WareList::add(DescriptionIndex const i, const WareCount count) {
+void WareList::add(DescriptionIndex const i, const Quantity count) {
if (!count)
return;
@@ -69,7 +69,7 @@
/**
* Remove the given number of items (default = 1) from the storage.
*/
-void WareList::remove(DescriptionIndex const i, const WareCount count) {
+void WareList::remove(DescriptionIndex const i, const Quantity count) {
if (!count)
return;
@@ -92,7 +92,7 @@
/**
* Return the number of wares of a given type stored in this storage.
*/
-WareList::WareCount WareList::stock(DescriptionIndex const id) const {
+Quantity WareList::stock(DescriptionIndex const id) const {
return id < wares_.size() ? wares_[id] : 0;
}
@@ -106,7 +106,7 @@
uint32_t i = 0;
while (i < wl.wares_.size()) {
- const WareCount count = wl.wares_[i];
+ const Quantity count = wl.wares_[i];
if (i < wares_.size()) {
if (count != wares_[i])
return false;
=== modified file 'src/logic/map_objects/tribes/warelist.h'
--- src/logic/map_objects/tribes/warelist.h 2016-02-09 07:42:38 +0000
+++ src/logic/map_objects/tribes/warelist.h 2016-04-11 06:48:15 +0000
@@ -40,17 +40,14 @@
void clear() {wares_.clear();} /// Clear the storage
- using WareCount = uint32_t;
- using WareCountVector = std::vector<WareCount>;
-
/// \return Highest possible ware id
DescriptionIndex get_nrwareids() const {return DescriptionIndex(wares_.size());}
- void add (DescriptionIndex, WareCount = 1);
+ void add (DescriptionIndex, Quantity = 1);
void add(const WareList &);
- void remove(DescriptionIndex, WareCount = 1);
+ void remove(DescriptionIndex, Quantity = 1);
void remove(const WareList & wl);
- WareCount stock(DescriptionIndex) const;
+ Quantity stock(DescriptionIndex) const;
void set_nrwares(DescriptionIndex const i) {
assert(wares_.empty());
@@ -63,7 +60,7 @@
mutable boost::signals2::signal<void ()> changed;
private:
- WareCountVector wares_;
+ std::vector<Quantity> wares_;
};
}
=== modified file 'src/logic/map_objects/tribes/worker.cc'
--- src/logic/map_objects/tribes/worker.cc 2016-04-10 16:53:41 +0000
+++ src/logic/map_objects/tribes/worker.cc 2016-04-11 06:48:15 +0000
@@ -128,8 +128,8 @@
MapRegion<Area<FCoords> > mr
(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));
do {
- uint8_t fres = mr.location().field->get_resources();
- uint32_t amount = mr.location().field->get_resources_amount();
+ DescriptionIndex fres = mr.location().field->get_resources();
+ ResourceAmount amount = mr.location().field->get_resources_amount();
// In the future, we might want to support amount = 0 for
// fields that can produce an infinite amount of resources.
@@ -164,12 +164,12 @@
mr = MapRegion<Area<FCoords> >
(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));
do {
- uint8_t fres = mr.location().field->get_resources();
+ DescriptionIndex fres = mr.location().field->get_resources();
if (fres != res) {
continue;
}
- uint32_t amount = mr.location().field->get_resources_amount();
+ ResourceAmount amount = mr.location().field->get_resources_amount();
pick -= 8 * amount;
if (pick < 0) {
@@ -233,8 +233,8 @@
MapRegion<Area<FCoords> > mr
(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));
do {
- uint8_t fres = mr.location().field->get_resources();
- uint32_t amount =
+ DescriptionIndex fres = mr.location().field->get_resources();
+ ResourceAmount amount =
mr.location().field->get_initial_res_amount() -
mr.location().field->get_resources_amount ();
@@ -273,11 +273,11 @@
(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));
do {
- uint8_t fres = mr.location().field->get_resources();
+ DescriptionIndex fres = mr.location().field->get_resources();
if (fres != res)
continue;
- uint32_t amount =
+ ResourceAmount amount =
mr.location().field->get_initial_res_amount() -
mr.location().field->get_resources_amount ();
=== modified file 'src/logic/map_objects/tribes/worker_descr.h'
--- src/logic/map_objects/tribes/worker_descr.h 2016-02-27 08:43:39 +0000
+++ src/logic/map_objects/tribes/worker_descr.h 2016-04-11 06:48:15 +0000
@@ -45,7 +45,7 @@
friend struct WorkerProgram;
public:
- using Buildcost = std::map<std::string, uint8_t>;
+ using Buildcost = std::map<std::string, Quantity>;
WorkerDescr(const std::string& init_descname,
MapObjectType type, const LuaTable& table, const EditorGameBase& egbase);
@@ -67,7 +67,7 @@
/// The special value std::numeric_limits<uint32_t>::max() means that the
/// the target quantity of this ware type will never be checked and should
/// not be configurable.
- uint32_t default_target_quantity() const {return default_target_quantity_;}
+ Quantity default_target_quantity() const {return default_target_quantity_;}
bool has_demand_check() const {
return default_target_quantity() != std::numeric_limits<uint32_t>::max();
@@ -111,7 +111,7 @@
protected:
Point ware_hotspot_;
- uint32_t default_target_quantity_;
+ Quantity default_target_quantity_;
std::string helptext_script_; // The path and filename to the worker's helptext script
DirAnimations walk_anims_;
DirAnimations walkload_anims_;
=== modified file 'src/logic/map_objects/world/resource_description.cc'
--- src/logic/map_objects/world/resource_description.cc 2016-01-25 18:16:48 +0000
+++ src/logic/map_objects/world/resource_description.cc 2016-04-11 06:48:15 +0000
@@ -77,7 +77,7 @@
return detectable_;
}
-int32_t ResourceDescription::max_amount() const {
+ResourceAmount ResourceDescription::max_amount() const {
return max_amount_;
}
=== modified file 'src/logic/map_objects/world/resource_description.h'
--- src/logic/map_objects/world/resource_description.h 2016-01-25 18:16:48 +0000
+++ src/logic/map_objects/world/resource_description.h 2016-04-11 06:48:15 +0000
@@ -49,7 +49,7 @@
bool detectable() const;
/// Returns the maximum amount that can be in a field for this resource.
- int32_t max_amount() const;
+ ResourceAmount max_amount() const;
/// Returns the path to the image that should be used in the editor to
/// represent an 'amount' of this resource.
@@ -62,7 +62,7 @@
const std::string name_;
const std::string descname_;
const bool detectable_;
- const int32_t max_amount_;
+ const ResourceAmount max_amount_;
const std::string representative_image_;
std::vector<EditorPicture> editor_pictures_;
=== modified file 'src/logic/map_objects/world/terrain_description.cc'
--- src/logic/map_objects/world/terrain_description.cc 2016-02-14 14:09:29 +0000
+++ src/logic/map_objects/world/terrain_description.cc 2016-04-11 06:48:15 +0000
@@ -214,20 +214,20 @@
return editor_category_;
}
-DescriptionIndex TerrainDescription::get_valid_resource(uint8_t index) const {
+DescriptionIndex TerrainDescription::get_valid_resource(DescriptionIndex index) const {
return valid_resources_[index];
}
-int TerrainDescription::get_num_valid_resources() const {
+size_t TerrainDescription::get_num_valid_resources() const {
return valid_resources_.size();
}
-std::vector<uint8_t> TerrainDescription::valid_resources() const {
+std::vector<DescriptionIndex> TerrainDescription::valid_resources() const {
return valid_resources_;
}
-bool TerrainDescription::is_resource_valid(const int res) const {
- for (const uint8_t resource_index : valid_resources_) {
+bool TerrainDescription::is_resource_valid(const DescriptionIndex res) const {
+ for (const DescriptionIndex resource_index : valid_resources_) {
if (resource_index == res) {
return true;
}
@@ -235,11 +235,11 @@
return false;
}
-int TerrainDescription::get_default_resource() const {
+DescriptionIndex TerrainDescription::get_default_resource() const {
return default_resource_index_;
}
-int TerrainDescription::get_default_resource_amount() const {
+ResourceAmount TerrainDescription::get_default_resource_amount() const {
return default_resource_amount_;
}
=== modified file 'src/logic/map_objects/world/terrain_description.h'
--- src/logic/map_objects/world/terrain_description.h 2016-02-14 14:09:29 +0000
+++ src/logic/map_objects/world/terrain_description.h 2016-04-11 06:48:15 +0000
@@ -89,23 +89,23 @@
const std::vector<TerrainDescription::Type> get_types() const;
/// Returns the valid resource with the given index.
- DescriptionIndex get_valid_resource(uint8_t index) const;
+ DescriptionIndex get_valid_resource(DescriptionIndex index) const;
/// Returns the number of valid resources.
- int get_num_valid_resources() const;
+ size_t get_num_valid_resources() const;
/// Returns the the valid resources.
- std::vector<uint8_t> valid_resources() const;
+ std::vector<DescriptionIndex> valid_resources() const;
/// Returns true if this resource can be found in this terrain type.
- bool is_resource_valid(int32_t res) const;
+ bool is_resource_valid(DescriptionIndex res) const;
/// Returns the resource index that can by default always be found in this
/// terrain.
- int get_default_resource() const;
+ DescriptionIndex get_default_resource() const;
/// Returns the default amount of resources you can find in this terrain.
- int32_t get_default_resource_amount() const;
+ ResourceAmount get_default_resource_amount() const;
/// Returns the dither layer, i.e. the information in which zlayer this
/// texture should be drawn.
@@ -134,8 +134,8 @@
const EditorCategory* editor_category_; ///< not owned.
Is is_;
std::vector<std::string> custom_tooltips_;
- std::vector<uint8_t> valid_resources_;
- int default_resource_index_;
+ std::vector<DescriptionIndex> valid_resources_;
+ DescriptionIndex default_resource_index_;
int default_resource_amount_;
int dither_layer_;
int frame_length_;
=== modified file 'src/logic/widelands.h'
--- src/logic/widelands.h 2016-04-03 12:35:43 +0000
+++ src/logic/widelands.h 2016-04-11 06:48:15 +0000
@@ -64,6 +64,8 @@
using ResourceAmount = uint8_t; /// 4 bits used, so 0 .. 15.
+using Quantity = uint32_t; // e.g. the number of a type of ware in a warehouse.
+
using Vision = uint16_t;
using Time = int32_t; // TODO(unknown): should be unsigned
=== modified file 'src/map_io/map_buildingdata_packet.cc'
--- src/map_io/map_buildingdata_packet.cc 2016-04-01 07:43:42 +0000
+++ src/map_io/map_buildingdata_packet.cc 2016-04-11 06:48:15 +0000
@@ -344,7 +344,7 @@
while (fr.unsigned_8()) {
const DescriptionIndex& id = tribe.ware_index(fr.c_string());
- uint32_t amount = fr.unsigned_32();
+ Quantity amount = fr.unsigned_32();
Warehouse::StockPolicy policy =
static_cast<Warehouse::StockPolicy>(fr.unsigned_8());
=== modified file 'src/map_io/map_resources_packet.cc'
--- src/map_io/map_resources_packet.cc 2016-01-16 12:55:14 +0000
+++ src/map_io/map_resources_packet.cc 2016-04-11 06:48:15 +0000
@@ -66,12 +66,13 @@
for (uint16_t y = 0; y < map.get_height(); ++y) {
for (uint16_t x = 0; x < map.get_width(); ++x) {
- uint8_t const id = fr.unsigned_8();
- uint8_t const found_amount = fr.unsigned_8();
- uint8_t const amount = found_amount;
- uint8_t const start_amount = fr.unsigned_8();
+ DescriptionIndex const id = fr.unsigned_8();
+ ResourceAmount const found_amount = fr.unsigned_8();
+ ResourceAmount const amount = found_amount;
+ ResourceAmount const start_amount = fr.unsigned_8();
- uint8_t set_id, set_amount, set_start_amount;
+ DescriptionIndex set_id;
+ ResourceAmount set_amount, set_start_amount;
// if amount is zero, theres nothing here
if (!amount) {
set_id = 0;
@@ -135,9 +136,9 @@
for (uint16_t y = 0; y < map.get_height(); ++y) {
for (uint16_t x = 0; x < map.get_width(); ++x) {
const Field & f = map[Coords(x, y)];
- int32_t res = f.get_resources ();
- int32_t const amount = f.get_resources_amount ();
- int32_t const start_amount = f.get_initial_res_amount();
+ DescriptionIndex res = f.get_resources ();
+ ResourceAmount const amount = f.get_resources_amount ();
+ ResourceAmount const start_amount = f.get_initial_res_amount();
if (!amount)
res = 0;
fw.unsigned_8(res);
=== modified file 'src/map_io/s2map.cc'
--- src/map_io/s2map.cc 2016-04-03 12:35:43 +0000
+++ src/map_io/s2map.cc 2016-04-11 06:48:15 +0000
@@ -635,7 +635,7 @@
default: res = ""; amount = 0; break;
};
- int32_t nres = 0;
+ Widelands::DescriptionIndex nres = 0;
if (*res) {
nres = world.get_resource(res);
if (nres == Widelands::INVALID_INDEX)
@@ -644,8 +644,7 @@
"play settler maps here",
res);
}
- const int32_t real_amount = static_cast<int32_t>
- (2.86f * static_cast<float>(amount));
+ const Widelands::ResourceAmount real_amount = static_cast<Widelands::ResourceAmount>(2.86f * amount);
map_.initialize_resources(c, nres, real_amount);
}
}
=== modified file 'src/scripting/lua_game.h'
--- src/scripting/lua_game.h 2016-03-14 19:56:14 +0000
+++ src/scripting/lua_game.h 2016-04-11 06:48:15 +0000
@@ -144,7 +144,7 @@
};
class LuaMessage : public LuaGameModuleClass {
- uint32_t player_number_; // TODO(Hasi50): in CTor this is uint8_t, well
+ Widelands::PlayerNumber player_number_;
Widelands::MessageId message_id_;
public:
=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc 2016-04-10 08:50:50 +0000
+++ src/scripting/lua_map.cc 2016-04-11 06:48:15 +0000
@@ -142,12 +142,12 @@
}
};
-using SoldiersMap = std::map<SoldierMapDescr, uint32_t>;
-using WaresMap = std::map<Widelands::DescriptionIndex, uint32_t>;
-using WorkersMap = std::map<Widelands::DescriptionIndex, uint32_t>;
-using SoldierAmount = std::pair<SoldierMapDescr, uint32_t>;
-using WorkerAmount = std::pair<Widelands::DescriptionIndex, uint32_t>;
-using PlrInfluence = std::pair<uint8_t, uint32_t>;
+using SoldiersMap = std::map<SoldierMapDescr, Widelands::Quantity>;
+using WaresMap = std::map<Widelands::DescriptionIndex, Widelands::Quantity>;
+using WorkersMap = std::map<Widelands::DescriptionIndex, Widelands::Quantity>;
+using SoldierAmount = std::pair<SoldierMapDescr, Widelands::Quantity>;
+using WorkerAmount = std::pair<Widelands::DescriptionIndex, Widelands::Quantity>;
+using PlrInfluence = std::pair<Widelands::PlayerNumber, Widelands::MilitaryInfluence>;
using WaresSet = std::set<Widelands::DescriptionIndex>;
using WorkersSet = std::set<Widelands::DescriptionIndex>;
using SoldiersList = std::vector<Widelands::Soldier *>;
@@ -309,7 +309,7 @@
lua_newtable(L);
for (const DescriptionIndex& i : set) {
- uint32_t cnt = 0;
+ Widelands::Quantity cnt = 0;
if (c_workers.count(i))
cnt = c_workers[i];
@@ -350,7 +350,7 @@
if (!valid_workers.count(sp.first))
report_error(L, "<%s> can't be employed here!", wdes->name().c_str());
- uint32_t cur = 0;
+ Widelands::Quantity cur = 0;
WorkersMap::iterator i = c_workers.find(sp.first);
if (i != c_workers.end())
cur = i->second;
@@ -422,14 +422,14 @@
SoldiersMap rv;
if (lua_gettop(L) > 2) {
// STACK: cls, descr, count
- const uint32_t count = luaL_checkuint32(L, 3);
+ const Widelands::Quantity count = luaL_checkuint32(L, 3);
const SoldierMapDescr d = unbox_lua_soldier_description(L, 2, soldier_descr);
rv.insert(SoldierAmount(d, count));
} else {
lua_pushnil(L);
while (lua_next(L, 2) != 0) {
const SoldierMapDescr d = unbox_lua_soldier_description(L, 3, soldier_descr);
- const uint32_t count = luaL_checkuint32(L, -1);
+ const Widelands::Quantity count = luaL_checkuint32(L, -1);
rv.insert(SoldierAmount(d, count));
lua_pop(L, 1);
}
@@ -484,7 +484,7 @@
// Only return the number of those requested
const SoldierMapDescr wanted = unbox_lua_soldier_description(L, 2, soldier_descr);
- uint32_t rv = 0;
+ Widelands::Quantity rv = 0;
for (const Soldier* s : soldiers) {
SoldierMapDescr sd
(s->get_health_level(), s->get_attack_level(), s->get_defense_level(), s->get_evade_level());
@@ -529,7 +529,7 @@
// Now adjust them
EditorGameBase& egbase = get_egbase(L);
for (const SoldiersMap::value_type& sp : setpoints) {
- uint32_t cur = 0;
+ Widelands::Quantity cur = 0;
SoldiersMap::iterator i = hist.find(sp.first);
if (i != hist.end())
cur = i->second;
@@ -952,7 +952,7 @@
Map & m = get_egbase(L).map();
lua_createtable(L, m.get_nrplayers(), 0);
- for (uint32_t i = 0; i < m.get_nrplayers(); i++) {
+ for (Widelands::PlayerNumber i = 0; i < m.get_nrplayers(); i++) {
lua_pushuint32(L, i + 1);
to_lua<LuaMaps::LuaPlayerSlot>(L, new LuaMaps::LuaPlayerSlot(i + 1));
lua_settable(L, -3);
@@ -3077,7 +3077,7 @@
*/
int LuaTerrainDescription::get_default_resource(lua_State * L) {
- int res_index = get()->get_default_resource();
+ DescriptionIndex res_index = get()->get_default_resource();
const World& world = get_egbase(L).world();
if (res_index != Widelands::kNoResource && res_index < world.get_nr_resources()) {
to_lua<LuaMaps::LuaResourceDescription>
@@ -3176,7 +3176,7 @@
const World& world = get_egbase(L).world();
lua_newtable(L);
int index = 1;
- for (uint8_t res_index : get()->valid_resources()) {
+ for (DescriptionIndex res_index : get()->valid_resources()) {
if (res_index != Widelands::kNoResource && res_index < world.get_nr_resources()) {
lua_pushint32(L, index++);
to_lua<LuaMaps::LuaResourceDescription>
@@ -3621,7 +3621,7 @@
WaresMap setpoints = parse_set_wares_arguments(L, f->owner().tribe());
WaresMap c_wares = count_wares_on_flag_(*f, tribes);
- uint32_t nwares = 0;
+ Widelands::Quantity nwares = 0;
for (const auto& ware : c_wares) {
// all wares currently on the flag without a setpoint should be removed
@@ -3690,7 +3690,7 @@
lua_newtable(L);
for (const Widelands::DescriptionIndex& ware : wares_set) {
- uint32_t count = 0;
+ Widelands::Quantity count = 0;
if (wares.count(ware))
count = wares[ware];
@@ -5173,7 +5173,7 @@
}
int LuaField::set_resource(lua_State * L) {
auto& egbase = get_egbase(L);
- int32_t res = egbase.world().get_resource
+ DescriptionIndex res = egbase.world().get_resource
(luaL_checkstring(L, -1));
if (res == Widelands::INVALID_INDEX)
@@ -5201,13 +5201,15 @@
int LuaField::set_resource_amount(lua_State * L) {
EditorGameBase& egbase = get_egbase(L);
auto c = fcoords(L);
- int32_t res = c.field->get_resources();
- int32_t amount = luaL_checkint32(L, -1);
+ DescriptionIndex res = c.field->get_resources();
+ auto amount = luaL_checkint32(L, -1);
const ResourceDescription * resDesc = egbase.world().get_resource(res);
- int32_t max_amount = resDesc ? resDesc->max_amount() : 0;
+ ResourceAmount max_amount = resDesc ? resDesc->max_amount() : 0;
if (amount < 0 || amount > max_amount)
- report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount, max_amount);
+ report_error(L, "Illegal amount: %i, must be >= 0 and <= %i",
+ amount,
+ static_cast<unsigned int>(max_amount));
auto& map = egbase.map();
if (is_a(Game, &egbase)) {
=== modified file 'src/wui/game_debug_ui.cc'
--- src/wui/game_debug_ui.cc 2016-03-19 09:50:23 +0000
+++ src/wui/game_debug_ui.cc 2016-04-11 06:48:15 +0000
@@ -362,13 +362,15 @@
if (ridx == Widelands::kNoResource) {
str += "Resource: None\n";
} else {
- const int ramount = coords_.field->get_resources_amount();
- const int initial_amount = coords_.field->get_initial_res_amount();
+ const Widelands::ResourceAmount ramount = coords_.field->get_resources_amount();
+ const Widelands::ResourceAmount initial_amount = coords_.field->get_initial_res_amount();
str += (boost::format("Resource: %s\n")
% ibase().egbase().world().get_resource(ridx)->name().c_str()).str();
- str += (boost::format(" Amount: %i/%i\n") % ramount % initial_amount).str();
+ str += (boost::format(" Amount: %i/%i\n")
+ % static_cast<unsigned int>(ramount)
+ % static_cast<unsigned int>(initial_amount)).str();
}
}
=== modified file 'src/wui/soldierlist.cc'
--- src/wui/soldierlist.cc 2016-03-16 09:16:58 +0000
+++ src/wui/soldierlist.cc 2016-04-11 06:48:15 +0000
@@ -120,7 +120,7 @@
icon_width_ += 2 * kIconBorder;
icon_height_ += 2 * kIconBorder;
- uint32_t maxcapacity = soldiers_.max_soldier_capacity();
+ Widelands::Quantity maxcapacity = soldiers_.max_soldier_capacity();
if (maxcapacity <= kMaxColumns) {
cols_ = maxcapacity;
rows_ = 1;
Follow ups