Merge lp:~widelands-dev/widelands/ai_trainingsites_proportion into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8381
Proposed branch: lp:~widelands-dev/widelands/ai_trainingsites_proportion
Merge into: lp:widelands
Diff against target: 209 lines (+75/-4)
9 files modified
data/tribes/buildings/trainingsites/empire/arena/init.lua (+1/-0)
src/ai/ai_hints.cc (+12/-1)
src/ai/ai_hints.h (+5/-0)
src/logic/map_objects/tribes/building.cc (+8/-0)
src/logic/map_objects/tribes/building.h (+2/-3)
src/logic/map_objects/tribes/tribe_descr.cc (+39/-0)
src/logic/map_objects/tribes/tribe_descr.h (+3/-0)
src/logic/map_objects/tribes/tribes.cc (+4/-0)
src/logic/map_objects/tribes/tribes.h (+1/-0)
To merge this branch: bzr merge lp:~widelands-dev/widelands/ai_trainingsites_proportion
Reviewer Review Type Date Requested Status
TiborB Approve
Review via email: mp+324607@code.launchpad.net

Commit message

Added new entry "trainingsites_max_percent" to AI building hints. If this is not set, the percentages will be evenly distributed while loading the tribe. TribeDescr now has a new convenience function trainingsites().

Description of the change

Let's get this in before the big AI change, to make the diff smaller.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2246. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/236078100.
Appveyor build 2081. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_trainingsites_proportion-2081.

Revision history for this message
TiborB (tiborb95) wrote :

The code was already merged and thus tested in AI branch, so this should be safe to merge to trunk. Though I must admit I did not specifically look if this does what it should. Anyway I think it can go

