widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #11398
[Merge] lp:~widelands-dev/widelands/bug-1728006 into lp:widelands
TiborB has proposed merging lp:~widelands-dev/widelands/bug-1728006 into lp:widelands.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1728006 in widelands: "AI crashes when a producer is also supporter"
https://bugs.launchpad.net/widelands/+bug/1728006
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/bug-1728006/+merge/333094
This adds support for productionsites that are also supporting site. Needs testing with frisian branch. And AI training a bit, but not as a part of this merge request of course.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/bug-1728006 into lp:widelands.
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h 2017-09-29 16:10:25 +0000
+++ src/ai/ai_help_structs.h 2017-11-01 20:08:18 +0000
@@ -78,6 +78,8 @@
kUpgradeExtends,
kLogRefiner,
kIronMine,
+ kPureProducer,
+ kSupportingProducer,
};
enum class AiType : uint8_t { kVeryWeak, kWeak, kNormal };
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2017-09-29 16:10:25 +0000
+++ src/ai/defaultai.cc 2017-11-01 20:08:18 +0000
@@ -698,6 +698,15 @@
bo.positions.push_back(temp_position.first);
}
+ // Now identify is it is a producer and if also supports some ware
+ if (!bo.outputs.empty()) {
+ if (bo.production_hints.empty()) {
+ bo.set_is(BuildingAttribute::kPureProducer);
+ } else {
+ bo.set_is(BuildingAttribute::kSupportingProducer);
+ }
+ }
+
iron_ore_id = tribe_->ironore();
if (bo.type == BuildingObserver::Type::kMine) {
@@ -2302,7 +2311,7 @@
bo.new_building == BuildingNecessity::kForced ||
bo.new_building == BuildingNecessity::kAllowed ||
bo.new_building == BuildingNecessity::kNeededPending) &&
- (!bo.outputs.empty() || bo.is(BuildingAttribute::kBarracks))) {
+ (bo.is(BuildingAttribute::kPureProducer) || bo.is(BuildingAttribute::kBarracks))) {
if (bo.max_needed_preciousness <= 0) {
throw wexception("AI: Max presciousness must not be <= 0 for building: %s",
bo.desc->name().c_str());
@@ -2649,7 +2658,7 @@
prio -= (bf->enemy_nearby) * 100;
prio -= (expansion_type.get_expansion_type() != ExpansionMode::kEconomy) * 100;
} else { // finally normal productionsites
- assert(bo.production_hints.empty());
+ assert(bo.production_hints.empty() || bo.is(BuildingAttribute::kSupportingProducer));
if (bo.new_building == BuildingNecessity::kForced) {
prio += 150;
@@ -2709,6 +2718,20 @@
}
}
+ // This is for a special case this is also supporter
+ for (auto ph : bo.production_hints) {
+ prio += management_data.neuron_pool[51].get_result_safe(
+ bf->producers_nearby.at(ph) * 5, kAbsValue) /
+ 2;
+ }
+
+ // This considers supporters nearby
+ for (auto ph : bo.outputs) {
+ prio += management_data.neuron_pool[52].get_result_safe(
+ bf->supporters_nearby.at(ph) * 5, kAbsValue) /
+ 2;
+ }
+
if (prio <= 0) {
continue;
}
@@ -4762,7 +4785,8 @@
bo.cnt_under_construction + bo.unoccupied_count == 0) {
bo.max_needed_preciousness = bo.max_preciousness; // even when rocks are not needed
return BuildingNecessity::kAllowed;
- } else if (!bo.production_hints.empty()) {
+ } else if (!bo.production_hints.empty() && !bo.is(BuildingAttribute::kSupportingProducer)) {
+ // Pure supporting sites only) {
if (bo.cnt_under_construction + bo.unoccupied_count - bo.unconnected_count > 0) {
return BuildingNecessity::kForbidden;
@@ -5126,6 +5150,15 @@
inputs[99] = (wood_policy_ == WoodPolicy::kAllowRangers) ? -1 : 0;
inputs[100] = (bo.total_count() == 0) ? 3 : 0;
inputs[101] = (bo.total_count() == 0) ? 6 : 0;
+ if (bo.is(BuildingAttribute::kSupportingProducer)) {
+ if (bo.total_count() == 0) {
+ inputs[102] = 1;
+ inputs[103] = 2;
+ inputs[104] = -2;
+ }
+ inputs[105] = -2;
+ inputs[106] = -2;
+ }
int16_t tmp_score = 0;
for (uint8_t i = 0; i < kFNeuronBitSize; ++i) {
Follow ups