Merge lp:~widelands-dev/widelands/ai_remove_iterators into lp:widelands
- ai_remove_iterators
- Merge into trunk
Proposed by
GunChleoc
Status: | Work in progress |
---|---|
Proposed branch: | lp:~widelands-dev/widelands/ai_remove_iterators |
Merge into: | lp:widelands |
Prerequisite: | lp:~widelands-dev/widelands/seafaring-ai |
Diff against target: |
1037 lines (+217/-239) 2 files modified
src/ai/ai_help_structs.h (+17/-0) src/ai/defaultai.cc (+200/-239) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/ai_remove_iterators |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Widelands Developers | Pending | ||
Review via email: mp+243894@code.launchpad.net |
Commit message
Description of the change
This isn't quite ready yet, but I wanted to get some feedback before I finish.
I have replaced all easy iterator loops with ranged-based for loops. The remaining ones have erase operations in them for objects that don't have a comparator yet. In order for them to work, I will have to add them to the ai_help_structs.h like this: http://
I think this makes the AI code more readable, but if you think this is overkill, I will leave it.
To post a comment you must log in.
Revision history for this message
GunChleoc (gunchleoc) wrote : | # |
Definitely, I just wanted an opinion before I continue :)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/ai/ai_help_structs.h' | |||
2 | --- src/ai/ai_help_structs.h 2014-12-16 11:37:49 +0000 | |||
3 | +++ src/ai/ai_help_structs.h 2014-12-16 11:37:49 +0000 | |||
4 | @@ -189,6 +189,14 @@ | |||
5 | 189 | Widelands::FCoords coords; | 189 | Widelands::FCoords coords; |
6 | 190 | int32_t blocked_until_; | 190 | int32_t blocked_until_; |
7 | 191 | 191 | ||
8 | 192 | bool operator== (const BlockedField& other) const { | ||
9 | 193 | return coords == other.coords; | ||
10 | 194 | } | ||
11 | 195 | |||
12 | 196 | bool operator!= (const BlockedField& other) const { | ||
13 | 197 | return coords != other.coords; | ||
14 | 198 | } | ||
15 | 199 | |||
16 | 192 | BlockedField(Widelands::FCoords c, int32_t until) : coords(c), blocked_until_(until) { | 200 | BlockedField(Widelands::FCoords c, int32_t until) : coords(c), blocked_until_(until) { |
17 | 193 | } | 201 | } |
18 | 194 | }; | 202 | }; |
19 | @@ -387,6 +395,15 @@ | |||
20 | 387 | }; | 395 | }; |
21 | 388 | 396 | ||
22 | 389 | struct ShipObserver { | 397 | struct ShipObserver { |
23 | 398 | |||
24 | 399 | bool operator== (const ShipObserver& other) const { | ||
25 | 400 | return ship->serial() == other.ship->serial(); | ||
26 | 401 | } | ||
27 | 402 | |||
28 | 403 | bool operator!= (const ShipObserver& other) const { | ||
29 | 404 | return ship->serial() != other.ship->serial(); | ||
30 | 405 | } | ||
31 | 406 | |||
32 | 390 | Widelands::Ship* ship; | 407 | Widelands::Ship* ship; |
33 | 391 | Widelands::Coords expedition_start_point_; | 408 | Widelands::Coords expedition_start_point_; |
34 | 392 | std::unordered_set<uint32_t> visited_spots_; | 409 | std::unordered_set<uint32_t> visited_spots_; |
35 | 393 | 410 | ||
36 | === modified file 'src/ai/defaultai.cc' | |||
37 | --- src/ai/defaultai.cc 2014-12-16 11:37:49 +0000 | |||
38 | +++ src/ai/defaultai.cc 2014-12-16 11:37:49 +0000 | |||
39 | @@ -181,19 +181,17 @@ | |||
40 | 181 | } | 181 | } |
41 | 182 | break; | 182 | break; |
42 | 183 | 183 | ||
47 | 184 | case NoteShipMessage::Message::kLost: | 184 | case NoteShipMessage::Message::kLost: { |
48 | 185 | for (std::list<ShipObserver>::iterator i = allships.begin(); i != allships.end(); ++i) { | 185 | for (const ShipObserver& ship_observer : allships) { |
49 | 186 | if (i->ship == note.ship) { | 186 | if (ship_observer.ship == note.ship) { |
50 | 187 | allships.erase(i); | 187 | allships.remove(ship_observer); |
51 | 188 | break; | 188 | break; |
60 | 189 | } | 189 | } |
61 | 190 | } | 190 | } |
62 | 191 | break; | 191 | case NoteShipMessage::Message::kWaitingForCommand: |
63 | 192 | 192 | for (ShipObserver& ship_observer : allships) { | |
64 | 193 | case NoteShipMessage::Message::kWaitingForCommand: | 193 | if (ship_observer.ship == note.ship) { |
65 | 194 | for (std::list<ShipObserver>::iterator i = allships.begin(); i != allships.end(); ++i) { | 194 | ship_observer.waiting_for_command_ = true; |
58 | 195 | if (i->ship == note.ship) { | ||
59 | 196 | i->waiting_for_command_ = true; | ||
66 | 197 | break; | 195 | break; |
67 | 198 | } | 196 | } |
68 | 199 | } | 197 | } |
69 | @@ -201,7 +199,8 @@ | |||
70 | 201 | default: | 199 | default: |
71 | 202 | ; | 200 | ; |
72 | 203 | } | 201 | } |
74 | 204 | }); | 202 | } |
75 | 203 | }); | ||
76 | 205 | } | 204 | } |
77 | 206 | 205 | ||
78 | 207 | DefaultAI::~DefaultAI() { | 206 | DefaultAI::~DefaultAI() { |
79 | @@ -1032,10 +1031,8 @@ | |||
80 | 1032 | for (int32_t i = 0; i < 4; ++i) | 1031 | for (int32_t i = 0; i < 4; ++i) |
81 | 1033 | spots_avail.at(i) = 0; | 1032 | spots_avail.at(i) = 0; |
82 | 1034 | 1033 | ||
87 | 1035 | for (std::list<BuildableField*>::iterator i = buildable_fields.begin(); | 1034 | for (const BuildableField* buildable_field : buildable_fields) |
88 | 1036 | i != buildable_fields.end(); | 1035 | ++spots_avail.at(buildable_field->coords.field->nodecaps() & BUILDCAPS_SIZEMASK); |
85 | 1037 | ++i) | ||
86 | 1038 | ++spots_avail.at((*i)->coords.field->nodecaps() & BUILDCAPS_SIZEMASK); | ||
89 | 1039 | 1036 | ||
90 | 1040 | spots_ = spots_avail.at(BUILDCAPS_SMALL); | 1037 | spots_ = spots_avail.at(BUILDCAPS_SMALL); |
91 | 1041 | spots_ += spots_avail.at(BUILDCAPS_MEDIUM); | 1038 | spots_ += spots_avail.at(BUILDCAPS_MEDIUM); |
92 | @@ -1125,12 +1122,11 @@ | |||
93 | 1125 | Coords proposed_coords; | 1122 | Coords proposed_coords; |
94 | 1126 | 1123 | ||
95 | 1127 | // Remove outdated fields from blocker list | 1124 | // Remove outdated fields from blocker list |
101 | 1128 | for (std::list<BlockedField>::iterator i = blocked_fields.begin(); i != blocked_fields.end();) | 1125 | for (const BlockedField& blocked_field : blocked_fields) { |
102 | 1129 | if (i->blocked_until_ < game().get_gametime()) { | 1126 | if (blocked_field.blocked_until_ < game().get_gametime()) { |
103 | 1130 | i = blocked_fields.erase(i); | 1127 | blocked_fields.remove(blocked_field); |
99 | 1131 | } else { | ||
100 | 1132 | ++i; | ||
104 | 1133 | } | 1128 | } |
105 | 1129 | } | ||
106 | 1134 | 1130 | ||
107 | 1135 | // testing big military buildings, whether critical construction | 1131 | // testing big military buildings, whether critical construction |
108 | 1136 | // material is available (at least in amount of | 1132 | // material is available (at least in amount of |
109 | @@ -1169,21 +1165,17 @@ | |||
110 | 1169 | int16_t max_needed_preciousness = 0; // preciousness_ of most precious NEEDED output | 1165 | int16_t max_needed_preciousness = 0; // preciousness_ of most precious NEEDED output |
111 | 1170 | 1166 | ||
112 | 1171 | // first scan all buildable fields for regular buildings | 1167 | // first scan all buildable fields for regular buildings |
117 | 1172 | for (std::list<BuildableField*>::iterator i = buildable_fields.begin(); | 1168 | for (const BuildableField* buildable_field : buildable_fields) { |
114 | 1173 | i != buildable_fields.end(); | ||
115 | 1174 | ++i) { | ||
116 | 1175 | BuildableField* const bf = *i; | ||
118 | 1176 | 1169 | ||
120 | 1177 | if (bf->next_update_due_ < gametime - 8000) { | 1170 | if (buildable_field->next_update_due_ < gametime - 8000) { |
121 | 1178 | continue; | 1171 | continue; |
122 | 1179 | } | 1172 | } |
123 | 1180 | 1173 | ||
124 | 1181 | // Continue if field is blocked at the moment | 1174 | // Continue if field is blocked at the moment |
125 | 1182 | field_blocked = false; | 1175 | field_blocked = false; |
126 | 1183 | 1176 | ||
130 | 1184 | for (std::list<BlockedField>::iterator j = blocked_fields.begin(); j != blocked_fields.end(); | 1177 | for (const BlockedField& blocked_field : blocked_fields) { |
131 | 1185 | ++j) { | 1178 | if (blocked_field.coords == buildable_field->coords) { |
129 | 1186 | if (j->coords == bf->coords) { | ||
132 | 1187 | field_blocked = true; | 1179 | field_blocked = true; |
133 | 1188 | } | 1180 | } |
134 | 1189 | } | 1181 | } |
135 | @@ -1194,7 +1186,7 @@ | |||
136 | 1194 | } | 1186 | } |
137 | 1195 | 1187 | ||
138 | 1196 | assert(player_); | 1188 | assert(player_); |
140 | 1197 | int32_t const maxsize = player_->get_buildcaps(bf->coords) & BUILDCAPS_SIZEMASK; | 1189 | int32_t const maxsize = player_->get_buildcaps(buildable_field->coords) & BUILDCAPS_SIZEMASK; |
141 | 1198 | 1190 | ||
142 | 1199 | // For every field test all buildings | 1191 | // For every field test all buildings |
143 | 1200 | for (uint32_t j = 0; j < buildings_.size(); ++j) { | 1192 | for (uint32_t j = 0; j < buildings_.size(); ++j) { |
144 | @@ -1215,7 +1207,7 @@ | |||
145 | 1215 | 1207 | ||
146 | 1216 | // testing for reserved ports | 1208 | // testing for reserved ports |
147 | 1217 | if (!bo.is_port_) { | 1209 | if (!bo.is_port_) { |
149 | 1218 | if (port_reserved_coords.count(coords_hash(bf->coords)) > 0) { | 1210 | if (port_reserved_coords.count(coords_hash(buildable_field->coords)) > 0) { |
150 | 1219 | continue; | 1211 | continue; |
151 | 1220 | } | 1212 | } |
152 | 1221 | } | 1213 | } |
153 | @@ -1251,13 +1243,13 @@ | |||
154 | 1251 | if (bo.type == BuildingObserver::PRODUCTIONSITE) { | 1243 | if (bo.type == BuildingObserver::PRODUCTIONSITE) { |
155 | 1252 | 1244 | ||
156 | 1253 | // exclude spots on border | 1245 | // exclude spots on border |
158 | 1254 | if (bf->near_border_ && !bo.need_trees_ && !bo.need_stones_ && !bo.is_fisher_) { | 1246 | if (buildable_field->near_border_ && !bo.need_trees_ && !bo.need_stones_ && !bo.is_fisher_) { |
159 | 1255 | continue; | 1247 | continue; |
160 | 1256 | } | 1248 | } |
161 | 1257 | 1249 | ||
162 | 1258 | // this can be only a well (as by now) | 1250 | // this can be only a well (as by now) |
163 | 1259 | if (bo.mines_water_) { | 1251 | if (bo.mines_water_) { |
165 | 1260 | if (bf->ground_water_ < 2) { | 1252 | if (buildable_field->ground_water_ < 2) { |
166 | 1261 | continue; | 1253 | continue; |
167 | 1262 | } | 1254 | } |
168 | 1263 | 1255 | ||
169 | @@ -1283,8 +1275,8 @@ | |||
170 | 1283 | if (bo.stocklevel_ > 50 + productionsites.size() * 5) { | 1275 | if (bo.stocklevel_ > 50 + productionsites.size() * 5) { |
171 | 1284 | continue; | 1276 | continue; |
172 | 1285 | } | 1277 | } |
175 | 1286 | prio += bf->ground_water_ - 2; | 1278 | prio += buildable_field->ground_water_ - 2; |
176 | 1287 | prio = recalc_with_border_range(*bf, prio); | 1279 | prio = recalc_with_border_range(*buildable_field, prio); |
177 | 1288 | 1280 | ||
178 | 1289 | } else if (bo.need_trees_) { // LUMBERJACS | 1281 | } else if (bo.need_trees_) { // LUMBERJACS |
179 | 1290 | 1282 | ||
180 | @@ -1292,14 +1284,14 @@ | |||
181 | 1292 | 3 + static_cast<int32_t>(mines_.size() + productionsites.size()) / 15; | 1284 | 3 + static_cast<int32_t>(mines_.size() + productionsites.size()) / 15; |
182 | 1293 | 1285 | ||
183 | 1294 | if (bo.total_count() == 0) { | 1286 | if (bo.total_count() == 0) { |
185 | 1295 | prio = 500 + bf->trees_nearby_; | 1287 | prio = 500 + buildable_field->trees_nearby_; |
186 | 1296 | } | 1288 | } |
187 | 1297 | 1289 | ||
188 | 1298 | else if (bo.total_count() == 1) { | 1290 | else if (bo.total_count() == 1) { |
190 | 1299 | prio = 400 + bf->trees_nearby_; | 1291 | prio = 400 + buildable_field->trees_nearby_; |
191 | 1300 | } | 1292 | } |
192 | 1301 | 1293 | ||
194 | 1302 | else if (bf->trees_nearby_ < 2) { | 1294 | else if (buildable_field->trees_nearby_ < 2) { |
195 | 1303 | continue; | 1295 | continue; |
196 | 1304 | } | 1296 | } |
197 | 1305 | 1297 | ||
198 | @@ -1311,15 +1303,15 @@ | |||
199 | 1311 | prio = 0; | 1303 | prio = 0; |
200 | 1312 | } | 1304 | } |
201 | 1313 | 1305 | ||
203 | 1314 | if (bf->producers_nearby_.at(bo.outputs_.at(0)) > 1) { | 1306 | if (buildable_field->producers_nearby_.at(bo.outputs_.at(0)) > 1) { |
204 | 1315 | continue; | 1307 | continue; |
205 | 1316 | } | 1308 | } |
206 | 1317 | 1309 | ||
209 | 1318 | prio += 2 * bf->trees_nearby_ - 10 - | 1310 | prio += 2 * buildable_field->trees_nearby_ - 10 - |
210 | 1319 | bf->producers_nearby_.at(bo.outputs_.at(0)) * 5 - | 1311 | buildable_field->producers_nearby_.at(bo.outputs_.at(0)) * 5 - |
211 | 1320 | new_buildings_stop_ * 15; | 1312 | new_buildings_stop_ * 15; |
212 | 1321 | 1313 | ||
214 | 1322 | if (bf->near_border_) { | 1314 | if (buildable_field->near_border_) { |
215 | 1323 | prio = prio / 2; | 1315 | prio = prio / 2; |
216 | 1324 | } | 1316 | } |
217 | 1325 | } | 1317 | } |
218 | @@ -1332,7 +1324,7 @@ | |||
219 | 1332 | if (bo.cnt_under_construction_ > 0) { | 1324 | if (bo.cnt_under_construction_ > 0) { |
220 | 1333 | continue; | 1325 | continue; |
221 | 1334 | } | 1326 | } |
223 | 1335 | prio = bf->stones_nearby_; | 1327 | prio = buildable_field->stones_nearby_; |
224 | 1336 | 1328 | ||
225 | 1337 | if (prio <= 0) { | 1329 | if (prio <= 0) { |
226 | 1338 | continue; | 1330 | continue; |
227 | @@ -1352,14 +1344,14 @@ | |||
228 | 1352 | } | 1344 | } |
229 | 1353 | 1345 | ||
230 | 1354 | // to prevent to many quaries on one spot | 1346 | // to prevent to many quaries on one spot |
232 | 1355 | prio = prio - 50 * bf->producers_nearby_.at(bo.outputs_.at(0)); | 1347 | prio = prio - 50 * buildable_field->producers_nearby_.at(bo.outputs_.at(0)); |
233 | 1356 | 1348 | ||
235 | 1357 | if (bf->near_border_) { | 1349 | if (buildable_field->near_border_) { |
236 | 1358 | prio = prio / 2; | 1350 | prio = prio / 2; |
237 | 1359 | } | 1351 | } |
238 | 1360 | 1352 | ||
239 | 1361 | } else if (bo.is_hunter_) { | 1353 | } else if (bo.is_hunter_) { |
241 | 1362 | if (bf->critters_nearby_ < 5) { | 1354 | if (buildable_field->critters_nearby_ < 5) { |
242 | 1363 | continue; | 1355 | continue; |
243 | 1364 | } | 1356 | } |
244 | 1365 | 1357 | ||
245 | @@ -1368,7 +1360,7 @@ | |||
246 | 1368 | } | 1360 | } |
247 | 1369 | 1361 | ||
248 | 1370 | prio += | 1362 | prio += |
250 | 1371 | (bf->critters_nearby_ * 2) - 8 - 5 * bf->producers_nearby_.at(bo.outputs_.at(0)); | 1363 | (buildable_field->critters_nearby_ * 2) - 8 - 5 * buildable_field->producers_nearby_.at(bo.outputs_.at(0)); |
251 | 1372 | 1364 | ||
252 | 1373 | } else if (bo.is_fisher_) { // fisher | 1365 | } else if (bo.is_fisher_) { // fisher |
253 | 1374 | 1366 | ||
254 | @@ -1381,7 +1373,7 @@ | |||
255 | 1381 | continue; | 1373 | continue; |
256 | 1382 | } | 1374 | } |
257 | 1383 | 1375 | ||
259 | 1384 | if (bf->water_nearby_ < 2) { | 1376 | if (buildable_field->water_nearby_ < 2) { |
260 | 1385 | continue; | 1377 | continue; |
261 | 1386 | } | 1378 | } |
262 | 1387 | 1379 | ||
263 | @@ -1400,11 +1392,11 @@ | |||
264 | 1400 | continue; | 1392 | continue; |
265 | 1401 | } | 1393 | } |
266 | 1402 | 1394 | ||
268 | 1403 | if (bf->producers_nearby_.at(bo.outputs_.at(0)) >= 1) { | 1395 | if (buildable_field->producers_nearby_.at(bo.outputs_.at(0)) >= 1) { |
269 | 1404 | continue; | 1396 | continue; |
270 | 1405 | } | 1397 | } |
271 | 1406 | 1398 | ||
273 | 1407 | prio = bf->fish_nearby_ - new_buildings_stop_ * 15 * bo.total_count(); | 1399 | prio = buildable_field->fish_nearby_ - new_buildings_stop_ * 15 * bo.total_count(); |
274 | 1408 | 1400 | ||
275 | 1409 | } else if (bo.production_hint_ >= 0) { | 1401 | } else if (bo.production_hint_ >= 0) { |
276 | 1410 | // first setting targets (needed also for dismantling) | 1402 | // first setting targets (needed also for dismantling) |
277 | @@ -1423,7 +1415,7 @@ | |||
278 | 1423 | if (bo.plants_trees_) { // RANGERS | 1415 | if (bo.plants_trees_) { // RANGERS |
279 | 1424 | 1416 | ||
280 | 1425 | // if there are too many trees nearby | 1417 | // if there are too many trees nearby |
282 | 1426 | if (bf->trees_nearby_ > 25 && bo.total_count() >= 1) { | 1418 | if (buildable_field->trees_nearby_ > 25 && bo.total_count() >= 1) { |
283 | 1427 | continue; | 1419 | continue; |
284 | 1428 | } | 1420 | } |
285 | 1429 | 1421 | ||
286 | @@ -1451,12 +1443,12 @@ | |||
287 | 1451 | } | 1443 | } |
288 | 1452 | 1444 | ||
289 | 1453 | // considering near trees and producers | 1445 | // considering near trees and producers |
292 | 1454 | prio += (30 - bf->trees_nearby_) * 2 + | 1446 | prio += (30 - buildable_field->trees_nearby_) * 2 + |
293 | 1455 | bf->producers_nearby_.at(bo.production_hint_) * 5 - | 1447 | buildable_field->producers_nearby_.at(bo.production_hint_) * 5 - |
294 | 1456 | new_buildings_stop_ * 15; | 1448 | new_buildings_stop_ * 15; |
295 | 1457 | 1449 | ||
296 | 1458 | // considering space consumers nearby | 1450 | // considering space consumers nearby |
298 | 1459 | prio -= bf->space_consumers_nearby_ * 5; | 1451 | prio -= buildable_field->space_consumers_nearby_ * 5; |
299 | 1460 | 1452 | ||
300 | 1461 | } else { // FISH BREEDERS and GAME KEEPERS | 1453 | } else { // FISH BREEDERS and GAME KEEPERS |
301 | 1462 | if (new_buildings_stop_ && bo.total_count() > 0) { | 1454 | if (new_buildings_stop_ && bo.total_count() > 0) { |
302 | @@ -1464,11 +1456,11 @@ | |||
303 | 1464 | } | 1456 | } |
304 | 1465 | 1457 | ||
305 | 1466 | // especially for fish breeders | 1458 | // especially for fish breeders |
307 | 1467 | if (bo.need_water_ && bf->water_nearby_ < 2) { | 1459 | if (bo.need_water_ && buildable_field->water_nearby_ < 2) { |
308 | 1468 | continue; | 1460 | continue; |
309 | 1469 | } | 1461 | } |
310 | 1470 | if (bo.need_water_) { | 1462 | if (bo.need_water_) { |
312 | 1471 | prio += bf->water_nearby_ / 5; | 1463 | prio += buildable_field->water_nearby_ / 5; |
313 | 1472 | } | 1464 | } |
314 | 1473 | 1465 | ||
315 | 1474 | if (bo.total_count() > bo.cnt_target_) { | 1466 | if (bo.total_count() > bo.cnt_target_) { |
316 | @@ -1485,14 +1477,14 @@ | |||
317 | 1485 | } | 1477 | } |
318 | 1486 | 1478 | ||
319 | 1487 | if (bo.total_count() == 0 && gametime > 45 * 1000) { | 1479 | if (bo.total_count() == 0 && gametime > 45 * 1000) { |
322 | 1488 | prio += 100 + bf->producers_nearby_.at(bo.production_hint_) * 10; | 1480 | prio += 100 + buildable_field->producers_nearby_.at(bo.production_hint_) * 10; |
323 | 1489 | } else if (bf->producers_nearby_.at(bo.production_hint_) == 0) { | 1481 | } else if (buildable_field->producers_nearby_.at(bo.production_hint_) == 0) { |
324 | 1490 | continue; | 1482 | continue; |
325 | 1491 | } else { | 1483 | } else { |
327 | 1492 | prio += bf->producers_nearby_.at(bo.production_hint_) * 10; | 1484 | prio += buildable_field->producers_nearby_.at(bo.production_hint_) * 10; |
328 | 1493 | } | 1485 | } |
329 | 1494 | 1486 | ||
331 | 1495 | if (bf->enemy_nearby_) { | 1487 | if (buildable_field->enemy_nearby_) { |
332 | 1496 | prio -= 10; | 1488 | prio -= 10; |
333 | 1497 | } | 1489 | } |
334 | 1498 | } | 1490 | } |
335 | @@ -1536,34 +1528,34 @@ | |||
336 | 1536 | prio += max_needed_preciousness + kDefaultPrioBoost; | 1528 | prio += max_needed_preciousness + kDefaultPrioBoost; |
337 | 1537 | 1529 | ||
338 | 1538 | if (bo.space_consumer_) { // need to consider trees nearby | 1530 | if (bo.space_consumer_) { // need to consider trees nearby |
340 | 1539 | prio += 20 - (bf->trees_nearby_ / 3); | 1531 | prio += 20 - (buildable_field->trees_nearby_ / 3); |
341 | 1540 | } | 1532 | } |
342 | 1541 | 1533 | ||
343 | 1542 | // we attempt to cluster space consumers together | 1534 | // we attempt to cluster space consumers together |
344 | 1543 | if (bo.space_consumer_) { // need to consider trees nearby | 1535 | if (bo.space_consumer_) { // need to consider trees nearby |
346 | 1544 | prio += bf->space_consumers_nearby_ * 2; | 1536 | prio += buildable_field->space_consumers_nearby_ * 2; |
347 | 1545 | } | 1537 | } |
348 | 1546 | 1538 | ||
350 | 1547 | if (bo.space_consumer_ && !bf->water_nearby_) { // not close to water | 1539 | if (bo.space_consumer_ && !buildable_field->water_nearby_) { // not close to water |
351 | 1548 | prio += 1; | 1540 | prio += 1; |
352 | 1549 | } | 1541 | } |
353 | 1550 | 1542 | ||
354 | 1551 | if (bo.space_consumer_ && | 1543 | if (bo.space_consumer_ && |
356 | 1552 | !bf->unowned_mines_pots_nearby_) { // not close to mountains | 1544 | !buildable_field->unowned_mines_pots_nearby_) { // not close to mountains |
357 | 1553 | prio += 1; | 1545 | prio += 1; |
358 | 1554 | } | 1546 | } |
359 | 1555 | 1547 | ||
360 | 1556 | if (!bo.space_consumer_) { | 1548 | if (!bo.space_consumer_) { |
362 | 1557 | prio -= bf->producers_nearby_.at(bo.outputs_.at(0)) * 20; | 1549 | prio -= buildable_field->producers_nearby_.at(bo.outputs_.at(0)) * 20; |
363 | 1558 | } // leave some free space between them | 1550 | } // leave some free space between them |
364 | 1559 | 1551 | ||
366 | 1560 | prio -= bf->space_consumers_nearby_ * 3; | 1552 | prio -= buildable_field->space_consumers_nearby_ * 3; |
367 | 1561 | } | 1553 | } |
368 | 1562 | 1554 | ||
369 | 1563 | else if (bo.is_shipyard_) { | 1555 | else if (bo.is_shipyard_) { |
370 | 1564 | // for now AI builds only one shipyard | 1556 | // for now AI builds only one shipyard |
373 | 1565 | if (bf->water_nearby_ > 3 && bo.total_count() == 0 && seafaring_economy) { | 1557 | if (buildable_field->water_nearby_ > 3 && bo.total_count() == 0 && seafaring_economy) { |
374 | 1566 | prio += kDefaultPrioBoost + productionsites.size() * 5 + bf->water_nearby_; | 1558 | prio += kDefaultPrioBoost + productionsites.size() * 5 + buildable_field->water_nearby_; |
375 | 1567 | } | 1559 | } |
376 | 1568 | 1560 | ||
377 | 1569 | } else if (!bo.inputs_.empty()) { | 1561 | } else if (!bo.inputs_.empty()) { |
378 | @@ -1584,7 +1576,7 @@ | |||
379 | 1584 | consumers_nearby_count = 0; | 1576 | consumers_nearby_count = 0; |
380 | 1585 | 1577 | ||
381 | 1586 | for (size_t k = 0; k < bo.outputs_.size(); ++k) | 1578 | for (size_t k = 0; k < bo.outputs_.size(); ++k) |
383 | 1587 | consumers_nearby_count += bf->consumers_nearby_.at(bo.outputs_.at(k)); | 1579 | consumers_nearby_count += buildable_field->consumers_nearby_.at(bo.outputs_.at(k)); |
384 | 1588 | 1580 | ||
385 | 1589 | if (consumers_nearby_count > 0) { | 1581 | if (consumers_nearby_count > 0) { |
386 | 1590 | prio += 1; | 1582 | prio += 1; |
387 | @@ -1595,11 +1587,11 @@ | |||
388 | 1595 | 1587 | ||
389 | 1596 | // we allow 1 exemption from big buildings prohibition | 1588 | // we allow 1 exemption from big buildings prohibition |
390 | 1597 | if (bo.build_material_shortage_ && | 1589 | if (bo.build_material_shortage_ && |
392 | 1598 | (bo.cnt_under_construction_ > 0 || !(bf->enemy_nearby_))) { | 1590 | (bo.cnt_under_construction_ > 0 || !(buildable_field->enemy_nearby_))) { |
393 | 1599 | continue; | 1591 | continue; |
394 | 1600 | } | 1592 | } |
395 | 1601 | 1593 | ||
397 | 1602 | if (!bf->unowned_land_nearby_) { | 1594 | if (!buildable_field->unowned_land_nearby_) { |
398 | 1603 | continue; | 1595 | continue; |
399 | 1604 | } | 1596 | } |
400 | 1605 | 1597 | ||
401 | @@ -1611,21 +1603,21 @@ | |||
402 | 1611 | continue; | 1603 | continue; |
403 | 1612 | } | 1604 | } |
404 | 1613 | 1605 | ||
406 | 1614 | if (expansion_mode == kDefenseOnly && !bf->enemy_nearby_) { | 1606 | if (expansion_mode == kDefenseOnly && !buildable_field->enemy_nearby_) { |
407 | 1615 | continue; | 1607 | continue; |
408 | 1616 | } | 1608 | } |
409 | 1617 | 1609 | ||
411 | 1618 | if (bf->enemy_nearby_ && bo.fighting_type_) { | 1610 | if (buildable_field->enemy_nearby_ && bo.fighting_type_) { |
412 | 1619 | ; | 1611 | ; |
413 | 1620 | } // it is ok, go on | 1612 | } // it is ok, go on |
415 | 1621 | else if (bf->unowned_mines_pots_nearby_ > 2 && | 1613 | else if (buildable_field->unowned_mines_pots_nearby_ > 2 && |
416 | 1622 | (bo.mountain_conqueror_ || bo.expansion_type_)) { | 1614 | (bo.mountain_conqueror_ || bo.expansion_type_)) { |
417 | 1623 | ; | 1615 | ; |
418 | 1624 | } // it is ok, go on | 1616 | } // it is ok, go on |
420 | 1625 | else if (bf->unowned_land_nearby_ && bo.expansion_type_ && | 1617 | else if (buildable_field->unowned_land_nearby_ && bo.expansion_type_ && |
421 | 1626 | num_milit_constructionsites <= 1) { | 1618 | num_milit_constructionsites <= 1) { |
422 | 1627 | ; // we allow big buildings now | 1619 | ; // we allow big buildings now |
424 | 1628 | } else if (bf->unowned_land_nearby_ && | 1620 | } else if (buildable_field->unowned_land_nearby_ && |
425 | 1629 | bo.expansion_type_) { // decreasing probability for big buidlings | 1621 | bo.expansion_type_) { // decreasing probability for big buidlings |
426 | 1630 | if (bo.desc->get_size() == 2 && gametime % 15 >= 1) { | 1622 | if (bo.desc->get_size() == 2 && gametime % 15 >= 1) { |
427 | 1631 | continue; | 1623 | continue; |
428 | @@ -1640,8 +1632,8 @@ | |||
429 | 1640 | } // the building is not suitable for situation | 1632 | } // the building is not suitable for situation |
430 | 1641 | 1633 | ||
431 | 1642 | // not to build so many military buildings nearby | 1634 | // not to build so many military buildings nearby |
434 | 1643 | if (!bf->enemy_nearby_ && | 1635 | if (!buildable_field->enemy_nearby_ && |
435 | 1644 | (bf->military_in_constr_nearby_ + bf->military_unstationed_) > 0) { | 1636 | (buildable_field->military_in_constr_nearby_ + buildable_field->military_unstationed_) > 0) { |
436 | 1645 | continue; | 1637 | continue; |
437 | 1646 | } | 1638 | } |
438 | 1647 | 1639 | ||
439 | @@ -1651,14 +1643,14 @@ | |||
440 | 1651 | local_boost = 200; | 1643 | local_boost = 200; |
441 | 1652 | } | 1644 | } |
442 | 1653 | 1645 | ||
447 | 1654 | prio = (bf->unowned_land_nearby_ * 2 * resource_necessity_territory_ / 255 + | 1646 | prio = (buildable_field->unowned_land_nearby_ * 2 * resource_necessity_territory_ / 255 + |
448 | 1655 | bf->unowned_mines_pots_nearby_ * resource_necessity_mines_ / 255 + | 1647 | buildable_field->unowned_mines_pots_nearby_ * resource_necessity_mines_ / 255 + |
449 | 1656 | bf->stones_nearby_ / 2 + bf->military_loneliness_ / 10 - 60 + local_boost + | 1648 | buildable_field->stones_nearby_ / 2 + buildable_field->military_loneliness_ / 10 - 60 + local_boost + |
450 | 1657 | bf->water_nearby_ * resource_necessity_water_ / 255); | 1649 | buildable_field->water_nearby_ * resource_necessity_water_ / 255); |
451 | 1658 | 1650 | ||
452 | 1659 | // special bonus due to remote water for atlanteans | 1651 | // special bonus due to remote water for atlanteans |
453 | 1660 | if (resource_necessity_water_needed_) | 1652 | if (resource_necessity_water_needed_) |
455 | 1661 | prio += bf->distant_water_ * resource_necessity_water_ / 255; | 1653 | prio += buildable_field->distant_water_ * resource_necessity_water_ / 255; |
456 | 1662 | 1654 | ||
457 | 1663 | if (bo.desc->get_size() < maxsize) { | 1655 | if (bo.desc->get_size() < maxsize) { |
458 | 1664 | prio = prio - 5; | 1656 | prio = prio - 5; |
459 | @@ -1671,22 +1663,22 @@ | |||
460 | 1671 | // for expansion) | 1663 | // for expansion) |
461 | 1672 | const int16_t bottom_treshold = | 1664 | const int16_t bottom_treshold = |
462 | 1673 | 15 - ((virtual_mines <= 4) ? (5 - virtual_mines) * 2 : 0); | 1665 | 15 - ((virtual_mines <= 4) ? (5 - virtual_mines) * 2 : 0); |
465 | 1674 | if (bf->enemy_nearby_ && bf->military_capacity_ < bottom_treshold) { | 1666 | if (buildable_field->enemy_nearby_ && buildable_field->military_capacity_ < bottom_treshold) { |
466 | 1675 | prio += 50 + (bottom_treshold - bf->military_capacity_) * 20; | 1667 | prio += 50 + (bottom_treshold - buildable_field->military_capacity_) * 20; |
467 | 1676 | } | 1668 | } |
468 | 1677 | 1669 | ||
471 | 1678 | if (bf->enemy_nearby_ && bf->military_capacity_ > bottom_treshold + 4) { | 1670 | if (buildable_field->enemy_nearby_ && buildable_field->military_capacity_ > bottom_treshold + 4) { |
472 | 1679 | prio -= (bf->military_capacity_ - (bottom_treshold + 4)) * 5; | 1671 | prio -= (buildable_field->military_capacity_ - (bottom_treshold + 4)) * 5; |
473 | 1680 | } | 1672 | } |
474 | 1681 | 1673 | ||
475 | 1682 | } else if (bo.type == BuildingObserver::WAREHOUSE) { | 1674 | } else if (bo.type == BuildingObserver::WAREHOUSE) { |
476 | 1683 | 1675 | ||
477 | 1684 | // exclude spots on border | 1676 | // exclude spots on border |
479 | 1685 | if (bf->near_border_ && !bo.is_port_) { | 1677 | if (buildable_field->near_border_ && !bo.is_port_) { |
480 | 1686 | continue; | 1678 | continue; |
481 | 1687 | } | 1679 | } |
482 | 1688 | 1680 | ||
484 | 1689 | if (!bf->is_portspace_ && bo.is_port_) { | 1681 | if (!buildable_field->is_portspace_ && bo.is_port_) { |
485 | 1690 | continue; | 1682 | continue; |
486 | 1691 | } | 1683 | } |
487 | 1692 | 1684 | ||
488 | @@ -1714,7 +1706,7 @@ | |||
489 | 1714 | 1706 | ||
490 | 1715 | // special boost for first port | 1707 | // special boost for first port |
491 | 1716 | if (bo.is_port_ && bo.total_count() == 0 && productionsites.size() > 5 && | 1708 | if (bo.is_port_ && bo.total_count() == 0 && productionsites.size() > 5 && |
493 | 1717 | !bf->enemy_nearby_ && bf->is_portspace_ && seafaring_economy) { | 1709 | !buildable_field->enemy_nearby_ && buildable_field->is_portspace_ && seafaring_economy) { |
494 | 1718 | prio += kDefaultPrioBoost + productionsites.size(); | 1710 | prio += kDefaultPrioBoost + productionsites.size(); |
495 | 1719 | warehouse_needed = true; | 1711 | warehouse_needed = true; |
496 | 1720 | } | 1712 | } |
497 | @@ -1728,7 +1720,7 @@ | |||
498 | 1728 | uint16_t nearest_distance = std::numeric_limits<uint16_t>::max(); | 1720 | uint16_t nearest_distance = std::numeric_limits<uint16_t>::max(); |
499 | 1729 | for (const WarehouseSiteObserver& wh_obs : warehousesites) { | 1721 | for (const WarehouseSiteObserver& wh_obs : warehousesites) { |
500 | 1730 | const uint16_t actual_distance = | 1722 | const uint16_t actual_distance = |
502 | 1731 | map.calc_distance(bf->coords, wh_obs.site->get_position()); | 1723 | map.calc_distance(buildable_field->coords, wh_obs.site->get_position()); |
503 | 1732 | nearest_distance = std::min(nearest_distance, actual_distance); | 1724 | nearest_distance = std::min(nearest_distance, actual_distance); |
504 | 1733 | } | 1725 | } |
505 | 1734 | //but limit to 15 | 1726 | //but limit to 15 |
506 | @@ -1737,11 +1729,11 @@ | |||
507 | 1737 | prio += nearest_distance; | 1729 | prio += nearest_distance; |
508 | 1738 | 1730 | ||
509 | 1739 | // take care about and enemies | 1731 | // take care about and enemies |
511 | 1740 | if (bf->enemy_nearby_) { | 1732 | if (buildable_field->enemy_nearby_) { |
512 | 1741 | prio /= 2; | 1733 | prio /= 2; |
513 | 1742 | } | 1734 | } |
514 | 1743 | 1735 | ||
516 | 1744 | if (bf->unowned_land_nearby_ && !bo.is_port_) { | 1736 | if (buildable_field->unowned_land_nearby_ && !bo.is_port_) { |
517 | 1745 | prio /= 2; | 1737 | prio /= 2; |
518 | 1746 | } | 1738 | } |
519 | 1747 | 1739 | ||
520 | @@ -1752,7 +1744,7 @@ | |||
521 | 1752 | } | 1744 | } |
522 | 1753 | 1745 | ||
523 | 1754 | // exclude spots on border | 1746 | // exclude spots on border |
525 | 1755 | if (bf->near_border_) { | 1747 | if (buildable_field->near_border_) { |
526 | 1756 | continue; | 1748 | continue; |
527 | 1757 | } | 1749 | } |
528 | 1758 | 1750 | ||
529 | @@ -1767,17 +1759,17 @@ | |||
530 | 1767 | } | 1759 | } |
531 | 1768 | 1760 | ||
532 | 1769 | // take care about borders and enemies | 1761 | // take care about borders and enemies |
534 | 1770 | if (bf->enemy_nearby_) { | 1762 | if (buildable_field->enemy_nearby_) { |
535 | 1771 | prio /= 2; | 1763 | prio /= 2; |
536 | 1772 | } | 1764 | } |
537 | 1773 | 1765 | ||
539 | 1774 | if (bf->unowned_land_nearby_) { | 1766 | if (buildable_field->unowned_land_nearby_) { |
540 | 1775 | prio /= 2; | 1767 | prio /= 2; |
541 | 1776 | } | 1768 | } |
542 | 1777 | } | 1769 | } |
543 | 1778 | 1770 | ||
544 | 1779 | // think of space consuming buildings nearby like farms or vineyards | 1771 | // think of space consuming buildings nearby like farms or vineyards |
546 | 1780 | prio -= bf->space_consumers_nearby_ * 10; | 1772 | prio -= buildable_field->space_consumers_nearby_ * 10; |
547 | 1781 | 1773 | ||
548 | 1782 | // Stop here, if priority is 0 or less. | 1774 | // Stop here, if priority is 0 or less. |
549 | 1783 | if (prio <= 0) { | 1775 | if (prio <= 0) { |
550 | @@ -1786,25 +1778,25 @@ | |||
551 | 1786 | 1778 | ||
552 | 1787 | // testing also vicinity | 1779 | // testing also vicinity |
553 | 1788 | if (!bo.is_port_) { | 1780 | if (!bo.is_port_) { |
555 | 1789 | if (port_reserved_coords.count(coords_hash(bf->coords)) > 0) { | 1781 | if (port_reserved_coords.count(coords_hash(buildable_field->coords)) > 0) { |
556 | 1790 | continue; | 1782 | continue; |
557 | 1791 | } | 1783 | } |
558 | 1792 | } | 1784 | } |
559 | 1793 | 1785 | ||
560 | 1794 | // Prefer road side fields | 1786 | // Prefer road side fields |
562 | 1795 | prio += bf->preferred_ ? 1 : 0; | 1787 | prio += buildable_field->preferred_ ? 1 : 0; |
563 | 1796 | // don't waste good land for small huts | 1788 | // don't waste good land for small huts |
564 | 1797 | prio -= (maxsize - bo.desc->get_size()) * 5; | 1789 | prio -= (maxsize - bo.desc->get_size()) * 5; |
565 | 1798 | 1790 | ||
566 | 1799 | // prefer vicinity of ports (with exemption of warehouses) | 1791 | // prefer vicinity of ports (with exemption of warehouses) |
568 | 1800 | if (bf->port_nearby_ && bo.type == BuildingObserver::MILITARYSITE) { | 1792 | if (buildable_field->port_nearby_ && bo.type == BuildingObserver::MILITARYSITE) { |
569 | 1801 | prio *= 2; | 1793 | prio *= 2; |
570 | 1802 | } | 1794 | } |
571 | 1803 | 1795 | ||
572 | 1804 | if (prio > proposed_priority) { | 1796 | if (prio > proposed_priority) { |
573 | 1805 | best_building = &bo; | 1797 | best_building = &bo; |
574 | 1806 | proposed_priority = prio; | 1798 | proposed_priority = prio; |
576 | 1807 | proposed_coords = bf->coords; | 1799 | proposed_coords = buildable_field->coords; |
577 | 1808 | } | 1800 | } |
578 | 1809 | } // ending loop over buildings | 1801 | } // ending loop over buildings |
579 | 1810 | } // ending loop over fields | 1802 | } // ending loop over fields |
580 | @@ -1862,18 +1854,16 @@ | |||
581 | 1862 | } | 1854 | } |
582 | 1863 | 1855 | ||
583 | 1864 | // iterating over fields | 1856 | // iterating over fields |
587 | 1865 | for (std::list<MineableField*>::iterator j = mineable_fields.begin(); | 1857 | for (const MineableField* mineable_field : mineable_fields) { |
585 | 1866 | j != mineable_fields.end(); | ||
586 | 1867 | ++j) { | ||
588 | 1868 | 1858 | ||
590 | 1869 | if ((*j)->coords.field->get_resources() != bo.mines_) { | 1859 | if (mineable_field->coords.field->get_resources() != bo.mines_) { |
591 | 1870 | continue; | 1860 | continue; |
592 | 1871 | } | 1861 | } |
593 | 1872 | 1862 | ||
595 | 1873 | int32_t prio = (*j)->coords.field->get_resources_amount(); | 1863 | int32_t prio = mineable_field->coords.field->get_resources_amount(); |
596 | 1874 | 1864 | ||
597 | 1875 | // applying nearnes penalty | 1865 | // applying nearnes penalty |
599 | 1876 | prio = prio - (*j)->mines_nearby_ * nearness_penalty; | 1866 | prio = prio - mineable_field->mines_nearby_ * nearness_penalty; |
600 | 1877 | 1867 | ||
601 | 1878 | // Only build mines_ on locations where some material can be mined | 1868 | // Only build mines_ on locations where some material can be mined |
602 | 1879 | if (prio < 2) { | 1869 | if (prio < 2) { |
603 | @@ -1883,10 +1873,8 @@ | |||
604 | 1883 | // Continue if field is blocked at the moment | 1873 | // Continue if field is blocked at the moment |
605 | 1884 | bool blocked = false; | 1874 | bool blocked = false; |
606 | 1885 | 1875 | ||
611 | 1886 | for (std::list<BlockedField>::iterator k = blocked_fields.begin(); | 1876 | for (const BlockedField& blocked_field :blocked_fields) |
612 | 1887 | k != blocked_fields.end(); | 1877 | if (mineable_field->coords == blocked_field.coords) { |
609 | 1888 | ++k) | ||
610 | 1889 | if ((*j)->coords == k->coords) { | ||
613 | 1890 | blocked = true; | 1878 | blocked = true; |
614 | 1891 | break; | 1879 | break; |
615 | 1892 | } | 1880 | } |
616 | @@ -1897,13 +1885,13 @@ | |||
617 | 1897 | } | 1885 | } |
618 | 1898 | 1886 | ||
619 | 1899 | // Prefer road side fields | 1887 | // Prefer road side fields |
621 | 1900 | prio += (*j)->preferred_ ? 1 : 0; | 1888 | prio += mineable_field->preferred_ ? 1 : 0; |
622 | 1901 | 1889 | ||
623 | 1902 | if (prio > proposed_priority) { | 1890 | if (prio > proposed_priority) { |
624 | 1903 | // proposed_building = bo.id; | 1891 | // proposed_building = bo.id; |
625 | 1904 | best_building = &bo; | 1892 | best_building = &bo; |
626 | 1905 | proposed_priority = prio; | 1893 | proposed_priority = prio; |
628 | 1906 | proposed_coords = (*j)->coords; | 1894 | proposed_coords = mineable_field->coords; |
629 | 1907 | mine = true; | 1895 | mine = true; |
630 | 1908 | } | 1896 | } |
631 | 1909 | } // end of evaluation of field | 1897 | } // end of evaluation of field |
632 | @@ -2098,10 +2086,10 @@ | |||
633 | 2098 | continue; | 2086 | continue; |
634 | 2099 | } | 2087 | } |
635 | 2100 | 2088 | ||
637 | 2101 | std::vector<NearFlag>::iterator f = | 2089 | std::vector<NearFlag>::iterator near_flag_it = |
638 | 2102 | find(reachableflags.begin(), reachableflags.end(), queue.top().flag); | 2090 | find(reachableflags.begin(), reachableflags.end(), queue.top().flag); |
639 | 2103 | 2091 | ||
641 | 2104 | if (f != reachableflags.end()) { | 2092 | if (near_flag_it != reachableflags.end()) { |
642 | 2105 | queue.pop(); | 2093 | queue.pop(); |
643 | 2106 | continue; | 2094 | continue; |
644 | 2107 | } | 2095 | } |
645 | @@ -2280,10 +2268,10 @@ | |||
646 | 2280 | 2268 | ||
647 | 2281 | // algorithm to walk on roads | 2269 | // algorithm to walk on roads |
648 | 2282 | while (!queue.empty()) { | 2270 | while (!queue.empty()) { |
650 | 2283 | std::vector<NearFlag>::iterator f = | 2271 | std::vector<NearFlag>::iterator near_flag_it = |
651 | 2284 | find(nearflags_tmp.begin(), nearflags_tmp.end(), queue.top().flag); | 2272 | find(nearflags_tmp.begin(), nearflags_tmp.end(), queue.top().flag); |
652 | 2285 | 2273 | ||
654 | 2286 | if (f != nearflags_tmp.end()) { | 2274 | if (near_flag_it != nearflags_tmp.end()) { |
655 | 2287 | queue.pop(); | 2275 | queue.pop(); |
656 | 2288 | continue; | 2276 | continue; |
657 | 2289 | } | 2277 | } |
658 | @@ -2318,19 +2306,16 @@ | |||
659 | 2318 | // iterating over nearflags_tmp, each item in nearflags_tmp should be contained also in nearflags | 2306 | // iterating over nearflags_tmp, each item in nearflags_tmp should be contained also in nearflags |
660 | 2319 | // so for each corresponding field in nearflags we update "cost" (distance on existing roads) | 2307 | // so for each corresponding field in nearflags we update "cost" (distance on existing roads) |
661 | 2320 | // to actual value | 2308 | // to actual value |
666 | 2321 | for (std::vector<NearFlag>::iterator nf_walk_it = nearflags_tmp.begin(); | 2309 | for (const NearFlag& temp_near_flag : nearflags_tmp) { |
667 | 2322 | nf_walk_it != nearflags_tmp.end(); | 2310 | uint32_t const hash_walk = coords_hash(temp_near_flag.flag->get_position()); |
664 | 2323 | ++nf_walk_it) { | ||
665 | 2324 | uint32_t const hash_walk = coords_hash(nf_walk_it->flag->get_position()); | ||
668 | 2325 | if (lookuptable.count(hash_walk) > 0) { | 2311 | if (lookuptable.count(hash_walk) > 0) { |
669 | 2326 | // iterating over nearflags | 2312 | // iterating over nearflags |
673 | 2327 | for (std::vector<NearFlag>::iterator nf_it = nearflags.begin(); nf_it != nearflags.end(); | 2313 | for (NearFlag& near_flag : nearflags) { |
674 | 2328 | ++nf_it) { | 2314 | uint32_t const hash = coords_hash(near_flag.flag->get_position()); |
672 | 2329 | uint32_t const hash = coords_hash(nf_it->flag->get_position()); | ||
675 | 2330 | if (hash == hash_walk) { | 2315 | if (hash == hash_walk) { |
676 | 2331 | // decreasing "cost" (of walking via roads) | 2316 | // decreasing "cost" (of walking via roads) |
679 | 2332 | if (nf_it->cost_ > nf_walk_it->cost_) { | 2317 | if (near_flag.cost_ > temp_near_flag.cost_) { |
680 | 2333 | nf_it->cost_ = nf_walk_it->cost_; | 2318 | near_flag.cost_ = temp_near_flag.cost_; |
681 | 2334 | } | 2319 | } |
682 | 2335 | } | 2320 | } |
683 | 2336 | } | 2321 | } |
684 | @@ -2403,26 +2388,21 @@ | |||
685 | 2403 | get_economy_observer(flag.economy())->flags.push_back(&flag); | 2388 | get_economy_observer(flag.economy())->flags.push_back(&flag); |
686 | 2404 | } | 2389 | } |
687 | 2405 | 2390 | ||
691 | 2406 | for (std::list<EconomyObserver*>::iterator obs_iter = economies.begin(); | 2391 | for (EconomyObserver* economy_observer : economies) { |
689 | 2407 | obs_iter != economies.end(); | ||
690 | 2408 | ++obs_iter) { | ||
692 | 2409 | // check if any flag has changed its economy | 2392 | // check if any flag has changed its economy |
694 | 2410 | std::list<Flag const*>& fl = (*obs_iter)->flags; | 2393 | std::list<Flag const*>& fl = economy_observer->flags; |
695 | 2411 | 2394 | ||
702 | 2412 | for (std::list<Flag const*>::iterator j = fl.begin(); j != fl.end();) { | 2395 | for (const Flag* flag : fl) { |
703 | 2413 | if (&(*obs_iter)->economy != &(*j)->economy()) { | 2396 | if (&economy_observer->economy != &flag->economy()) { |
704 | 2414 | get_economy_observer((*j)->economy())->flags.push_back(*j); | 2397 | get_economy_observer(flag->economy())->flags.push_back(flag); |
705 | 2415 | j = fl.erase(j); | 2398 | fl.remove(flag); |
700 | 2416 | } else { | ||
701 | 2417 | ++j; | ||
706 | 2418 | } | 2399 | } |
707 | 2419 | } | 2400 | } |
708 | 2420 | 2401 | ||
709 | 2421 | // if there are no more flags in this economy, | 2402 | // if there are no more flags in this economy, |
710 | 2422 | // we no longer need it's observer | 2403 | // we no longer need it's observer |
714 | 2423 | if ((*obs_iter)->flags.empty()) { | 2404 | if (economy_observer->flags.empty()) { |
715 | 2424 | delete *obs_iter; | 2405 | economies.remove(economy_observer); |
713 | 2425 | economies.erase(obs_iter); | ||
716 | 2426 | return true; | 2406 | return true; |
717 | 2427 | } | 2407 | } |
718 | 2428 | } | 2408 | } |
719 | @@ -2800,20 +2780,19 @@ | |||
720 | 2800 | } | 2780 | } |
721 | 2801 | 2781 | ||
722 | 2802 | // and now over ships | 2782 | // and now over ships |
726 | 2803 | for (std::list<ShipObserver>::iterator sp_iter = allships.begin(); sp_iter != allships.end(); | 2783 | for (const ShipObserver& ship_observer : allships) { |
727 | 2804 | ++sp_iter) { | 2784 | if (ship_observer.ship->state_is_expedition()) { |
725 | 2805 | if (sp_iter->ship->state_is_expedition()) { | ||
728 | 2806 | expeditions_in_progress += 1; | 2785 | expeditions_in_progress += 1; |
729 | 2807 | } | 2786 | } |
730 | 2808 | } | 2787 | } |
731 | 2809 | 2788 | ||
732 | 2810 | // we must verify that all remote ports are still ours (and exists at all) | 2789 | // we must verify that all remote ports are still ours (and exists at all) |
733 | 2811 | bool still_ours; | 2790 | bool still_ours; |
737 | 2812 | for (std::unordered_set<uint32_t>::iterator ports_iter = remote_ports_coords.begin(); | 2791 | for (std::unordered_set<uint32_t>::iterator ports_it = remote_ports_coords.begin(); |
738 | 2813 | ports_iter != remote_ports_coords.end(); | 2792 | ports_it != remote_ports_coords.end(); |
739 | 2814 | ++ports_iter) { | 2793 | ++ports_it) { |
740 | 2815 | still_ours = false; | 2794 | still_ours = false; |
742 | 2816 | FCoords fcoords = game().map().get_fcoords(coords_unhash(*ports_iter)); | 2795 | FCoords fcoords = game().map().get_fcoords(coords_unhash(*ports_it)); |
743 | 2817 | if (fcoords.field->get_owned_by() == player_number()) { | 2796 | if (fcoords.field->get_owned_by() == player_number()) { |
744 | 2818 | if (upcast(PlayerImmovable, imm, fcoords.field->get_immovable())) { | 2797 | if (upcast(PlayerImmovable, imm, fcoords.field->get_immovable())) { |
745 | 2819 | still_ours = true; | 2798 | still_ours = true; |
746 | @@ -2821,7 +2800,7 @@ | |||
747 | 2821 | } | 2800 | } |
748 | 2822 | 2801 | ||
749 | 2823 | if (!still_ours) { | 2802 | if (!still_ours) { |
751 | 2824 | remote_ports_coords.erase(*ports_iter); | 2803 | remote_ports_coords.erase(*ports_it); |
752 | 2825 | break; | 2804 | break; |
753 | 2826 | } | 2805 | } |
754 | 2827 | } | 2806 | } |
755 | @@ -2892,26 +2871,25 @@ | |||
756 | 2892 | } | 2871 | } |
757 | 2893 | 2872 | ||
758 | 2894 | if (!allships.empty()) { | 2873 | if (!allships.empty()) { |
768 | 2895 | // iterating over ships and executing what is needed | 2874 | // Iterating over ships and executing what is needed. |
769 | 2896 | for (std::list<ShipObserver>::iterator i = allships.begin(); i != allships.end(); ++i) { | 2875 | for (ShipObserver& ship_observer : allships) { |
770 | 2897 | 2876 | // Only two states need attention. | |
771 | 2898 | // only two states need an attention | 2877 | if ((ship_observer.ship->get_ship_state() == Widelands::Ship::EXP_WAITING || |
772 | 2899 | if ((i->ship->get_ship_state() == Widelands::Ship::EXP_WAITING || | 2878 | ship_observer.ship->get_ship_state() == Widelands::Ship::EXP_FOUNDPORTSPACE) && |
773 | 2900 | i->ship->get_ship_state() == Widelands::Ship::EXP_FOUNDPORTSPACE) && | 2879 | !ship_observer.waiting_for_command_) { |
774 | 2901 | !i->waiting_for_command_) { | 2880 | if (gametime - ship_observer.last_command_time > 180 * 1000) { |
775 | 2902 | if (gametime - i->last_command_time > 180 * 1000) { | 2881 | ship_observer.waiting_for_command_ = true; |
767 | 2903 | i->waiting_for_command_ = true; | ||
776 | 2904 | log(" %1d: last command for ship at %3dx%3d was %3d seconds ago, something wrong " | 2882 | log(" %1d: last command for ship at %3dx%3d was %3d seconds ago, something wrong " |
777 | 2905 | "here?...\n", | 2883 | "here?...\n", |
778 | 2906 | player_number(), | 2884 | player_number(), |
782 | 2907 | i->ship->get_position().x, | 2885 | ship_observer.ship->get_position().x, |
783 | 2908 | i->ship->get_position().y, | 2886 | ship_observer.ship->get_position().y, |
784 | 2909 | (gametime - i->last_command_time) / 1000); | 2887 | (gametime - ship_observer.last_command_time) / 1000); |
785 | 2910 | } | 2888 | } |
786 | 2911 | } | 2889 | } |
790 | 2912 | // if ships is waiting for command | 2890 | // If ship is waiting for command. |
791 | 2913 | if (i->waiting_for_command_) { | 2891 | if (ship_observer.waiting_for_command_) { |
792 | 2914 | expedition_management(*i); | 2892 | expedition_management(ship_observer); |
793 | 2915 | } | 2893 | } |
794 | 2916 | } | 2894 | } |
795 | 2917 | } | 2895 | } |
796 | @@ -2920,33 +2898,27 @@ | |||
797 | 2920 | while (!marineTaskQueue_.empty()) { | 2898 | while (!marineTaskQueue_.empty()) { |
798 | 2921 | if (marineTaskQueue_.back() == kStopShipyard) { | 2899 | if (marineTaskQueue_.back() == kStopShipyard) { |
799 | 2922 | // iterate over all production sites searching for shipyard | 2900 | // iterate over all production sites searching for shipyard |
806 | 2923 | for (std::list<ProductionSiteObserver>::iterator site = productionsites.begin(); | 2901 | for (const ProductionSiteObserver& prod_site_observer : productionsites) { |
807 | 2924 | site != productionsites.end(); | 2902 | if (prod_site_observer.bo->is_shipyard_) { |
808 | 2925 | ++site) { | 2903 | if (!prod_site_observer.site->is_stopped()) { |
809 | 2926 | if (site->bo->is_shipyard_) { | 2904 | game().send_player_start_stop_building(*prod_site_observer.site); |
804 | 2927 | if (!site->site->is_stopped()) { | ||
805 | 2928 | game().send_player_start_stop_building(*site->site); | ||
810 | 2929 | } | 2905 | } |
811 | 2930 | } | 2906 | } |
812 | 2931 | } | 2907 | } |
813 | 2932 | } | 2908 | } |
814 | 2933 | 2909 | ||
815 | 2934 | if (marineTaskQueue_.back() == kReprioritize) { | 2910 | if (marineTaskQueue_.back() == kReprioritize) { |
821 | 2935 | for (std::list<ProductionSiteObserver>::iterator site = productionsites.begin(); | 2911 | for (const ProductionSiteObserver& prod_site_observer : productionsites) { |
822 | 2936 | site != productionsites.end(); | 2912 | if (prod_site_observer.bo->is_shipyard_) { |
823 | 2937 | ++site) { | 2913 | for (uint32_t k = 0; k < prod_site_observer.bo->inputs_.size(); ++k) { |
819 | 2938 | if (site->bo->is_shipyard_) { | ||
820 | 2939 | for (uint32_t k = 0; k < site->bo->inputs_.size(); ++k) { | ||
824 | 2940 | game().send_player_set_ware_priority( | 2914 | game().send_player_set_ware_priority( |
826 | 2941 | *site->site, wwWARE, site->bo->inputs_.at(k), HIGH_PRIORITY); | 2915 | *prod_site_observer.site, wwWARE, prod_site_observer.bo->inputs_.at(k), HIGH_PRIORITY); |
827 | 2942 | } | 2916 | } |
828 | 2943 | } | 2917 | } |
829 | 2944 | } | 2918 | } |
830 | 2945 | } | 2919 | } |
831 | 2946 | |||
832 | 2947 | marineTaskQueue_.pop_back(); | 2920 | marineTaskQueue_.pop_back(); |
833 | 2948 | } | 2921 | } |
834 | 2949 | |||
835 | 2950 | return true; | 2922 | return true; |
836 | 2951 | } | 2923 | } |
837 | 2952 | 2924 | ||
838 | @@ -3127,13 +3099,9 @@ | |||
839 | 3127 | // perhaps it will be able to replace get_stocklevel | 3099 | // perhaps it will be able to replace get_stocklevel |
840 | 3128 | uint32_t DefaultAI::get_warehoused_stock(WareIndex wt) { | 3100 | uint32_t DefaultAI::get_warehoused_stock(WareIndex wt) { |
841 | 3129 | uint32_t count = 0; | 3101 | uint32_t count = 0; |
847 | 3130 | 3102 | for (const WarehouseSiteObserver& warehouse_observer : warehousesites) { | |
848 | 3131 | for (std::list<WarehouseSiteObserver>::iterator i = warehousesites.begin(); | 3103 | count += warehouse_observer.site->get_wares().stock(wt); |
844 | 3132 | i != warehousesites.end(); | ||
845 | 3133 | ++i) { | ||
846 | 3134 | count += i->site->get_wares().stock(wt); | ||
849 | 3135 | } | 3104 | } |
850 | 3136 | |||
851 | 3137 | return count; | 3105 | return count; |
852 | 3138 | } | 3106 | } |
853 | 3139 | 3107 | ||
854 | @@ -3155,13 +3123,10 @@ | |||
855 | 3155 | } else { | 3123 | } else { |
856 | 3156 | new_priority = DEFAULT_PRIORITY; | 3124 | new_priority = DEFAULT_PRIORITY; |
857 | 3157 | } | 3125 | } |
863 | 3158 | for (std::list<TrainingSiteObserver>::iterator site = trainingsites.begin(); | 3126 | for (const TrainingSiteObserver& trainingsite_observer :trainingsites) { |
864 | 3159 | site != trainingsites.end(); | 3127 | for (uint32_t k = 0; k < trainingsite_observer.bo->inputs_.size(); ++k) { |
860 | 3160 | ++site) { | ||
861 | 3161 | |||
862 | 3162 | for (uint32_t k = 0; k < site->bo->inputs_.size(); ++k) { | ||
865 | 3163 | game().send_player_set_ware_priority( | 3128 | game().send_player_set_ware_priority( |
867 | 3164 | *site->site, wwWARE, site->bo->inputs_.at(k), new_priority); | 3129 | *trainingsite_observer.site, wwWARE, trainingsite_observer.bo->inputs_.at(k), new_priority); |
868 | 3165 | } | 3130 | } |
869 | 3166 | } | 3131 | } |
870 | 3167 | return true; | 3132 | return true; |
871 | @@ -3186,10 +3151,8 @@ | |||
872 | 3186 | // construction | 3151 | // construction |
873 | 3187 | unstationed_milit_buildings_ = 0; | 3152 | unstationed_milit_buildings_ = 0; |
874 | 3188 | 3153 | ||
879 | 3189 | for (std::list<MilitarySiteObserver>::iterator it = militarysites.begin(); | 3154 | for (const MilitarySiteObserver& militarysite_observer : militarysites) { |
880 | 3190 | it != militarysites.end(); | 3155 | if (militarysite_observer.site->stationed_soldiers().size() == 0) { |
877 | 3191 | ++it) { | ||
878 | 3192 | if (it->site->stationed_soldiers().size() == 0) { | ||
881 | 3193 | unstationed_milit_buildings_ += 1; | 3156 | unstationed_milit_buildings_ += 1; |
882 | 3194 | } | 3157 | } |
883 | 3195 | } | 3158 | } |
884 | @@ -3387,9 +3350,11 @@ | |||
885 | 3387 | 3350 | ||
886 | 3388 | /// \returns the economy observer containing \arg economy | 3351 | /// \returns the economy observer containing \arg economy |
887 | 3389 | EconomyObserver* DefaultAI::get_economy_observer(Economy& economy) { | 3352 | EconomyObserver* DefaultAI::get_economy_observer(Economy& economy) { |
891 | 3390 | for (std::list<EconomyObserver*>::iterator i = economies.begin(); i != economies.end(); ++i) | 3353 | for (EconomyObserver* economy_observer : economies) { |
892 | 3391 | if (&(*i)->economy == &economy) | 3354 | if (&economy_observer->economy == &economy) { |
893 | 3392 | return *i; | 3355 | return economy_observer; |
894 | 3356 | } | ||
895 | 3357 | } | ||
896 | 3393 | 3358 | ||
897 | 3394 | economies.push_front(new EconomyObserver(economy)); | 3359 | economies.push_front(new EconomyObserver(economy)); |
898 | 3395 | return economies.front(); | 3360 | return economies.front(); |
899 | @@ -3427,20 +3392,16 @@ | |||
900 | 3427 | lose_building(*building); | 3392 | lose_building(*building); |
901 | 3428 | } else if (upcast(Flag const, flag, &pi)) { | 3393 | } else if (upcast(Flag const, flag, &pi)) { |
902 | 3429 | for (EconomyObserver* eco_obs : economies) { | 3394 | for (EconomyObserver* eco_obs : economies) { |
908 | 3430 | for (std::list<Flag const*>::iterator flag_iter = eco_obs->flags.begin(); | 3395 | for (const Flag* economy_flag : eco_obs->flags) { |
909 | 3431 | flag_iter != eco_obs->flags.end(); | 3396 | if (economy_flag == flag) { |
910 | 3432 | ++flag_iter) { | 3397 | eco_obs->flags.remove(economy_flag); |
906 | 3433 | if (*flag_iter == flag) { | ||
907 | 3434 | eco_obs->flags.erase(flag_iter); | ||
911 | 3435 | return; | 3398 | return; |
912 | 3436 | } | 3399 | } |
913 | 3437 | } | 3400 | } |
914 | 3438 | } | 3401 | } |
920 | 3439 | for (std::list<Flag const*>::iterator flag_iter = new_flags.begin(); | 3402 | for (const Flag* new_flag : new_flags) { |
921 | 3440 | flag_iter != new_flags.end(); | 3403 | if (new_flag == flag) { |
922 | 3441 | ++flag_iter) { | 3404 | new_flags.remove(new_flag); |
918 | 3442 | if (*flag_iter == flag) { | ||
919 | 3443 | new_flags.erase(flag_iter); | ||
923 | 3444 | return; | 3405 | return; |
924 | 3445 | } | 3406 | } |
925 | 3446 | } | 3407 | } |
926 | @@ -3453,9 +3414,9 @@ | |||
927 | 3453 | void DefaultAI::out_of_resources_site(const ProductionSite& site) { | 3414 | void DefaultAI::out_of_resources_site(const ProductionSite& site) { |
928 | 3454 | 3415 | ||
929 | 3455 | // we must identify which mine matches the productionsite a note reffers to | 3416 | // we must identify which mine matches the productionsite a note reffers to |
933 | 3456 | for (std::list<ProductionSiteObserver>::iterator i = mines_.begin(); i != mines_.end(); ++i) | 3417 | for (ProductionSiteObserver& mine_observer : mines_) |
934 | 3457 | if (i->site == &site) { | 3418 | if (mine_observer.site == &site) { |
935 | 3458 | i->no_resources_count += 1; | 3419 | mine_observer.no_resources_count += 1; |
936 | 3459 | break; | 3420 | break; |
937 | 3460 | } | 3421 | } |
938 | 3461 | } | 3422 | } |
939 | @@ -3752,11 +3713,11 @@ | |||
940 | 3752 | 3713 | ||
941 | 3753 | if (bo.type == BuildingObserver::PRODUCTIONSITE) { | 3714 | if (bo.type == BuildingObserver::PRODUCTIONSITE) { |
942 | 3754 | 3715 | ||
948 | 3755 | for (std::list<ProductionSiteObserver>::iterator i = productionsites.begin(); | 3716 | for (std::list<ProductionSiteObserver>::iterator prod_site_observer_it = productionsites.begin(); |
949 | 3756 | i != productionsites.end(); | 3717 | prod_site_observer_it != productionsites.end(); |
950 | 3757 | ++i) | 3718 | ++prod_site_observer_it) |
951 | 3758 | if (i->site == &b) { | 3719 | if (prod_site_observer_it->site == &b) { |
952 | 3759 | productionsites.erase(i); | 3720 | productionsites.erase(prod_site_observer_it); |
953 | 3760 | break; | 3721 | break; |
954 | 3761 | } | 3722 | } |
955 | 3762 | 3723 | ||
956 | @@ -3768,10 +3729,10 @@ | |||
957 | 3768 | --wares.at(bo.inputs_.at(i)).consumers_; | 3729 | --wares.at(bo.inputs_.at(i)).consumers_; |
958 | 3769 | } | 3730 | } |
959 | 3770 | } else if (bo.type == BuildingObserver::MINE) { | 3731 | } else if (bo.type == BuildingObserver::MINE) { |
964 | 3771 | for (std::list<ProductionSiteObserver>::iterator i = mines_.begin(); i != mines_.end(); | 3732 | for (std::list<ProductionSiteObserver>::iterator mines_observer_it = mines_.begin(); mines_observer_it != mines_.end(); |
965 | 3772 | ++i) { | 3733 | ++mines_observer_it) { |
966 | 3773 | if (i->site == &b) { | 3734 | if (mines_observer_it->site == &b) { |
967 | 3774 | mines_.erase(i); | 3735 | mines_.erase(mines_observer_it); |
968 | 3775 | break; | 3736 | break; |
969 | 3776 | } | 3737 | } |
970 | 3777 | } | 3738 | } |
971 | @@ -3785,21 +3746,21 @@ | |||
972 | 3785 | } | 3746 | } |
973 | 3786 | } else if (bo.type == BuildingObserver::MILITARYSITE) { | 3747 | } else if (bo.type == BuildingObserver::MILITARYSITE) { |
974 | 3787 | 3748 | ||
980 | 3788 | for (std::list<MilitarySiteObserver>::iterator i = militarysites.begin(); | 3749 | for (std::list<MilitarySiteObserver>::iterator militarysite_observer_it = militarysites.begin(); |
981 | 3789 | i != militarysites.end(); | 3750 | militarysite_observer_it != militarysites.end(); |
982 | 3790 | ++i) { | 3751 | ++militarysite_observer_it) { |
983 | 3791 | if (i->site == &b) { | 3752 | if (militarysite_observer_it->site == &b) { |
984 | 3792 | militarysites.erase(i); | 3753 | militarysites.erase(militarysite_observer_it); |
985 | 3793 | break; | 3754 | break; |
986 | 3794 | } | 3755 | } |
987 | 3795 | } | 3756 | } |
988 | 3796 | } else if (bo.type == BuildingObserver::TRAININGSITE) { | 3757 | } else if (bo.type == BuildingObserver::TRAININGSITE) { |
989 | 3797 | 3758 | ||
995 | 3798 | for (std::list<TrainingSiteObserver>::iterator i = trainingsites.begin(); | 3759 | for (std::list<TrainingSiteObserver>::iterator trainingsite_observer_it = trainingsites.begin(); |
996 | 3799 | i != trainingsites.end(); | 3760 | trainingsite_observer_it != trainingsites.end(); |
997 | 3800 | ++i) { | 3761 | ++trainingsite_observer_it) { |
998 | 3801 | if (i->site == &b) { | 3762 | if (trainingsite_observer_it->site == &b) { |
999 | 3802 | trainingsites.erase(i); | 3763 | trainingsites.erase(trainingsite_observer_it); |
1000 | 3803 | break; | 3764 | break; |
1001 | 3804 | } | 3765 | } |
1002 | 3805 | } | 3766 | } |
1003 | @@ -3810,11 +3771,11 @@ | |||
1004 | 3810 | --num_ports; | 3771 | --num_ports; |
1005 | 3811 | } | 3772 | } |
1006 | 3812 | 3773 | ||
1012 | 3813 | for (std::list<WarehouseSiteObserver>::iterator i = warehousesites.begin(); | 3774 | for (std::list<WarehouseSiteObserver>::iterator warehouse_observer_it = warehousesites.begin(); |
1013 | 3814 | i != warehousesites.end(); | 3775 | warehouse_observer_it != warehousesites.end(); |
1014 | 3815 | ++i) { | 3776 | ++warehouse_observer_it) { |
1015 | 3816 | if (i->site == &b) { | 3777 | if (warehouse_observer_it->site == &b) { |
1016 | 3817 | warehousesites.erase(i); | 3778 | warehousesites.erase(warehouse_observer_it); |
1017 | 3818 | break; | 3779 | break; |
1018 | 3819 | } | 3780 | } |
1019 | 3820 | } | 3781 | } |
1020 | @@ -3982,12 +3943,12 @@ | |||
1021 | 3982 | for (uint32_t position = gametime % test_every; position < militarysites.size(); | 3943 | for (uint32_t position = gametime % test_every; position < militarysites.size(); |
1022 | 3983 | position += test_every) { | 3944 | position += test_every) { |
1023 | 3984 | 3945 | ||
1030 | 3985 | std::list<MilitarySiteObserver>::iterator mso = militarysites.begin(); | 3946 | std::list<MilitarySiteObserver>::iterator militarysite_observer_it = militarysites.begin(); |
1031 | 3986 | std::advance(mso, position); | 3947 | std::advance(militarysite_observer_it, position); |
1032 | 3987 | 3948 | ||
1033 | 3988 | MilitarySite* ms = mso->site; | 3949 | MilitarySite* ms = militarysite_observer_it->site; |
1034 | 3989 | 3950 | ||
1035 | 3990 | if (!mso->enemies_nearby_) { | 3951 | if (!militarysite_observer_it->enemies_nearby_) { |
1036 | 3991 | continue; | 3952 | continue; |
1037 | 3992 | } | 3953 | } |
1038 | 3993 | 3954 |
I think this is a definitive improvement to the readability. I did not carefully review this yet though, I think the seafaring branch should be merged first.