review: Approve
Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the review :)

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2306. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/243567535.
Appveyor build 2140. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_ai_trainingsites_proportion-2140.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 2306. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/243567535.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'data/tribes/buildings/trainingsites/empire/arena/init.lua'
--- data/tribes/buildings/trainingsites/empire/arena/init.lua 2017-02-10 09:40:17 +0000
+++ data/tribes/buildings/trainingsites/empire/arena/init.lua 2017-06-17 05:42:52 +0000
@@ -38,6 +38,7 @@
3838
39 aihints = {39 aihints = {
40 trainingsite_type = "basic",40 trainingsite_type = "basic",
41 trainingsites_max_percent = 20,
41 prohibited_till = 900,42 prohibited_till = 900,
42 very_weak_ai_limit = 1,43 very_weak_ai_limit = 1,
43 weak_ai_limit = 2,44 weak_ai_limit = 2,
4445
=== modified file 'src/ai/ai_hints.cc'
--- src/ai/ai_hints.cc 2017-01-25 18:55:59 +0000
+++ src/ai/ai_hints.cc 2017-06-17 05:42:52 +0000
@@ -44,7 +44,10 @@
44 very_weak_ai_limit_(44 very_weak_ai_limit_(
45 table->has_key("very_weak_ai_limit") ? table->get_int("very_weak_ai_limit") : -1),45 table->has_key("very_weak_ai_limit") ? table->get_int("very_weak_ai_limit") : -1),
46 weak_ai_limit_(table->has_key("weak_ai_limit") ? table->get_int("weak_ai_limit") : -1),46 weak_ai_limit_(table->has_key("weak_ai_limit") ? table->get_int("weak_ai_limit") : -1),
47 trainingsite_type_(TrainingSiteType::kNoTS) {47 trainingsite_type_(TrainingSiteType::kNoTS),
48 trainingsites_max_percent_(table->has_key("trainingsites_max_percent") ?
49 table->get_int("trainingsites_max_percent") :
50 0) {
4851
49 if (table->has_key("trainingsite_type")) {52 if (table->has_key("trainingsite_type")) {
50 if (table->get_string("trainingsite_type") == "basic") {53 if (table->get_string("trainingsite_type") == "basic") {
@@ -54,3 +57,11 @@
54 }57 }
55 }58 }
56}59}
60
61void BuildingHints::set_trainingsites_max_percent(uint8_t percent) {
62 trainingsites_max_percent_ = percent;
63}
64
65uint8_t BuildingHints::trainingsites_max_percent() const {
66 return trainingsites_max_percent_;
67}
5768
=== modified file 'src/ai/ai_hints.h'
--- src/ai/ai_hints.h 2017-01-25 18:55:59 +0000
+++ src/ai/ai_hints.h 2017-06-17 05:42:52 +0000
@@ -115,6 +115,10 @@
115 return trainingsite_type_;115 return trainingsite_type_;
116 }116 }
117117
118 void set_trainingsites_max_percent(uint8_t percent);
119
120 uint8_t trainingsites_max_percent() const;
121
118private:122private:
119 std::string renews_map_resource_;123 std::string renews_map_resource_;
120 std::string mines_;124 std::string mines_;
@@ -134,6 +138,7 @@
134 int16_t very_weak_ai_limit_;138 int16_t very_weak_ai_limit_;
135 int16_t weak_ai_limit_;139 int16_t weak_ai_limit_;
136 TrainingSiteType trainingsite_type_;140 TrainingSiteType trainingsite_type_;
141 int trainingsites_max_percent_;
137142
138 DISALLOW_COPY_AND_ASSIGN(BuildingHints);143 DISALLOW_COPY_AND_ASSIGN(BuildingHints);
139};144};
140145
=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc 2017-05-23 07:00:23 +0000
+++ src/logic/map_objects/tribes/building.cc 2017-06-17 05:42:52 +0000
@@ -189,6 +189,14 @@
189 size_ <= (fc.field->nodecaps() & Widelands::BUILDCAPS_SIZEMASK);189 size_ <= (fc.field->nodecaps() & Widelands::BUILDCAPS_SIZEMASK);
190}190}
191191
192const BuildingHints& BuildingDescr::hints() const {
193 return hints_;
194}
195
196void BuildingDescr::set_hints_trainingsites_max_percent(int percent) {
197 hints_.set_trainingsites_max_percent(percent);
198}
199
192/**200/**
193 * Normal buildings don't conquer anything, so this returns 0 by default.201 * Normal buildings don't conquer anything, so this returns 0 by default.
194 *202 *
195203
=== modified file 'src/logic/map_objects/tribes/building.h'
--- src/logic/map_objects/tribes/building.h 2017-05-21 11:16:46 +0000
+++ src/logic/map_objects/tribes/building.h 2017-06-17 05:42:52 +0000
@@ -157,9 +157,8 @@
157 WorkareaInfo workarea_info_;157 WorkareaInfo workarea_info_;
158158
159 bool suitability(const Map&, const FCoords&) const;159 bool suitability(const Map&, const FCoords&) const;
160 const BuildingHints& hints() const {160 const BuildingHints& hints() const;
161 return hints_;161 void set_hints_trainingsites_max_percent(int percent);
162 }
163162
164protected:163protected:
165 virtual Building& create_object() const = 0;164 virtual Building& create_object() const = 0;
166165
=== modified file 'src/logic/map_objects/tribes/tribe_descr.cc'
--- src/logic/map_objects/tribes/tribe_descr.cc 2017-04-30 10:30:02 +0000
+++ src/logic/map_objects/tribes/tribe_descr.cc 2017-06-17 05:42:52 +0000
@@ -172,6 +172,11 @@
172 }172 }
173 buildings_.push_back(index);173 buildings_.push_back(index);
174174
175 // Register trainigsites
176 if (get_building_descr(index)->type() == MapObjectType::TRAININGSITE) {
177 trainingsites_.push_back(index);
178 }
179
175 // Register construction materials180 // Register construction materials
176 for (const auto& build_cost : get_building_descr(index)->buildcost()) {181 for (const auto& build_cost : get_building_descr(index)->buildcost()) {
177 if (!is_construction_material(build_cost.first)) {182 if (!is_construction_material(build_cost.first)) {
@@ -188,6 +193,36 @@
188 }193 }
189 }194 }
190195
196 // Set default trainingsites proportions for AI. Make sure that we get a sum of ca. 100
197 float trainingsites_without_percent = 0.f;
198 int used_percent = 0;
199 for (const DescriptionIndex& index : trainingsites_) {
200 const BuildingDescr& descr = *tribes_.get_building_descr(index);
201 if (descr.hints().trainingsites_max_percent() == 0) {
202 ++trainingsites_without_percent;
203 } else {
204 used_percent += descr.hints().trainingsites_max_percent();
205 }
206 }
207 if (trainingsites_without_percent > 0.f && used_percent > 100) {
208 throw GameDataError("Predefined training sites proportions add up to > 100%%: %d", used_percent);
209 } else if (trainingsites_without_percent > 0) {
210 const int percent_to_use = std::ceil((100 - used_percent) / trainingsites_without_percent);
211 if (percent_to_use < 1) {
212 throw GameDataError("Training sites without predefined proportions add up to < 1%% and will never be built: %d", used_percent);
213 }
214 for (const DescriptionIndex& index : trainingsites_) {
215 BuildingDescr* descr = tribes_.get_mutable_building_descr(index);
216 if (descr->hints().trainingsites_max_percent() == 0) {
217 descr->set_hints_trainingsites_max_percent(percent_to_use);
218 used_percent += percent_to_use;
219 }
220 }
221 }
222 if (used_percent < 100) {
223 throw GameDataError("Final training sites proportions add up to < 100%%: %d", used_percent);
224 }
225
191 // Special types226 // Special types
192 builder_ = add_special_worker(table.get_string("builder"));227 builder_ = add_special_worker(table.get_string("builder"));
193 carrier_ = add_special_worker(table.get_string("carrier"));228 carrier_ = add_special_worker(table.get_string("carrier"));
@@ -333,6 +368,10 @@
333 assert(tribes_.building_exists(barracks_));368 assert(tribes_.building_exists(barracks_));
334 return barracks_;369 return barracks_;
335}370}
371
372const std::vector<DescriptionIndex>& TribeDescr::trainingsites() const {
373 return trainingsites_;
374}
336const std::vector<DescriptionIndex>& TribeDescr::worker_types_without_cost() const {375const std::vector<DescriptionIndex>& TribeDescr::worker_types_without_cost() const {
337 return worker_types_without_cost_;376 return worker_types_without_cost_;
338}377}
339378
=== modified file 'src/logic/map_objects/tribes/tribe_descr.h'
--- src/logic/map_objects/tribes/tribe_descr.h 2017-04-30 10:30:02 +0000
+++ src/logic/map_objects/tribes/tribe_descr.h 2017-06-17 05:42:52 +0000
@@ -105,6 +105,8 @@
105 DescriptionIndex headquarters() const;105 DescriptionIndex headquarters() const;
106 DescriptionIndex port() const;106 DescriptionIndex port() const;
107 DescriptionIndex barracks() const;107 DescriptionIndex barracks() const;
108
109 const std::vector<DescriptionIndex>& trainingsites() const;
108 const std::vector<DescriptionIndex>& worker_types_without_cost() const;110 const std::vector<DescriptionIndex>& worker_types_without_cost() const;
109111
110 uint32_t frontier_animation() const;112 uint32_t frontier_animation() const;
@@ -186,6 +188,7 @@
186 DescriptionIndex port_; // The port that this tribe uses188 DescriptionIndex port_; // The port that this tribe uses
187 DescriptionIndex barracks_; // The barracks to create soldiers189 DescriptionIndex barracks_; // The barracks to create soldiers
188 std::vector<DescriptionIndex> worker_types_without_cost_;190 std::vector<DescriptionIndex> worker_types_without_cost_;
191 std::vector<DescriptionIndex> trainingsites_;
189 // Order and positioning of wares in the warehouse display192 // Order and positioning of wares in the warehouse display
190 WaresOrder wares_order_;193 WaresOrder wares_order_;
191 WaresOrderCoords wares_order_coords_;194 WaresOrderCoords wares_order_coords_;
192195
=== modified file 'src/logic/map_objects/tribes/tribes.cc'
--- src/logic/map_objects/tribes/tribes.cc 2017-01-30 14:40:12 +0000
+++ src/logic/map_objects/tribes/tribes.cc 2017-06-17 05:42:52 +0000
@@ -284,6 +284,10 @@
284 return buildings_->get_mutable(buildingindex);284 return buildings_->get_mutable(buildingindex);
285}285}
286286
287BuildingDescr* Tribes::get_mutable_building_descr(DescriptionIndex buildingindex) const {
288 return buildings_->get_mutable(buildingindex);
289}
290
287const ImmovableDescr* Tribes::get_immovable_descr(DescriptionIndex immovableindex) const {291const ImmovableDescr* Tribes::get_immovable_descr(DescriptionIndex immovableindex) const {
288 return immovables_->get_mutable(immovableindex);292 return immovables_->get_mutable(immovableindex);
289}293}
290294
=== modified file 'src/logic/map_objects/tribes/tribes.h'
--- src/logic/map_objects/tribes/tribes.h 2017-01-30 14:40:12 +0000
+++ src/logic/map_objects/tribes/tribes.h 2017-06-17 05:42:52 +0000
@@ -131,6 +131,7 @@
131 DescriptionIndex worker_index(const std::string& workername) const;131 DescriptionIndex worker_index(const std::string& workername) const;
132132
133 const BuildingDescr* get_building_descr(DescriptionIndex building_index) const;133 const BuildingDescr* get_building_descr(DescriptionIndex building_index) const;
134 BuildingDescr* get_mutable_building_descr(DescriptionIndex building_index) const;
134 const ImmovableDescr* get_immovable_descr(DescriptionIndex immovable_index) const;135 const ImmovableDescr* get_immovable_descr(DescriptionIndex immovable_index) const;
135 const ShipDescr* get_ship_descr(DescriptionIndex ship_index) const;136 const ShipDescr* get_ship_descr(DescriptionIndex ship_index) const;
136 const WareDescr* get_ware_descr(DescriptionIndex ware_index) const;137 const WareDescr* get_ware_descr(DescriptionIndex ware_index) const;

Subscribers

People subscribed via source and target branches

to status/vote changes: