widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #17783
[Merge] lp:~widelands-dev/widelands/constructionsite_options into lp:widelands
Benedikt Straub has proposed merging lp:~widelands-dev/widelands/constructionsite_options into lp:widelands.
Commit message:
Fixes for some errors in constructionsite settings
Requested reviews:
GunChleoc (gunchleoc)
Related bugs:
Bug #1597310 in widelands: "Possibility to set building options when building is under construction"
https://bugs.launchpad.net/widelands/+bug/1597310
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/constructionsite_options/+merge/369210
As happens so often, new bugs are found directly after the feature that causes them has been merged :)
– Fix two errors with ware priorities and max fills (we need to distinguish between the constructionsite´s real input queues and those for the settings)
– Minimum allowed capacity for milsites is 1, not 0
– Fix initial priority view in inputqueuedisplay
– Fix a bug in saveloading trainingsite-constructionsite-settings
--
Your team Widelands Developers is subscribed to branch lp:~widelands-dev/widelands/constructionsite_options.
=== modified file 'src/logic/game.cc'
--- src/logic/game.cc 2019-06-23 11:41:17 +0000
+++ src/logic/game.cc 2019-06-24 06:10:51 +0000
@@ -789,17 +789,19 @@
void Game::send_player_set_ware_priority(PlayerImmovable& imm,
int32_t const type,
DescriptionIndex const index,
- int32_t const prio) {
+ int32_t const prio,
+ bool cs) {
send_player_command(
- new CmdSetWarePriority(get_gametime(), imm.owner().player_number(), imm, type, index, prio));
+ new CmdSetWarePriority(get_gametime(), imm.owner().player_number(), imm, type, index, prio, cs));
}
void Game::send_player_set_input_max_fill(PlayerImmovable& imm,
DescriptionIndex const index,
WareWorker type,
- uint32_t const max_fill) {
+ uint32_t const max_fill,
+ bool cs) {
send_player_command(new CmdSetInputMaxFill(
- get_gametime(), imm.owner().player_number(), imm, index, type, max_fill));
+ get_gametime(), imm.owner().player_number(), imm, index, type, max_fill, cs));
}
void Game::send_player_change_training_options(TrainingSite& ts,
=== modified file 'src/logic/game.h'
--- src/logic/game.h 2019-06-09 10:33:51 +0000
+++ src/logic/game.h 2019-06-24 06:10:51 +0000
@@ -268,11 +268,13 @@
void send_player_set_ware_priority(PlayerImmovable&,
int32_t type,
DescriptionIndex index,
- int32_t prio);
+ int32_t prio,
+ bool is_cs = false);
void send_player_set_input_max_fill(PlayerImmovable&,
DescriptionIndex index,
WareWorker type,
- uint32_t);
+ uint32_t,
+ bool is_cs = false);
void send_player_change_training_options(TrainingSite&, TrainingAttribute, int32_t);
void send_player_drop_soldier(Building&, int32_t);
void send_player_change_soldier_capacity(Building&, int32_t);
=== modified file 'src/logic/map_objects/tribes/building_settings.cc'
--- src/logic/map_objects/tribes/building_settings.cc 2019-06-23 11:41:17 +0000
+++ src/logic/map_objects/tribes/building_settings.cc 2019-06-24 06:10:51 +0000
@@ -138,13 +138,6 @@
constexpr uint8_t kCurrentPacketVersionTrainingsite = 1;
constexpr uint8_t kCurrentPacketVersionWarehouse = 1;
-enum class BuildingType : uint8_t {
- kWarehouse = 1,
- kProductionsite = 2,
- kTrainingsite = 3,
- kMilitarysite = 4,
-};
-
// static
BuildingSettings* BuildingSettings::load(const Game& game, const TribeDescr& tribe, FileRead& fr) {
try {
@@ -200,6 +193,7 @@
void BuildingSettings::save(const Game&, FileWrite& fw) const {
fw.unsigned_8(kCurrentPacketVersion);
fw.c_string(descr_.c_str());
+ fw.unsigned_8(static_cast<uint8_t>(type()));
}
void MilitarysiteSettings::read(const Game& game, FileRead& fr) {
@@ -220,7 +214,6 @@
void MilitarysiteSettings::save(const Game& game, FileWrite& fw) const {
BuildingSettings::save(game, fw);
- fw.unsigned_8(static_cast<uint8_t>(BuildingType::kMilitarysite));
fw.unsigned_8(kCurrentPacketVersionMilitarysite);
fw.unsigned_32(desired_capacity);
@@ -262,7 +255,6 @@
void ProductionsiteSettings::save(const Game& game, FileWrite& fw) const {
BuildingSettings::save(game, fw);
- fw.unsigned_8(static_cast<uint8_t>(BuildingType::kProductionsite));
fw.unsigned_8(kCurrentPacketVersionProductionsite);
fw.unsigned_8(stopped ? 1 : 0);
@@ -297,7 +289,6 @@
void TrainingsiteSettings::save(const Game& game, FileWrite& fw) const {
ProductionsiteSettings::save(game, fw);
- fw.unsigned_8(static_cast<uint8_t>(BuildingType::kTrainingsite));
fw.unsigned_8(kCurrentPacketVersionTrainingsite);
fw.unsigned_32(desired_capacity);
}
@@ -331,7 +322,6 @@
void WarehouseSettings::save(const Game& game, FileWrite& fw) const {
BuildingSettings::save(game, fw);
- fw.unsigned_8(static_cast<uint8_t>(BuildingType::kWarehouse));
fw.unsigned_8(kCurrentPacketVersionWarehouse);
fw.unsigned_8(launch_expedition ? 1 : 0);
=== modified file 'src/logic/map_objects/tribes/building_settings.h'
--- src/logic/map_objects/tribes/building_settings.h 2019-05-15 09:20:22 +0000
+++ src/logic/map_objects/tribes/building_settings.h 2019-06-24 06:10:51 +0000
@@ -53,6 +53,15 @@
virtual void apply(const BuildingSettings&) {
}
+protected:
+ enum class BuildingType : uint8_t {
+ kWarehouse = 1,
+ kProductionsite = 2,
+ kTrainingsite = 3,
+ kMilitarysite = 4,
+ };
+ virtual BuildingType type() const = 0;
+
private:
const std::string descr_;
};
@@ -74,6 +83,11 @@
std::vector<std::pair<DescriptionIndex, InputQueueSetting>> ware_queues;
std::vector<std::pair<DescriptionIndex, InputQueueSetting>> worker_queues;
bool stopped;
+
+protected:
+ BuildingType type() const override {
+ return BuildingType::kProductionsite;
+ }
};
struct MilitarysiteSettings : public BuildingSettings {
@@ -88,6 +102,11 @@
const uint32_t max_capacity;
uint32_t desired_capacity;
bool prefer_heroes;
+
+protected:
+ BuildingType type() const override {
+ return BuildingType::kMilitarysite;
+ }
};
struct TrainingsiteSettings : public ProductionsiteSettings {
@@ -101,6 +120,11 @@
const uint32_t max_capacity;
uint32_t desired_capacity;
+
+protected:
+ BuildingType type() const override {
+ return BuildingType::kTrainingsite;
+ }
};
struct WarehouseSettings : public BuildingSettings {
@@ -116,6 +140,11 @@
std::map<DescriptionIndex, StockPolicy> worker_preferences;
const bool launch_expedition_allowed;
bool launch_expedition;
+
+protected:
+ BuildingType type() const override {
+ return BuildingType::kWarehouse;
+ }
};
} // namespace Widelands
=== modified file 'src/logic/playercommand.cc'
--- src/logic/playercommand.cc 2019-06-23 11:41:17 +0000
+++ src/logic/playercommand.cc 2019-06-24 06:10:51 +0000
@@ -1049,25 +1049,29 @@
PlayerImmovable& imm,
const int32_t init_type,
const DescriptionIndex i,
- const int32_t init_priority)
+ const int32_t init_priority,
+ bool cs_setting)
: PlayerCommand(init_duetime, init_sender),
serial_(imm.serial()),
type_(init_type),
index_(i),
- priority_(init_priority) {
+ priority_(init_priority),
+ is_constructionsite_setting_(cs_setting) {
}
void CmdSetWarePriority::execute(Game& game) {
MapObject* mo = game.objects().get_object(serial_);
- if (upcast(ConstructionSite, cs, mo)) {
- if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
- for (auto& pair : s->ware_queues) {
- if (pair.first == index_) {
- pair.second.priority = priority_;
- return;
+ if (is_constructionsite_setting_) {
+ if (upcast(ConstructionSite, cs, mo)) {
+ if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
+ for (auto& pair : s->ware_queues) {
+ if (pair.first == index_) {
+ pair.second.priority = priority_;
+ return;
+ }
}
+ NEVER_HERE();
}
- NEVER_HERE();
}
} else if (upcast(Building, psite, mo)) {
if (psite->owner().player_number() == sender()) {
@@ -1076,7 +1080,7 @@
}
}
-constexpr uint16_t kCurrentPacketVersionCmdSetWarePriority = 1;
+constexpr uint16_t kCurrentPacketVersionCmdSetWarePriority = 2;
void CmdSetWarePriority::write(FileWrite& fw, EditorGameBase& egbase, MapObjectSaver& mos) {
fw.unsigned_16(kCurrentPacketVersionCmdSetWarePriority);
@@ -1087,6 +1091,7 @@
fw.unsigned_8(type_);
fw.signed_32(index_);
fw.signed_32(priority_);
+ fw.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
}
void CmdSetWarePriority::read(FileRead& fr, EditorGameBase& egbase, MapObjectLoader& mol) {
@@ -1098,6 +1103,7 @@
type_ = fr.unsigned_8();
index_ = fr.signed_32();
priority_ = fr.signed_32();
+ is_constructionsite_setting_ = fr.unsigned_8();
} else {
throw UnhandledVersionError(
"CmdSetWarePriority", packet_version, kCurrentPacketVersionCmdSetWarePriority);
@@ -1113,7 +1119,8 @@
serial_(des.unsigned_32()),
type_(des.unsigned_8()),
index_(des.signed_32()),
- priority_(des.signed_32()) {
+ priority_(des.signed_32()),
+ is_constructionsite_setting_(des.unsigned_8()) {
}
void CmdSetWarePriority::serialize(StreamWrite& ser) {
@@ -1123,6 +1130,7 @@
ser.unsigned_8(type_);
ser.signed_32(index_);
ser.signed_32(priority_);
+ ser.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
}
/*** class Cmd_SetWareMaxFill ***/
@@ -1131,39 +1139,43 @@
PlayerImmovable& imm,
const DescriptionIndex index,
const WareWorker type,
- const uint32_t max_fill)
+ const uint32_t max_fill,
+ bool cs_setting)
: PlayerCommand(init_duetime, init_sender),
serial_(imm.serial()),
index_(index),
type_(type),
- max_fill_(max_fill) {
+ max_fill_(max_fill),
+ is_constructionsite_setting_(cs_setting) {
}
void CmdSetInputMaxFill::execute(Game& game) {
MapObject* mo = game.objects().get_object(serial_);
- if (upcast(ConstructionSite, cs, mo)) {
- if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
- switch (type_) {
- case wwWARE:
- for (auto& pair : s->ware_queues) {
- if (pair.first == index_) {
- assert(pair.second.max_fill >= max_fill_);
- pair.second.desired_fill = max_fill_;
- return;
- }
- }
- NEVER_HERE();
- case wwWORKER:
- for (auto& pair : s->worker_queues) {
- if (pair.first == index_) {
- assert(pair.second.max_fill >= max_fill_);
- pair.second.desired_fill = max_fill_;
- return;
- }
+ if (is_constructionsite_setting_) {
+ if (upcast(ConstructionSite, cs, mo)) {
+ if (upcast(ProductionsiteSettings, s, cs->get_settings())) {
+ switch (type_) {
+ case wwWARE:
+ for (auto& pair : s->ware_queues) {
+ if (pair.first == index_) {
+ assert(pair.second.max_fill >= max_fill_);
+ pair.second.desired_fill = max_fill_;
+ return;
+ }
+ }
+ NEVER_HERE();
+ case wwWORKER:
+ for (auto& pair : s->worker_queues) {
+ if (pair.first == index_) {
+ assert(pair.second.max_fill >= max_fill_);
+ pair.second.desired_fill = max_fill_;
+ return;
+ }
+ }
+ NEVER_HERE();
}
NEVER_HERE();
}
- NEVER_HERE();
}
} else if (upcast(Building, b, mo)) {
if (b->owner().player_number() == sender()) {
@@ -1172,7 +1184,7 @@
}
}
-constexpr uint16_t kCurrentPacketVersionCmdSetInputMaxFill = 2;
+constexpr uint16_t kCurrentPacketVersionCmdSetInputMaxFill = 3;
void CmdSetInputMaxFill::write(FileWrite& fw, EditorGameBase& egbase, MapObjectSaver& mos) {
fw.unsigned_16(kCurrentPacketVersionCmdSetInputMaxFill);
@@ -1187,6 +1199,7 @@
fw.unsigned_8(1);
}
fw.unsigned_32(max_fill_);
+ fw.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
}
void CmdSetInputMaxFill::read(FileRead& fr, EditorGameBase& egbase, MapObjectLoader& mol) {
@@ -1202,6 +1215,7 @@
type_ = wwWORKER;
}
max_fill_ = fr.unsigned_32();
+ is_constructionsite_setting_ = fr.unsigned_8();
} else {
throw UnhandledVersionError(
"CmdSetInputMaxFill", packet_version, kCurrentPacketVersionCmdSetInputMaxFill);
@@ -1220,6 +1234,7 @@
type_ = wwWORKER;
}
max_fill_ = des.unsigned_32();
+ is_constructionsite_setting_ = des.unsigned_8();
}
void CmdSetInputMaxFill::serialize(StreamWrite& ser) {
@@ -1233,6 +1248,7 @@
ser.unsigned_8(1);
}
ser.unsigned_32(max_fill_);
+ ser.unsigned_8(is_constructionsite_setting_ ? 1 : 0);
}
CmdChangeTargetQuantity::CmdChangeTargetQuantity(const uint32_t init_duetime,
=== modified file 'src/logic/playercommand.h'
--- src/logic/playercommand.h 2019-06-19 07:34:19 +0000
+++ src/logic/playercommand.h 2019-06-24 06:10:51 +0000
@@ -475,7 +475,8 @@
PlayerImmovable&,
int32_t type,
DescriptionIndex index,
- int32_t priority);
+ int32_t priority,
+ bool cs);
// Write these commands to a file (for savegames)
void write(FileWrite&, EditorGameBase&, MapObjectSaver&) override;
@@ -495,6 +496,7 @@
int32_t type_; ///< this is always WARE right now
DescriptionIndex index_;
int32_t priority_;
+ bool is_constructionsite_setting_;
};
struct CmdSetInputMaxFill : public PlayerCommand {
@@ -505,7 +507,8 @@
PlayerImmovable&,
DescriptionIndex,
WareWorker,
- uint32_t maxfill);
+ uint32_t maxfill,
+ bool cs);
// Write these commands to a file (for savegames)
void write(FileWrite&, EditorGameBase&, MapObjectSaver&) override;
@@ -525,6 +528,7 @@
DescriptionIndex index_;
WareWorker type_;
uint32_t max_fill_;
+ bool is_constructionsite_setting_;
};
struct CmdChangeTargetQuantity : public PlayerCommand {
=== modified file 'src/wui/constructionsitewindow.cc'
--- src/wui/constructionsitewindow.cc 2019-06-23 11:41:17 +0000
+++ src/wui/constructionsitewindow.cc 2019-06-24 06:10:51 +0000
@@ -219,7 +219,7 @@
cs_soldier_capacity_decrease_->sigclicked.connect([this, ms]() {
igbase()->game().send_player_change_soldier_capacity(
*construction_site_.get(igbase()->egbase()),
- SDL_GetModState() & KMOD_CTRL ? 0 : ms->desired_capacity - 1);
+ SDL_GetModState() & KMOD_CTRL ? 1 : ms->desired_capacity - 1);
});
cs_soldier_capacity_increase_->sigclicked.connect([this, ms]() {
igbase()->game().send_player_change_soldier_capacity(
=== modified file 'src/wui/inputqueuedisplay.cc'
--- src/wui/inputqueuedisplay.cc 2019-06-23 11:41:17 +0000
+++ src/wui/inputqueuedisplay.cc 2019-06-24 06:10:51 +0000
@@ -281,7 +281,17 @@
this, pos, g_gr->images().get(pic_priority_low), _("Lowest priority"));
}
- int32_t priority = building_.get_priority(type_, index_, false);
+ int32_t priority = -1;
+ if (settings_) {
+ for (const auto& pair : settings_->ware_queues) {
+ if (pair.first == index_) {
+ priority = pair.second.priority;
+ break;
+ }
+ }
+ } else {
+ priority = building_.get_priority(type_, index_, false);
+ }
switch (priority) {
case Widelands::kPriorityHigh:
priority_radiogroup_->set_state(0);
@@ -293,7 +303,7 @@
priority_radiogroup_->set_state(2);
break;
default:
- break;
+ NEVER_HERE();
}
priority_radiogroup_->changedto.connect(
@@ -405,7 +415,7 @@
if (SDL_GetModState() & KMOD_CTRL) {
update_siblings_priority(state);
}
- igb_.game().send_player_set_ware_priority(building_, type_, index_, priority);
+ igb_.game().send_player_set_ware_priority(building_, type_, index_, priority, settings_ != nullptr);
}
void InputQueueDisplay::radiogroup_clicked() {
@@ -465,7 +475,7 @@
// Update the value of this queue if required
if (cache_max_fill_ > 0) {
igb_.game().send_player_set_input_max_fill(
- building_, index_, type_, ((SDL_GetModState() & KMOD_CTRL) ? 0 : cache_max_fill_ - 1));
+ building_, index_, type_, ((SDL_GetModState() & KMOD_CTRL) ? 0 : cache_max_fill_ - 1), settings_ != nullptr);
}
// Update other queues of this building
@@ -484,7 +494,7 @@
if (cache_max_fill_ < cache_size_) {
igb_.game().send_player_set_input_max_fill(
building_, index_, type_,
- ((SDL_GetModState() & KMOD_CTRL) ? cache_size_ : cache_max_fill_ + 1));
+ ((SDL_GetModState() & KMOD_CTRL) ? cache_size_ : cache_max_fill_ + 1), settings_ != nullptr);
}
if (SDL_GetModState() & KMOD_SHIFT) {
@@ -512,7 +522,7 @@
display->cache_size_));
if (new_fill != display->cache_max_fill_) {
igb_.game().send_player_set_input_max_fill(
- building_, display->index_, display->type_, new_fill);
+ building_, display->index_, display->type_, new_fill, settings_ != nullptr);
}
} while ((sibling = sibling->get_next_sibling()));
}
References