← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/ai_2_new_hints into lp:widelands

 

TiborB has proposed merging lp:~widelands-dev/widelands/ai_2_new_hints into lp:widelands.

Requested reviews:
  Widelands Developers (widelands-dev)

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/ai_2_new_hints/+merge/340548

Brings two new ai hints like:
      normal_ai_limit = 2,
      requires_supporters = true
Not thoroughly tested, and I propose it mainly so that windows builds are built and can be tested.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/ai_2_new_hints into lp:widelands.
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h	2018-02-16 21:04:59 +0000
+++ src/ai/ai_help_structs.h	2018-03-02 20:46:51 +0000
@@ -450,6 +450,7 @@
 	int32_t substitutes_count;
 
 	std::set<DescriptionIndex> production_hints;
+	bool requires_supporters;
 
 	// information needed for decision on new building construction
 	int16_t max_preciousness;

=== modified file 'src/ai/ai_hints.cc'
--- src/ai/ai_hints.cc	2017-11-10 09:59:25 +0000
+++ src/ai/ai_hints.cc	2018-03-02 20:46:51 +0000
@@ -203,6 +203,13 @@
     the AI can tolerate such buildings, they will be primarily treated as normal
     production sites when deciding on the building's location.
 
+**requires_supporters**
+    This building will be built only if a supporter is nearby::
+
+        requires_supporters = true,
+
+    For example if set for lumberjack, it will be built only if a renger is nearby.
+
 **trainingsites_max_percent**
     The maximum percengate this training site will have among all training sites, e.g.::
 
@@ -237,6 +244,8 @@
      very_weak_ai_limit_(
         table->has_key("very_weak_ai_limit") ? table->get_int("very_weak_ai_limit") : -1),
      weak_ai_limit_(table->has_key("weak_ai_limit") ? table->get_int("weak_ai_limit") : -1),
+     normal_ai_limit_(table->has_key("normal_ai_limit") ? table->get_int("normal_ai_limit") : -1),
+     requires_supporters_(table->has_key("requires_supporters") ? table->get_bool("requires_supporters") : false),
      trainingsites_max_percent_(table->has_key("trainingsites_max_percent") ?
                                    table->get_int("trainingsites_max_percent") :
                                    0) {

=== modified file 'src/ai/ai_hints.h'
--- src/ai/ai_hints.h	2017-08-26 06:56:49 +0000
+++ src/ai/ai_hints.h	2018-03-02 20:46:51 +0000
@@ -81,6 +81,10 @@
 		return mountain_conqueror_;
 	}
 
+	bool requires_supporters() const {
+		return requires_supporters_;
+	}
+
 	bool is_shipyard() const {
 		return shipyard_;
 	}
@@ -109,6 +113,10 @@
 		return weak_ai_limit_;
 	}
 
+	int16_t get_normal_ai_limit() const {
+		return normal_ai_limit_;
+	}
+
 	void set_trainingsites_max_percent(int percent);
 
 	uint8_t trainingsites_max_percent() const;
@@ -124,6 +132,7 @@
 	bool expansion_;
 	bool fighting_;
 	bool mountain_conqueror_;
+	bool requires_supporters_;
 	bool shipyard_;
 	int32_t prohibited_till_;
 	uint32_t basic_amount_;
@@ -131,6 +140,7 @@
 	int8_t mines_percent_;
 	int16_t very_weak_ai_limit_;
 	int16_t weak_ai_limit_;
+	int16_t normal_ai_limit_;
 	int trainingsites_max_percent_;
 	std::set<std::string> supported_production_;
 

=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc	2018-03-02 07:50:34 +0000
+++ src/ai/defaultai.cc	2018-03-02 20:46:51 +0000
@@ -647,6 +647,10 @@
 		bo.expansion_type = bh.is_expansion_type();
 		bo.fighting_type = bh.is_fighting_type();
 		bo.mountain_conqueror = bh.is_mountain_conqueror();
+		bo.requires_supporters = bh.requires_supporters();
+		if (bo.requires_supporters) {
+			log(" %d: %s strictly requires supporters\n", bo.name);
+		}
 		bo.prohibited_till = bh.get_prohibited_till() * 1000;  // value in conf is in seconds
 		bo.forced_after = bh.get_forced_after() * 1000;        // value in conf is in seconds
 		if (bld.get_isport()) {
@@ -674,6 +678,11 @@
 			log(" %d: AI 'weak' mode: applying limit %d building(s) for %s\n", player_number(),
 			    bo.cnt_limit_by_aimode, bo.name);
 		}
+		if (type_ == Widelands::AiType::kNormal && bh.get_normal_ai_limit() >= 0) {
+			bo.cnt_limit_by_aimode = bh.get_normal_ai_limit();
+			log(" %d: AI 'normal' mode: applying limit %d building(s) for %s\n", player_number(),
+			    bo.cnt_limit_by_aimode, bo.name);
+		}
 
 		// Read all interesting data from ware producing buildings
 		if (bld.type() == MapObjectType::PRODUCTIONSITE) {
@@ -2575,6 +2584,17 @@
 
 				prio += management_data.neuron_pool[44].get_result_safe(bf->military_score_ / 20) / 5;
 
+				// Some productionsites strictly require supporting sites nearby
+				if (bo.requires_supporters) {
+					uint16_t supporters_nearby = 0;
+					for (auto output : bo.outputs) {
+						supporters_nearby += bf->supporters_nearby.at(output);
+					}
+					if (supporters_nearby == 0) {
+						continue;
+					}
+				}
+
 				// this can be only a well (as by now)
 				if (bo.is(BuildingAttribute::kWell)) {
 


Follow ups