Merge lp:~widelands-dev/widelands/cleanup_map into lp:widelands
- cleanup_map
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 8432 |
Proposed branch: | lp:~widelands-dev/widelands/cleanup_map |
Merge into: | lp:widelands |
Diff against target: |
3125 lines (+394/-469) 69 files modified
src/ai/ai_help_structs.cc (+1/-1) src/ai/ai_help_structs.h (+1/-1) src/ai/defaultai.cc (+13/-17) src/ai/defaultai_seafaring.cc (+2/-2) src/ai/defaultai_warfare.cc (+2/-3) src/economy/economy.cc (+4/-9) src/economy/fleet.cc (+2/-5) src/economy/road.cc (+4/-4) src/economy/test/test_road.cc (+3/-14) src/editor/editorinteractive.cc (+20/-22) src/editor/ui_menus/main_menu_map_options.cc (+6/-6) src/editor/ui_menus/main_menu_new_map.cc (+3/-3) src/editor/ui_menus/main_menu_random_map.cc (+9/-10) src/editor/ui_menus/main_menu_save_map.cc (+12/-12) src/editor/ui_menus/player_menu.cc (+25/-25) src/editor/ui_menus/tool_change_resources_options_menu.cc (+4/-4) src/editor/ui_menus/tool_menu.cc (+3/-3) src/game_io/game_map_packet.cc (+1/-1) src/game_io/game_player_ai_persistent_packet.cc (+2/-4) src/graphic/game_renderer.cc (+1/-1) src/graphic/minimap_renderer.cc (+1/-1) src/logic/editor_game_base.cc (+6/-23) src/logic/editor_game_base.h (+4/-9) src/logic/game.cc (+7/-19) src/logic/map.cc (+9/-9) src/logic/map.h (+30/-30) src/logic/map_objects/bob.cc (+7/-8) src/logic/map_objects/checkstep.cc (+12/-12) src/logic/map_objects/checkstep.h (+16/-16) src/logic/map_objects/immovable.cc (+11/-9) src/logic/map_objects/tribes/building.cc (+4/-4) src/logic/map_objects/tribes/carrier.cc (+1/-1) src/logic/map_objects/tribes/militarysite.cc (+1/-1) src/logic/map_objects/tribes/production_program.cc (+9/-9) src/logic/map_objects/tribes/ship.cc (+15/-16) src/logic/map_objects/tribes/soldier.cc (+9/-9) src/logic/map_objects/tribes/warehouse.cc (+4/-5) src/logic/map_objects/tribes/worker.cc (+20/-21) src/logic/player.cc (+6/-6) src/logic/replay_game_controller.cc (+0/-3) src/map_io/map_bob_packet.cc (+4/-4) src/map_io/map_building_packet.cc (+1/-1) src/map_io/map_buildingdata_packet.cc (+4/-3) src/map_io/map_elemental_packet.cc (+1/-1) src/map_io/map_exploration_packet.cc (+2/-2) src/map_io/map_heights_packet.cc (+2/-2) src/map_io/map_node_ownership_packet.cc (+2/-2) src/map_io/map_objective_packet.cc (+1/-1) src/map_io/map_player_names_and_tribes_packet.cc (+1/-1) src/map_io/map_player_position_packet.cc (+4/-4) src/map_io/map_port_spaces_packet.cc (+4/-4) src/map_io/map_resources_packet.cc (+6/-6) src/map_io/map_roaddata_packet.cc (+1/-1) src/map_io/map_saver.cc (+3/-5) src/map_io/map_terrain_packet.cc (+1/-1) src/map_io/map_version_packet.cc (+11/-11) src/scripting/lua_bases.cc (+1/-1) src/scripting/lua_game.cc (+12/-15) src/scripting/lua_map.cc (+22/-21) src/website/map_info.cc (+1/-2) src/wui/attack_box.cc (+2/-3) src/wui/attack_box.h (+1/-1) src/wui/building_statistics_menu.cc (+1/-2) src/wui/fieldaction.cc (+5/-5) src/wui/game_debug_ui.cc (+1/-1) src/wui/game_main_menu_save_game.cc (+1/-1) src/wui/interactive_base.cc (+4/-4) src/wui/interactive_gamebase.cc (+2/-3) src/wui/watchwindow.cc (+3/-3) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/cleanup_map |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
SirVer | Approve | ||
GunChleoc | Approve | ||
Review via email: mp+329282@code.launchpad.net |
Commit message
Cleanups map handling in EditorGameBase
- remove set_map which was unused.
- remove redundant functions, only keep map() and get_map().
- mark more functions around path finding as const to make the API of the map clearer.
This is a simple, but huge refactoring since it needs to touch all code that deals with the map.
Description of the change
bunnybot (widelandsofficial) wrote : | # |
GunChleoc (gunchleoc) wrote : | # |
LGTM :)
There is still 1 NOCOM in the code.
I did some additional cleanup - feel free to merge if you agree with my changes.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 2586. State: passed. Details: https:/
Appveyor build 2408. State: success. Details: https:/
SirVer (sirver) wrote : | # |
> There is still 1 NOCOM in the code.
Ups. Fixed.
> I did some additional cleanup - feel free to merge if you agree with my changes.
Thanks! lgtm.
@bunnybot merge
Preview Diff
1 | === modified file 'src/ai/ai_help_structs.cc' |
2 | --- src/ai/ai_help_structs.cc 2017-08-19 23:24:28 +0000 |
3 | +++ src/ai/ai_help_structs.cc 2017-08-20 12:33:35 +0000 |
4 | @@ -41,7 +41,7 @@ |
5 | } |
6 | |
7 | bool CheckStepRoadAI::allowed( |
8 | - Map& map, FCoords start, FCoords end, int32_t, CheckStep::StepId const id) const { |
9 | + const Map& map, FCoords start, FCoords end, int32_t, CheckStep::StepId const id) const { |
10 | uint8_t endcaps = player->get_buildcaps(end); |
11 | |
12 | // we should not cross fields with road or flags (or any other immovable) |
13 | |
14 | === modified file 'src/ai/ai_help_structs.h' |
15 | --- src/ai/ai_help_structs.h 2017-08-19 19:33:37 +0000 |
16 | +++ src/ai/ai_help_structs.h 2017-08-20 12:33:35 +0000 |
17 | @@ -131,7 +131,7 @@ |
18 | struct CheckStepRoadAI { |
19 | CheckStepRoadAI(Player* const pl, uint8_t const mc, bool const oe); |
20 | |
21 | - bool allowed(Map&, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) const; |
22 | + bool allowed(const Map&, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) const; |
23 | bool reachable_dest(const Map&, const FCoords& dest) const; |
24 | |
25 | Player* player; |
26 | |
27 | === modified file 'src/ai/defaultai.cc' |
28 | --- src/ai/defaultai.cc 2017-08-19 19:33:37 +0000 |
29 | +++ src/ai/defaultai.cc 2017-08-20 12:33:35 +0000 |
30 | @@ -244,8 +244,6 @@ |
31 | |
32 | const int32_t delay_time = gametime - taskPool.front().due_time; |
33 | |
34 | - Map& map = game().map(); |
35 | - |
36 | // Here we decide how many jobs will be run now (none - 5) |
37 | // in case no job is due now, it can be zero |
38 | uint32_t jobs_to_run_count = (delay_time < 0) ? 0 : 1; |
39 | @@ -446,7 +444,7 @@ |
40 | { // statistics for spotted warehouses |
41 | uint16_t conquered_wh = 0; |
42 | for (auto coords : enemy_warehouses) { |
43 | - if (get_land_owner(map, coords) == player_number()) { |
44 | + if (get_land_owner(game().map(), coords) == player_number()) { |
45 | ++conquered_wh; |
46 | } |
47 | }; |
48 | @@ -690,7 +688,7 @@ |
49 | for (const DescriptionIndex& temp_output : prod.output_ware_types()) { |
50 | bo.outputs.push_back(temp_output); |
51 | } |
52 | - for (const auto temp_position : prod.working_positions()) { |
53 | + for (const auto& temp_position : prod.working_positions()) { |
54 | bo.positions.push_back(temp_position.first); |
55 | } |
56 | |
57 | @@ -925,7 +923,7 @@ |
58 | taskPool.push_back(SchedulerTask( |
59 | std::max<uint32_t>(gametime, 10 * 1000), SchedulerTaskId::kUpdateStats, 15, "review")); |
60 | |
61 | - Map& map = game().map(); |
62 | + const Map& map = game().map(); |
63 | |
64 | // here we generate list of all ports and their vicinity from entire map |
65 | for (const Coords& c : map.get_port_spaces()) { |
66 | @@ -1185,7 +1183,7 @@ |
67 | /// Updates one buildable field |
68 | void DefaultAI::update_buildable_field(BuildableField& field) { |
69 | // look if there is any unowned land nearby |
70 | - Map& map = game().map(); |
71 | + const Map& map = game().map(); |
72 | const uint32_t gametime = game().get_gametime(); |
73 | FindNodeUnownedWalkable find_unowned_walkable(player_, game()); |
74 | FindEnemyNodeWalkable find_enemy_owned_walkable(player_, game()); |
75 | @@ -1813,7 +1811,7 @@ |
76 | void DefaultAI::update_mineable_field(MineableField& field) { |
77 | // collect information about resources in the area |
78 | std::vector<ImmovableFound> immovables; |
79 | - Map& map = game().map(); |
80 | + const Map& map = game().map(); |
81 | map.find_immovables(Area<FCoords>(field.coords, 5), &immovables); |
82 | field.preferred = false; |
83 | field.mines_nearby = 0; |
84 | @@ -1948,7 +1946,7 @@ |
85 | bool mine = false; |
86 | uint32_t consumers_nearby_count = 0; |
87 | |
88 | - Map& map = game().map(); |
89 | + const Map& map = game().map(); |
90 | |
91 | for (int32_t i = 0; i < 4; ++i) |
92 | spots_avail.at(i) = 0; |
93 | @@ -3226,7 +3224,6 @@ |
94 | } else { |
95 | checkradius = 15; |
96 | } |
97 | - Map& map = game().map(); |
98 | |
99 | // algorithm to walk on roads |
100 | while (!queue.empty()) { |
101 | @@ -3270,7 +3267,7 @@ |
102 | endflag = &near_road->get_flag(Road::FlagEnd); |
103 | } |
104 | |
105 | - int32_t dist = map.calc_distance(roadstartflag.get_position(), endflag->get_position()); |
106 | + int32_t dist = game().map().calc_distance(roadstartflag.get_position(), endflag->get_position()); |
107 | |
108 | if (dist > checkradius) { // out of range of interest |
109 | continue; |
110 | @@ -3371,7 +3368,7 @@ |
111 | checkradius += 2; |
112 | } |
113 | |
114 | - Map& map = game().map(); |
115 | + const Map& map = game().map(); |
116 | |
117 | // initializing new object of FlagsForRoads, we will push there all candidate flags |
118 | Widelands::FlagsForRoads RoadCandidates(min_reduction); |
119 | @@ -3514,7 +3511,7 @@ |
120 | // first we block the field and vicinity for 15 minutes, probably it is not a good place to |
121 | // build on |
122 | MapRegion<Area<FCoords>> mr( |
123 | - game().map(), Area<FCoords>(map.get_fcoords(bld->get_position()), 2)); |
124 | + map, Area<FCoords>(map.get_fcoords(bld->get_position()), 2)); |
125 | do { |
126 | blocked_fields.add(mr.location(), game().get_gametime() + 15 * 60 * 1000); |
127 | } while (mr.advance(map)); |
128 | @@ -3605,7 +3602,7 @@ |
129 | } |
130 | } |
131 | |
132 | - Map& map = game().map(); |
133 | + const Map& map = game().map(); |
134 | |
135 | // The code here is bit complicated |
136 | // a) Either this site is pending for upgrade, if ready, order the upgrade |
137 | @@ -5437,7 +5434,7 @@ |
138 | uint16_t* mineable_fields_count, |
139 | const Coords& starting_spot, |
140 | const WalkSearch& type) { |
141 | - Map& map = game().map(); |
142 | + const Map& map = game().map(); |
143 | std::list<uint32_t> queue; |
144 | std::unordered_set<uint32_t> done; |
145 | queue.push_front(starting_spot.hash()); |
146 | @@ -5640,7 +5637,7 @@ |
147 | ++num_ports; |
148 | seafaring_economy = true; |
149 | // unblock nearby fields, might be used for other buildings... |
150 | - Map& map = game().map(); |
151 | + const Map& map = game().map(); |
152 | MapRegion<Area<FCoords>> mr( |
153 | map, Area<FCoords>(map.get_fcoords(warehousesites.back().site->get_position()), 3)); |
154 | do { |
155 | @@ -5809,9 +5806,8 @@ |
156 | return; |
157 | } |
158 | player_statistics.set_update_time(gametime); |
159 | - Map& map = game().map(); |
160 | Widelands::PlayerNumber const pn = player_number(); |
161 | - PlayerNumber const nr_players = map.get_nrplayers(); |
162 | + PlayerNumber const nr_players = game().map().get_nrplayers(); |
163 | uint32_t plr_in_game = 0; |
164 | iterate_players_existing_novar(p, nr_players, game())++ plr_in_game; |
165 | |
166 | |
167 | === modified file 'src/ai/defaultai_seafaring.cc' |
168 | --- src/ai/defaultai_seafaring.cc 2017-06-26 15:09:21 +0000 |
169 | +++ src/ai/defaultai_seafaring.cc 2017-08-20 12:33:35 +0000 |
170 | @@ -26,7 +26,7 @@ |
171 | // this scores spot for potential colony |
172 | uint8_t DefaultAI::spot_scoring(Widelands::Coords candidate_spot) { |
173 | |
174 | - Map& map = game().map(); |
175 | + const Map& map = game().map(); |
176 | PlayerNumber const pn = player_->player_number(); |
177 | uint8_t score = 0; |
178 | uint16_t mineable_fields_count = 0; |
179 | @@ -421,7 +421,6 @@ |
180 | // navigation decisions (these notifications are processes not in 'real time') |
181 | void DefaultAI::expedition_management(ShipObserver& so) { |
182 | |
183 | - Map& map = game().map(); |
184 | const int32_t gametime = game().get_gametime(); |
185 | PlayerNumber const pn = player_->player_number(); |
186 | // probability for island exploration repetition |
187 | @@ -484,6 +483,7 @@ |
188 | // we head for open sea again |
189 | } else { |
190 | // determine swimmable directions |
191 | + const Map& map = game().map(); |
192 | std::vector<Direction> possible_directions; |
193 | for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) { |
194 | // testing distance of 8 fields |
195 | |
196 | === modified file 'src/ai/defaultai_warfare.cc' |
197 | --- src/ai/defaultai_warfare.cc 2017-08-19 13:27:38 +0000 |
198 | +++ src/ai/defaultai_warfare.cc 2017-08-20 12:33:35 +0000 |
199 | @@ -23,7 +23,7 @@ |
200 | |
201 | bool DefaultAI::check_enemy_sites(uint32_t const gametime) { |
202 | |
203 | - Map& map = game().map(); |
204 | + const Map& map = game().map(); |
205 | |
206 | PlayerNumber const nr_players = map.get_nrplayers(); |
207 | uint32_t plr_in_game = 0; |
208 | @@ -777,7 +777,6 @@ |
209 | |
210 | // Check next militarysite |
211 | bool changed = false; |
212 | - Map& map = game().map(); |
213 | MilitarySite* ms = militarysites.front().site; |
214 | |
215 | // Don't do anything if last change took place lately |
216 | @@ -787,7 +786,7 @@ |
217 | return false; |
218 | } |
219 | |
220 | - FCoords f = map.get_fcoords(ms->get_position()); |
221 | + FCoords f = game().map().get_fcoords(ms->get_position()); |
222 | |
223 | BuildableField bf(f); |
224 | update_buildable_field(bf); |
225 | |
226 | === modified file 'src/economy/economy.cc' |
227 | --- src/economy/economy.cc 2017-06-20 08:17:02 +0000 |
228 | +++ src/economy/economy.cc 2017-08-20 12:33:35 +0000 |
229 | @@ -136,8 +136,6 @@ |
230 | |
231 | void Economy::check_splits() { |
232 | EditorGameBase& egbase = owner().egbase(); |
233 | - Map& map = egbase.map(); |
234 | - |
235 | while (split_checks_.size()) { |
236 | Flag* f1 = split_checks_.back().first.get(egbase); |
237 | Flag* f2 = split_checks_.back().second.get(egbase); |
238 | @@ -172,7 +170,7 @@ |
239 | // reached from f1. These nodes induce a connected subgraph. |
240 | // This means that the newly created economy, which contains all the |
241 | // flags that have been split, is already connected. |
242 | - RouteAStar<AStarEstimator> astar(*router_, wwWORKER, AStarEstimator(map, *f2)); |
243 | + RouteAStar<AStarEstimator> astar(*router_, wwWORKER, AStarEstimator(*egbase.mutable_map(), *f2)); |
244 | astar.push(*f1); |
245 | std::set<OPtr<Flag>> reachable; |
246 | |
247 | @@ -198,10 +196,8 @@ |
248 | Flag& start, Flag& end, Route* const route, WareWorker const type, int32_t const cost_cutoff) { |
249 | assert(start.get_economy() == this); |
250 | assert(end.get_economy() == this); |
251 | - |
252 | - Map& map = owner().egbase().map(); |
253 | - |
254 | - return router_->find_route(start, end, route, type, cost_cutoff, map); |
255 | + return router_->find_route( |
256 | + start, end, route, type, cost_cutoff, *owner().egbase().mutable_map()); |
257 | } |
258 | |
259 | struct ZeroEstimator { |
260 | @@ -604,7 +600,6 @@ |
261 | Route* best_route = nullptr; |
262 | int32_t best_cost = -1; |
263 | Flag& target_flag = req.target_flag(); |
264 | - Map& map = game.map(); |
265 | |
266 | available_supplies_.clear(); |
267 | |
268 | @@ -626,7 +621,7 @@ |
269 | const Widelands::Coords provider_position = |
270 | supp.get_position(game)->base_flag().get_position(); |
271 | |
272 | - const uint32_t dist = map.calc_distance(target_flag.get_position(), provider_position); |
273 | + const uint32_t dist = game.map().calc_distance(target_flag.get_position(), provider_position); |
274 | |
275 | UniqueDistance ud = {dist, supp.get_position(game)->serial(), provider}; |
276 | |
277 | |
278 | === modified file 'src/economy/fleet.cc' |
279 | --- src/economy/fleet.cc 2017-08-09 19:25:04 +0000 |
280 | +++ src/economy/fleet.cc 2017-08-20 12:33:35 +0000 |
281 | @@ -138,9 +138,7 @@ |
282 | * of the same player. |
283 | */ |
284 | void Fleet::find_other_fleet(EditorGameBase& egbase) { |
285 | - Map& map = egbase.map(); |
286 | - MapAStar<StepEvalFindFleet> astar(map, StepEvalFindFleet()); |
287 | - |
288 | + MapAStar<StepEvalFindFleet> astar(*egbase.mutable_map(), StepEvalFindFleet()); |
289 | for (const Ship* temp_ship : ships_) { |
290 | astar.push(temp_ship->get_position()); |
291 | } |
292 | @@ -443,7 +441,6 @@ |
293 | * because path finding is flaky during map loading. |
294 | */ |
295 | void Fleet::connect_port(EditorGameBase& egbase, uint32_t idx) { |
296 | - Map& map = egbase.map(); |
297 | StepEvalFindPorts se; |
298 | |
299 | for (uint32_t i = 0; i < ports_.size(); ++i) { |
300 | @@ -463,7 +460,7 @@ |
301 | if (se.targets.empty()) |
302 | return; |
303 | |
304 | - MapAStar<StepEvalFindPorts> astar(map, se); |
305 | + MapAStar<StepEvalFindPorts> astar(*egbase.mutable_map(), se); |
306 | |
307 | BaseImmovable::PositionList src(ports_[idx]->get_positions(egbase)); |
308 | for (const Coords& temp_pos : src) { |
309 | |
310 | === modified file 'src/economy/road.cc' |
311 | --- src/economy/road.cc 2017-04-23 12:11:19 +0000 |
312 | +++ src/economy/road.cc 2017-08-20 12:33:35 +0000 |
313 | @@ -109,7 +109,7 @@ |
314 | } |
315 | |
316 | BaseImmovable::PositionList Road::get_positions(const EditorGameBase& egbase) const { |
317 | - Map& map = egbase.map(); |
318 | + const Map& map = egbase.map(); |
319 | Coords curf = map.get_fcoords(path_.get_start()); |
320 | |
321 | PositionList rv; |
322 | @@ -155,7 +155,7 @@ |
323 | * Add road markings to the map |
324 | */ |
325 | void Road::mark_map(EditorGameBase& egbase) { |
326 | - Map& map = egbase.map(); |
327 | + const Map& map = egbase.map(); |
328 | FCoords curf = map.get_fcoords(path_.get_start()); |
329 | |
330 | const Path::StepVector::size_type nr_steps = path_.get_nsteps(); |
331 | @@ -189,7 +189,7 @@ |
332 | * Remove road markings from the map |
333 | */ |
334 | void Road::unmark_map(EditorGameBase& egbase) { |
335 | - Map& map = egbase.map(); |
336 | + const Map& map = egbase.map(); |
337 | FCoords curf(path_.get_start(), &map[path_.get_start()]); |
338 | |
339 | const Path::StepVector::size_type nr_steps = path_.get_nsteps(); |
340 | @@ -425,7 +425,7 @@ |
341 | oldend.detach_road(flagidx_[FlagEnd]); |
342 | |
343 | // build our new path and the new road's path |
344 | - Map& map = game.map(); |
345 | + const Map& map = game.map(); |
346 | CoordPath path(map, path_); |
347 | CoordPath secondpath(path); |
348 | int32_t const index = path.get_index(flag.get_position()); |
349 | |
350 | === modified file 'src/economy/test/test_road.cc' |
351 | --- src/economy/test/test_road.cc 2017-06-22 16:49:12 +0000 |
352 | +++ src/economy/test/test_road.cc 2017-08-20 12:33:35 +0000 |
353 | @@ -45,14 +45,6 @@ |
354 | set_flag_position(c); |
355 | } |
356 | }; |
357 | -struct TestingMap : public Map { |
358 | - TestingMap(int const w, int const h) : Map() { |
359 | - set_size(w, h); |
360 | - } |
361 | - |
362 | - void recalc_for_field_area(const World&, Area<FCoords>) override { |
363 | - } |
364 | -}; |
365 | |
366 | /*************************************************************************/ |
367 | /* TESTS */ |
368 | @@ -69,11 +61,9 @@ |
369 | |
370 | struct SimpleRoadTestsFixture : public WlTestFixture { |
371 | SimpleRoadTestsFixture() : g(nullptr), path(Coords(5, 5)) { |
372 | - map = new TestingMap(32, 32); |
373 | - g.set_map(map); |
374 | - |
375 | - path.append(*map, WALK_E); |
376 | - path.append(*map, WALK_E); |
377 | + g.mutable_map()->set_size(32, 32); |
378 | + path.append(g.map(), WALK_E); |
379 | + path.append(g.map(), WALK_E); |
380 | |
381 | start = new TestingFlag(g, Coords(5, 5)); |
382 | end = new TestingFlag(g, Coords(7, 5)); |
383 | @@ -84,7 +74,6 @@ |
384 | // Map is deleted by EditorGameBase |
385 | } |
386 | |
387 | - TestingMap* map; |
388 | EditorGameBase g; |
389 | Road r; |
390 | Path path; |
391 | |
392 | === modified file 'src/editor/editorinteractive.cc' |
393 | --- src/editor/editorinteractive.cc 2017-08-17 15:34:45 +0000 |
394 | +++ src/editor/editorinteractive.cc 2017-08-20 12:33:35 +0000 |
395 | @@ -177,21 +177,21 @@ |
396 | } |
397 | |
398 | void EditorInteractive::register_overlays() { |
399 | - Widelands::Map& map = egbase().map(); |
400 | + Widelands::Map* map = egbase().mutable_map(); |
401 | |
402 | // Starting locations |
403 | - Widelands::PlayerNumber const nr_players = map.get_nrplayers(); |
404 | + Widelands::PlayerNumber const nr_players = map->get_nrplayers(); |
405 | assert(nr_players <= kMaxPlayers); |
406 | iterate_player_numbers(p, nr_players) { |
407 | - if (Widelands::Coords const sp = map.get_starting_pos(p)) { |
408 | - tools_->set_starting_pos.set_starting_pos(*this, p, sp, &map); |
409 | + if (Widelands::Coords const sp = map->get_starting_pos(p)) { |
410 | + tools_->set_starting_pos.set_starting_pos(*this, p, sp, map); |
411 | } |
412 | } |
413 | |
414 | // Resources: we do not calculate default resources, therefore we do not |
415 | // expect to meet them here. |
416 | - Widelands::Extent const extent = map.extent(); |
417 | - iterate_Map_FCoords(map, extent, fc) { |
418 | + Widelands::Extent const extent = map->extent(); |
419 | + iterate_Map_FCoords(*map, extent, fc) { |
420 | if (uint8_t const amount = fc.field->get_resources_amount()) { |
421 | const std::string& immname = |
422 | egbase().world().get_resource(fc.field->get_resources())->editor_image(amount); |
423 | @@ -206,11 +206,11 @@ |
424 | void EditorInteractive::load(const std::string& filename) { |
425 | assert(filename.size()); |
426 | |
427 | - Widelands::Map& map = egbase().map(); |
428 | + Widelands::Map* map = egbase().mutable_map(); |
429 | |
430 | cleanup_for_load(); |
431 | |
432 | - std::unique_ptr<Widelands::MapLoader> ml(map.get_correct_loader(filename)); |
433 | + std::unique_ptr<Widelands::MapLoader> ml(map->get_correct_loader(filename)); |
434 | if (!ml.get()) |
435 | throw WLWarning( |
436 | _("Unsupported format"), |
437 | @@ -228,8 +228,8 @@ |
438 | |
439 | // Create the players. TODO(SirVer): this must be managed better |
440 | loader_ui.step(_("Creating players")); |
441 | - iterate_player_numbers(p, map.get_nrplayers()) { |
442 | - egbase().add_player(p, 0, map.get_scenario_player_tribe(p), map.get_scenario_player_name(p)); |
443 | + iterate_player_numbers(p, map->get_nrplayers()) { |
444 | + egbase().add_player(p, 0, map->get_scenario_player_tribe(p), map->get_scenario_player_name(p)); |
445 | } |
446 | |
447 | ml->load_map_complete(egbase(), Widelands::MapLoader::LoadType::kEditor); |
448 | @@ -288,8 +288,8 @@ |
449 | } |
450 | |
451 | void EditorInteractive::map_clicked(bool should_draw) { |
452 | - history_->do_action(tools_->current(), tools_->use_tool, egbase().map(), egbase().world(), |
453 | - get_sel_pos(), *this, should_draw); |
454 | + history_->do_action(tools_->current(), tools_->use_tool, *egbase().mutable_map(), |
455 | + egbase().world(), get_sel_pos(), *this, should_draw); |
456 | set_need_save(true); |
457 | } |
458 | |
459 | @@ -523,11 +523,10 @@ |
460 | toolsize_menu.update(toolsize_menu.value()); |
461 | } |
462 | } |
463 | - Widelands::Map& map = egbase().map(); |
464 | // A new tool has been selected. Remove all registered overlay callback |
465 | // functions. |
466 | mutable_field_overlay_manager()->register_overlay_callback_function(nullptr); |
467 | - map.recalc_whole_map(egbase().world()); |
468 | + egbase().mutable_map()->recalc_whole_map(egbase().world()); |
469 | } |
470 | tools_->current_pointer = &primary; |
471 | tools_->use_tool = which; |
472 | @@ -603,16 +602,15 @@ |
473 | GameTips editortips(loader_ui, tipstext); |
474 | |
475 | { |
476 | - Widelands::Map& map = *new Widelands::Map; |
477 | - egbase.set_map(&map); |
478 | if (filename.empty()) { |
479 | loader_ui.step(_("Creating empty map…")); |
480 | - map.create_empty_map(egbase.world(), 64, 64, 0, |
481 | - /** TRANSLATORS: Default name for new map */ |
482 | - _("No Name"), |
483 | - /** TRANSLATORS: Map author name when it hasn't been set yet */ |
484 | - g_options.pull_section("global").get_string( |
485 | - "realname", pgettext("author_name", "Unknown"))); |
486 | + egbase.mutable_map()->create_empty_map( |
487 | + egbase.world(), 64, 64, 0, |
488 | + /** TRANSLATORS: Default name for new map */ |
489 | + _("No Name"), |
490 | + /** TRANSLATORS: Map author name when it hasn't been set yet */ |
491 | + g_options.pull_section("global").get_string( |
492 | + "realname", pgettext("author_name", "Unknown"))); |
493 | |
494 | load_all_tribes(&egbase, &loader_ui); |
495 | |
496 | |
497 | === modified file 'src/editor/ui_menus/main_menu_map_options.cc' |
498 | --- src/editor/ui_menus/main_menu_map_options.cc 2017-06-11 20:09:05 +0000 |
499 | +++ src/editor/ui_menus/main_menu_map_options.cc 2017-08-20 12:33:35 +0000 |
500 | @@ -193,16 +193,16 @@ |
501 | } |
502 | |
503 | void MainMenuMapOptions::clicked_ok() { |
504 | - eia().egbase().map().set_name(name_.text()); |
505 | - eia().egbase().map().set_author(author_.text()); |
506 | + eia().egbase().mutable_map()->set_name(name_.text()); |
507 | + eia().egbase().mutable_map()->set_author(author_.text()); |
508 | g_options.pull_section("global").set_string("realname", author_.text()); |
509 | - eia().egbase().map().set_description(descr_->get_text()); |
510 | - eia().egbase().map().set_hint(hint_->get_text()); |
511 | + eia().egbase().mutable_map()->set_description(descr_->get_text()); |
512 | + eia().egbase().mutable_map()->set_hint(hint_->get_text()); |
513 | |
514 | - eia().egbase().map().clear_tags(); |
515 | + eia().egbase().mutable_map()->clear_tags(); |
516 | for (const auto& tag : tags_checkboxes_) { |
517 | if (tag.second->get_state()) { |
518 | - eia().egbase().map().add_tag(tag.first); |
519 | + eia().egbase().mutable_map()->add_tag(tag.first); |
520 | } |
521 | } |
522 | |
523 | |
524 | === modified file 'src/editor/ui_menus/main_menu_new_map.cc' |
525 | --- src/editor/ui_menus/main_menu_new_map.cc 2017-02-25 11:17:28 +0000 |
526 | +++ src/editor/ui_menus/main_menu_new_map.cc 2017-08-20 12:33:35 +0000 |
527 | @@ -138,14 +138,14 @@ |
528 | void MainMenuNewMap::clicked_create_map() { |
529 | EditorInteractive& parent = eia(); |
530 | Widelands::EditorGameBase& egbase = parent.egbase(); |
531 | - Widelands::Map& map = egbase.map(); |
532 | + Widelands::Map* map = egbase.mutable_map(); |
533 | UI::ProgressWindow loader_ui; |
534 | |
535 | loader_ui.step(_("Creating empty map…")); |
536 | |
537 | parent.cleanup_for_load(); |
538 | |
539 | - map.create_empty_map( |
540 | + map->create_empty_map( |
541 | egbase.world(), width_.get_value() > 0 ? width_.get_value() : Widelands::kMapDimensions[0], |
542 | height_.get_value() > 0 ? height_.get_value() : Widelands::kMapDimensions[0], |
543 | list_.get_selected(), _("No Name"), |
544 | @@ -154,7 +154,7 @@ |
545 | egbase.postload(); |
546 | egbase.load_graphics(loader_ui); |
547 | |
548 | - map.recalc_whole_map(egbase.world()); |
549 | + map->recalc_whole_map(egbase.world()); |
550 | parent.map_changed(EditorInteractive::MapWas::kReplaced); |
551 | die(); |
552 | } |
553 | |
554 | === modified file 'src/editor/ui_menus/main_menu_random_map.cc' |
555 | --- src/editor/ui_menus/main_menu_random_map.cc 2017-06-20 08:18:38 +0000 |
556 | +++ src/editor/ui_menus/main_menu_random_map.cc 2017-08-20 12:33:35 +0000 |
557 | @@ -231,8 +231,7 @@ |
558 | width_.set_value_list(Widelands::kMapDimensions); |
559 | height_.set_value_list(Widelands::kMapDimensions); |
560 | { |
561 | - const Widelands::Map& map = parent.egbase().map(); |
562 | - Widelands::Extent const map_extent = map.extent(); |
563 | + Widelands::Extent const map_extent = parent.egbase().map().extent(); |
564 | width_.set_value(find_dimension_index(map_extent.w)); |
565 | height_.set_value(find_dimension_index(map_extent.h)); |
566 | } |
567 | @@ -512,7 +511,7 @@ |
568 | cancel_button_.set_enabled(false); |
569 | EditorInteractive& eia = dynamic_cast<EditorInteractive&>(*get_parent()); |
570 | Widelands::EditorGameBase& egbase = eia.egbase(); |
571 | - Widelands::Map& map = egbase.map(); |
572 | + Widelands::Map* map = egbase.mutable_map(); |
573 | UI::ProgressWindow loader_ui; |
574 | |
575 | eia.cleanup_for_load(); |
576 | @@ -528,12 +527,12 @@ |
577 | << "Resources = " << resources_.get_title() << "\n" |
578 | << "ID = " << map_id_edit_.text() << "\n"; |
579 | |
580 | - MapGenerator gen(map, map_info, egbase); |
581 | - map.create_empty_map( |
582 | - egbase.world(), map_info.w, map_info.h, 0, _("No Name"), |
583 | - g_options.pull_section("global").get_string("realname", pgettext("author_name", "Unknown")), |
584 | - sstrm.str().c_str()); |
585 | - loader_ui.step(_("Generating random map…")); |
586 | + MapGenerator gen(*map, map_info, egbase); |
587 | + map->create_empty_map( |
588 | + egbase.world(), map_info.w, map_info.h, 0, _("No Name"), |
589 | + g_options.pull_section("global").get_string("realname", pgettext("author_name", "Unknown")), |
590 | + sstrm.str().c_str()); |
591 | + loader_ui.step(_("Generating random map…")); |
592 | |
593 | log("============== Generating Map ==============\n"); |
594 | log("ID: %s\n", map_id_edit_.text().c_str()); |
595 | @@ -564,7 +563,7 @@ |
596 | egbase.postload(); |
597 | egbase.load_graphics(loader_ui); |
598 | |
599 | - map.recalc_whole_map(egbase.world()); |
600 | + map->recalc_whole_map(egbase.world()); |
601 | eia.map_changed(EditorInteractive::MapWas::kReplaced); |
602 | UI::WLMessageBox mbox( |
603 | &eia, |
604 | |
605 | === modified file 'src/editor/ui_menus/main_menu_save_map.cc' |
606 | --- src/editor/ui_menus/main_menu_save_map.cc 2017-02-26 12:16:09 +0000 |
607 | +++ src/editor/ui_menus/main_menu_save_map.cc 2017-08-20 12:33:35 +0000 |
608 | @@ -129,10 +129,10 @@ |
609 | set_current_directory(complete_filename); |
610 | fill_table(); |
611 | } else { // Ok, save this map |
612 | - Widelands::Map& map = eia().egbase().map(); |
613 | - if (map.get_name() == _("No Name")) { |
614 | + Widelands::Map* map = eia().egbase().mutable_map(); |
615 | + if (map->get_name() == _("No Name")) { |
616 | std::string::size_type const filename_size = filename.size(); |
617 | - map.set_name(4 <= filename_size && boost::iends_with(filename, WLMF_SUFFIX) ? |
618 | + map->set_name(4 <= filename_size && boost::iends_with(filename, WLMF_SUFFIX) ? |
619 | filename.substr(0, filename_size - 4) : |
620 | filename); |
621 | } |
622 | @@ -272,23 +272,23 @@ |
623 | } |
624 | |
625 | Widelands::EditorGameBase& egbase = eia().egbase(); |
626 | - Widelands::Map& map = egbase.map(); |
627 | + Widelands::Map* map = egbase.mutable_map(); |
628 | |
629 | { // fs scope |
630 | std::unique_ptr<FileSystem> fs( |
631 | g_fs->create_sub_file_system(tmp_name, binary ? FileSystem::ZIP : FileSystem::DIR)); |
632 | |
633 | // Recompute seafaring tag |
634 | - if (map.allows_seafaring()) { |
635 | - map.add_tag("seafaring"); |
636 | + if (map->allows_seafaring()) { |
637 | + map->add_tag("seafaring"); |
638 | } else { |
639 | - map.delete_tag("seafaring"); |
640 | + map->delete_tag("seafaring"); |
641 | } |
642 | |
643 | - if (map.has_artifacts()) { |
644 | - map.add_tag("artifacts"); |
645 | + if (map->has_artifacts()) { |
646 | + map->add_tag("artifacts"); |
647 | } else { |
648 | - map.delete_tag("artifacts"); |
649 | + map->delete_tag("artifacts"); |
650 | } |
651 | |
652 | try { |
653 | @@ -297,14 +297,14 @@ |
654 | delete wms; |
655 | // Reset filesystem to avoid file locks on saves |
656 | fs.reset(); |
657 | - map.reset_filesystem(); |
658 | + map->reset_filesystem(); |
659 | eia().set_need_save(false); |
660 | g_fs->fs_unlink(complete_filename); |
661 | g_fs->fs_rename(tmp_name, complete_filename); |
662 | // Also change fs, as we assign it to the map below |
663 | fs.reset(g_fs->make_sub_file_system(complete_filename)); |
664 | // Set the filesystem of the map to the current save file / directory |
665 | - map.swap_filesystem(fs); |
666 | + map->swap_filesystem(fs); |
667 | // DONT use fs as of here, its garbage now! |
668 | |
669 | } catch (const std::exception& e) { |
670 | |
671 | === modified file 'src/editor/ui_menus/player_menu.cc' |
672 | --- src/editor/ui_menus/player_menu.cc 2017-08-18 02:28:27 +0000 |
673 | +++ src/editor/ui_menus/player_menu.cc 2017-08-20 12:33:35 +0000 |
674 | @@ -110,8 +110,8 @@ |
675 | if (is_minimal()) |
676 | return; |
677 | |
678 | - Widelands::Map& map = eia().egbase().map(); |
679 | - Widelands::PlayerNumber const nr_players = map.get_nrplayers(); |
680 | + Widelands::Map* map = eia().egbase().mutable_map(); |
681 | + Widelands::PlayerNumber const nr_players = map->get_nrplayers(); |
682 | { |
683 | assert(nr_players <= 99); // 2 decimal digits |
684 | char text[3]; |
685 | @@ -147,7 +147,7 @@ |
686 | plr_names_[p - 1]->changed.connect( |
687 | boost::bind(&EditorPlayerMenu::name_changed, this, p - 1)); |
688 | posx += 140 + spacing; |
689 | - plr_names_[p - 1]->set_text(map.get_scenario_player_name(p)); |
690 | + plr_names_[p - 1]->set_text(map->get_scenario_player_name(p)); |
691 | } |
692 | |
693 | if (!plr_set_tribes_buts_[p - 1]) { |
694 | @@ -160,19 +160,19 @@ |
695 | } |
696 | |
697 | // Get/Set (localized) tribe names |
698 | - if (map.get_scenario_player_tribe(p) != UNDEFINED_TRIBE_NAME) { |
699 | - selected_tribes_[p - 1] = map.get_scenario_player_tribe(p); |
700 | + if (map->get_scenario_player_tribe(p) != UNDEFINED_TRIBE_NAME) { |
701 | + selected_tribes_[p - 1] = map->get_scenario_player_tribe(p); |
702 | } else { |
703 | selected_tribes_[p - 1] = tribenames_[0]; |
704 | - map.set_scenario_player_tribe(p, selected_tribes_[p - 1]); |
705 | + map->set_scenario_player_tribe(p, selected_tribes_[p - 1]); |
706 | } |
707 | |
708 | plr_set_tribes_buts_[p - 1]->set_title( |
709 | Widelands::get_tribeinfo(selected_tribes_[p - 1]).descname); |
710 | |
711 | // Set default AI and closeable to false (always default - should be changed by hand) |
712 | - map.set_scenario_player_ai(p, ""); |
713 | - map.set_scenario_player_closeable(p, false); |
714 | + map->set_scenario_player_ai(p, ""); |
715 | + map->set_scenario_player_closeable(p, false); |
716 | |
717 | // Set Starting pos button. |
718 | if (!plr_set_pos_buts_[p - 1]) { |
719 | @@ -195,18 +195,18 @@ |
720 | } |
721 | |
722 | void EditorPlayerMenu::clicked_add_player() { |
723 | - Widelands::Map& map = eia().egbase().map(); |
724 | - Widelands::PlayerNumber const nr_players = map.get_nrplayers() + 1; |
725 | + Widelands::Map* map = eia().egbase().mutable_map(); |
726 | + Widelands::PlayerNumber const nr_players = map->get_nrplayers() + 1; |
727 | assert(nr_players <= kMaxPlayers); |
728 | - map.set_nrplayers(nr_players); |
729 | + map->set_nrplayers(nr_players); |
730 | { // register new default name for this players |
731 | assert(nr_players <= 99); // 2 decimal digits |
732 | /** TRANSLATORS: Default player name, e.g. Player 1 */ |
733 | const std::string name = |
734 | (boost::format(_("Player %u")) % static_cast<unsigned int>(nr_players)).str(); |
735 | - map.set_scenario_player_name(nr_players, name); |
736 | + map->set_scenario_player_name(nr_players, name); |
737 | } |
738 | - map.set_scenario_player_tribe(nr_players, tribenames_[0]); |
739 | + map->set_scenario_player_tribe(nr_players, tribenames_[0]); |
740 | eia().set_need_save(true); |
741 | add_player_.set_enabled(nr_players < kMaxPlayers); |
742 | remove_last_player_.set_enabled(true); |
743 | @@ -215,13 +215,13 @@ |
744 | |
745 | void EditorPlayerMenu::clicked_remove_last_player() { |
746 | EditorInteractive& menu = eia(); |
747 | - Widelands::Map& map = menu.egbase().map(); |
748 | - Widelands::PlayerNumber const old_nr_players = map.get_nrplayers(); |
749 | + Widelands::Map* map = menu.egbase().mutable_map(); |
750 | + Widelands::PlayerNumber const old_nr_players = map->get_nrplayers(); |
751 | Widelands::PlayerNumber const nr_players = old_nr_players - 1; |
752 | assert(1 <= nr_players); |
753 | |
754 | if (!menu.is_player_tribe_referenced(old_nr_players)) { |
755 | - if (const Widelands::Coords sp = map.get_starting_pos(old_nr_players)) { |
756 | + if (const Widelands::Coords sp = map->get_starting_pos(old_nr_players)) { |
757 | // Remove starting position marker. |
758 | const Image* player_image = |
759 | playercolor_image(old_nr_players - 1, "images/players/player_position.png"); |
760 | @@ -232,7 +232,7 @@ |
761 | if (old_nr_players == menu.tools()->set_starting_pos.get_current_player()) |
762 | set_starting_pos_clicked(nr_players); |
763 | } |
764 | - map.set_nrplayers(nr_players); |
765 | + map->set_nrplayers(nr_players); |
766 | add_player_.set_enabled(nr_players < kMaxPlayers); |
767 | remove_last_player_.set_enabled(1 < nr_players); |
768 | update(); |
769 | @@ -257,7 +257,7 @@ |
770 | } |
771 | } |
772 | selected_tribes_[n] = i == tribenames_.size() - 1 ? tribenames_[0] : tribenames_[++i]; |
773 | - menu.egbase().map().set_scenario_player_tribe(n + 1, selected_tribes_[n]); |
774 | + menu.egbase().mutable_map()->set_scenario_player_tribe(n + 1, selected_tribes_[n]); |
775 | menu.set_need_save(true); |
776 | } else { |
777 | UI::WLMessageBox mmb(&menu, _("Error!"), |
778 | @@ -275,8 +275,8 @@ |
779 | void EditorPlayerMenu::set_starting_pos_clicked(uint8_t n) { |
780 | EditorInteractive& menu = eia(); |
781 | // jump to the current node |
782 | - Widelands::Map& map = menu.egbase().map(); |
783 | - if (Widelands::Coords const sp = map.get_starting_pos(n)) { |
784 | + Widelands::Map* map = menu.egbase().mutable_map(); |
785 | + if (Widelands::Coords const sp = map->get_starting_pos(n)) { |
786 | menu.map_view()->scroll_to_field(sp, MapView::Transition::Smooth); |
787 | } |
788 | |
789 | @@ -290,8 +290,8 @@ |
790 | // Register callback function to make sure that only valid locations are |
791 | // selected. |
792 | menu.mutable_field_overlay_manager()->register_overlay_callback_function( |
793 | - boost::bind(&editor_tool_set_starting_pos_callback, _1, boost::ref(map))); |
794 | - map.recalc_whole_map(menu.egbase().world()); |
795 | + boost::bind(&editor_tool_set_starting_pos_callback, _1, boost::ref(*map))); |
796 | + map->recalc_whole_map(menu.egbase().world()); |
797 | update(); |
798 | } |
799 | |
800 | @@ -302,8 +302,8 @@ |
801 | // Player name has been changed. |
802 | std::string text = plr_names_[m]->text(); |
803 | EditorInteractive& menu = eia(); |
804 | - Widelands::Map& map = menu.egbase().map(); |
805 | - map.set_scenario_player_name(m + 1, text); |
806 | - plr_names_[m]->set_text(map.get_scenario_player_name(m + 1)); |
807 | + Widelands::Map* map = menu.egbase().mutable_map(); |
808 | + map->set_scenario_player_name(m + 1, text); |
809 | + plr_names_[m]->set_text(map->get_scenario_player_name(m + 1)); |
810 | menu.set_need_save(true); |
811 | } |
812 | |
813 | === modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc' |
814 | --- src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-08-13 18:02:53 +0000 |
815 | +++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-08-20 12:33:35 +0000 |
816 | @@ -154,16 +154,16 @@ |
817 | increase_tool_.decrease_tool().set_cur_res(resource_index); |
818 | |
819 | Widelands::EditorGameBase& egbase = eia().egbase(); |
820 | - Widelands::Map& map = egbase.map(); |
821 | + Widelands::Map* map = egbase.mutable_map(); |
822 | eia().mutable_field_overlay_manager()->register_overlay_callback_function( |
823 | - [resource_index, &map, &egbase](const Widelands::FCoords& fc) -> uint32_t { |
824 | - if (map.is_resource_valid(egbase.world(), fc, resource_index)) { |
825 | + [resource_index, map, &egbase](const Widelands::FCoords& fc) -> uint32_t { |
826 | + if (map->is_resource_valid(egbase.world(), fc, resource_index)) { |
827 | return fc.field->nodecaps(); |
828 | } |
829 | return 0; |
830 | }); |
831 | |
832 | - map.recalc_whole_map(egbase.world()); |
833 | + map->recalc_whole_map(egbase.world()); |
834 | select_correct_tool(); |
835 | update(); |
836 | } |
837 | |
838 | === modified file 'src/editor/ui_menus/tool_menu.cc' |
839 | --- src/editor/ui_menus/tool_menu.cc 2017-08-13 18:02:53 +0000 |
840 | +++ src/editor/ui_menus/tool_menu.cc 2017-08-20 12:33:35 +0000 |
841 | @@ -142,10 +142,10 @@ |
842 | parent.select_tool(*current_tool_pointer, EditorTool::First); |
843 | if (current_tool_pointer == &parent.tools()->set_port_space) { |
844 | // Set correct overlay |
845 | - Widelands::Map& map = parent.egbase().map(); |
846 | + Widelands::Map* map = parent.egbase().mutable_map(); |
847 | parent.mutable_field_overlay_manager()->register_overlay_callback_function( |
848 | - boost::bind(&editor_tool_set_port_space_callback, _1, boost::ref(map))); |
849 | - map.recalc_whole_map(parent.egbase().world()); |
850 | + boost::bind(&editor_tool_set_port_space_callback, _1, boost::ref(*map))); |
851 | + map->recalc_whole_map(parent.egbase().world()); |
852 | } |
853 | |
854 | if (current_registry_pointer) { |
855 | |
856 | === modified file 'src/game_io/game_map_packet.cc' |
857 | --- src/game_io/game_map_packet.cc 2017-01-25 18:55:59 +0000 |
858 | +++ src/game_io/game_map_packet.cc 2017-08-20 12:33:35 +0000 |
859 | @@ -41,7 +41,7 @@ |
860 | // Now Load the map as it would be a normal map saving. |
861 | delete wml_; |
862 | |
863 | - wml_ = new WidelandsMapLoader(fs.make_sub_file_system("map"), &game.map()); |
864 | + wml_ = new WidelandsMapLoader(fs.make_sub_file_system("map"), game.mutable_map()); |
865 | |
866 | wml_->preload_map(true); |
867 | |
868 | |
869 | === modified file 'src/game_io/game_player_ai_persistent_packet.cc' |
870 | --- src/game_io/game_player_ai_persistent_packet.cc 2017-06-28 08:50:42 +0000 |
871 | +++ src/game_io/game_player_ai_persistent_packet.cc 2017-08-20 12:33:35 +0000 |
872 | @@ -32,8 +32,7 @@ |
873 | |
874 | void GamePlayerAiPersistentPacket::read(FileSystem& fs, Game& game, MapObjectLoader*) { |
875 | try { |
876 | - const Map& map = game.map(); |
877 | - PlayerNumber const nr_players = map.get_nrplayers(); |
878 | + PlayerNumber const nr_players = game.map().get_nrplayers(); |
879 | |
880 | FileRead fr; |
881 | fr.open(fs, "binary/player_ai"); |
882 | @@ -125,8 +124,7 @@ |
883 | |
884 | fw.unsigned_16(kCurrentPacketVersion); |
885 | |
886 | - const Map& map = game.map(); |
887 | - PlayerNumber const nr_players = map.get_nrplayers(); |
888 | + PlayerNumber const nr_players = game.map().get_nrplayers(); |
889 | iterate_players_existing_const(p, nr_players, game, player) { |
890 | fw.unsigned_8(player->ai_data.initialized); |
891 | fw.unsigned_32(player->ai_data.colony_scan_area); |
892 | |
893 | === modified file 'src/graphic/game_renderer.cc' |
894 | --- src/graphic/game_renderer.cc 2017-08-16 08:59:09 +0000 |
895 | +++ src/graphic/game_renderer.cc 2017-08-20 12:33:35 +0000 |
896 | @@ -340,7 +340,7 @@ |
897 | const int surface_width = surface->width(); |
898 | const int surface_height = surface->height(); |
899 | |
900 | - Map& map = egbase.map(); |
901 | + const Map& map = egbase.map(); |
902 | const uint32_t gametime = egbase.get_gametime(); |
903 | |
904 | const float scale = 1.f / zoom; |
905 | |
906 | === modified file 'src/graphic/minimap_renderer.cc' |
907 | --- src/graphic/minimap_renderer.cc 2017-08-09 19:25:04 +0000 |
908 | +++ src/graphic/minimap_renderer.cc 2017-08-20 12:33:35 +0000 |
909 | @@ -158,7 +158,7 @@ |
910 | const Widelands::Map& map = egbase.map(); |
911 | const uint16_t surface_h = texture->height(); |
912 | const uint16_t surface_w = texture->width(); |
913 | - const int32_t mapwidth = egbase.get_map().get_width(); |
914 | + const int32_t mapwidth = map.get_width(); |
915 | |
916 | for (uint32_t y = 0; y < surface_h; ++y) { |
917 | Widelands::FCoords f( |
918 | |
919 | === modified file 'src/logic/editor_game_base.cc' |
920 | --- src/logic/editor_game_base.cc 2017-06-25 08:20:25 +0000 |
921 | +++ src/logic/editor_game_base.cc 2017-08-20 12:33:35 +0000 |
922 | @@ -67,14 +67,12 @@ |
923 | : gametime_(0), |
924 | lua_(lua_interface), |
925 | player_manager_(new PlayersManager(*this)), |
926 | - ibase_(nullptr), |
927 | - map_(nullptr) { |
928 | + ibase_(nullptr) { |
929 | if (!lua_) // TODO(SirVer): this is sooo ugly, I can't say |
930 | lua_.reset(new LuaEditorInterface(this)); |
931 | } |
932 | |
933 | EditorGameBase::~EditorGameBase() { |
934 | - delete map_; |
935 | delete player_manager_.release(); |
936 | } |
937 | |
938 | @@ -187,19 +185,6 @@ |
939 | } |
940 | } |
941 | |
942 | -/** |
943 | - * Replaces the current map with the given one. Ownership of the map is transferred |
944 | - * to the EditorGameBase object. |
945 | - */ |
946 | -void EditorGameBase::set_map(Map* const new_map) { |
947 | - assert(new_map != map_); |
948 | - assert(new_map); |
949 | - |
950 | - delete map_; |
951 | - |
952 | - map_ = new_map; |
953 | -} |
954 | - |
955 | void EditorGameBase::allocate_player_maps() { |
956 | iterate_players_existing(plnum, kMaxPlayers, *this, p) { |
957 | p->allocate_map(); |
958 | @@ -412,8 +397,7 @@ |
959 | |
960 | player_manager_->cleanup(); |
961 | |
962 | - if (map_) |
963 | - map_->cleanup(); |
964 | + map_.cleanup(); |
965 | } |
966 | |
967 | void EditorGameBase::set_road(const FCoords& f, uint8_t const direction, uint8_t const roadtype) { |
968 | @@ -566,7 +550,7 @@ |
969 | // This must reach one step beyond the conquered area to adjust the borders |
970 | // of neighbour players. |
971 | ++player_area.radius; |
972 | - map().recalc_for_field_area(world(), player_area); |
973 | + map_.recalc_for_field_area(world(), player_area); |
974 | } |
975 | |
976 | /// Conquers the given area for that player; does the actual work. |
977 | @@ -642,21 +626,20 @@ |
978 | // This must reach one step beyond the conquered area to adjust the borders |
979 | // of neighbour players. |
980 | ++player_area.radius; |
981 | - map().recalc_for_field_area(world(), player_area); |
982 | + map_.recalc_for_field_area(world(), player_area); |
983 | } |
984 | |
985 | /// Makes sure that buildings cannot exist outside their owner's territory. |
986 | void EditorGameBase::cleanup_playerimmovables_area(PlayerArea<Area<FCoords>> const area) { |
987 | std::vector<ImmovableFound> immovables; |
988 | std::vector<PlayerImmovable*> burnlist; |
989 | - Map& m = map(); |
990 | |
991 | // find all immovables that need fixing |
992 | - m.find_immovables(area, &immovables, FindImmovablePlayerImmovable()); |
993 | + map_.find_immovables(area, &immovables, FindImmovablePlayerImmovable()); |
994 | |
995 | for (const ImmovableFound& temp_imm : immovables) { |
996 | upcast(PlayerImmovable, imm, temp_imm.object); |
997 | - if (!m[temp_imm.coords].is_interior(imm->owner().player_number())) { |
998 | + if (!map_[temp_imm.coords].is_interior(imm->owner().player_number())) { |
999 | if (std::find(burnlist.begin(), burnlist.end(), imm) == burnlist.end()) { |
1000 | burnlist.push_back(imm); |
1001 | } |
1002 | |
1003 | === modified file 'src/logic/editor_game_base.h' |
1004 | --- src/logic/editor_game_base.h 2017-06-25 19:12:30 +0000 |
1005 | +++ src/logic/editor_game_base.h 2017-08-20 12:33:35 +0000 |
1006 | @@ -84,16 +84,11 @@ |
1007 | explicit EditorGameBase(LuaInterface* lua); |
1008 | virtual ~EditorGameBase(); |
1009 | |
1010 | - void set_map(Map*); |
1011 | - // TODO(sirver): this should just be const Map& map() and Map* mutable_map(). |
1012 | - Map& map() const { |
1013 | - return *map_; |
1014 | - } |
1015 | - Map* get_map() { |
1016 | + const Map& map() const { |
1017 | return map_; |
1018 | } |
1019 | - Map& get_map() const { |
1020 | - return *map_; |
1021 | + Map* mutable_map() { |
1022 | + return &map_; |
1023 | } |
1024 | const ObjectManager& objects() const { |
1025 | return objects_; |
1026 | @@ -258,7 +253,7 @@ |
1027 | std::unique_ptr<World> world_; |
1028 | std::unique_ptr<Tribes> tribes_; |
1029 | std::unique_ptr<InteractiveBase> ibase_; |
1030 | - Map* map_; |
1031 | + Map map_; |
1032 | |
1033 | DISALLOW_COPY_AND_ASSIGN(EditorGameBase); |
1034 | }; |
1035 | |
1036 | === modified file 'src/logic/game.cc' |
1037 | --- src/logic/game.cc 2017-08-18 02:28:27 +0000 |
1038 | +++ src/logic/game.cc 2017-08-20 12:33:35 +0000 |
1039 | @@ -192,14 +192,10 @@ |
1040 | |
1041 | bool Game::run_splayer_scenario_direct(const std::string& mapname, |
1042 | const std::string& script_to_run) { |
1043 | - assert(!get_map()); |
1044 | - |
1045 | // Replays can't handle scenarios |
1046 | set_write_replay(false); |
1047 | |
1048 | - set_map(new Map); |
1049 | - |
1050 | - std::unique_ptr<MapLoader> maploader(map().get_correct_loader(mapname)); |
1051 | + std::unique_ptr<MapLoader> maploader(mutable_map()->get_correct_loader(mapname)); |
1052 | if (!maploader) |
1053 | throw wexception("could not load \"%s\"", mapname.c_str()); |
1054 | UI::ProgressWindow loader_ui; |
1055 | @@ -252,10 +248,7 @@ |
1056 | |
1057 | loader_ui->step(_("Preloading map")); |
1058 | |
1059 | - assert(!get_map()); |
1060 | - set_map(new Map); |
1061 | - |
1062 | - std::unique_ptr<MapLoader> maploader(map().get_correct_loader(settings.mapfilename)); |
1063 | + std::unique_ptr<MapLoader> maploader(mutable_map()->get_correct_loader(settings.mapfilename)); |
1064 | assert(maploader != nullptr); |
1065 | maploader->preload_map(settings.scenario); |
1066 | |
1067 | @@ -325,8 +318,6 @@ |
1068 | |
1069 | loader_ui->step(_("Preloading map")); |
1070 | |
1071 | - assert(!get_map()); |
1072 | - set_map(new Map); |
1073 | try { |
1074 | GameLoader gl(settings.mapfilename, *this); |
1075 | Widelands::GamePreloadPacket gpdp; |
1076 | @@ -355,9 +346,6 @@ |
1077 | |
1078 | loader_ui.step(_("Preloading map")); |
1079 | |
1080 | - // We have to create an empty map, otherwise nothing will load properly |
1081 | - set_map(new Map); |
1082 | - |
1083 | { |
1084 | GameLoader gl(filename, *this); |
1085 | |
1086 | @@ -462,7 +450,7 @@ |
1087 | } |
1088 | |
1089 | // Prepare the map, set default textures |
1090 | - map().recalc_default_resources(world()); |
1091 | + mutable_map()->recalc_default_resources(world()); |
1092 | |
1093 | // Finally, set the scenario names and tribes to represent |
1094 | // the correct names of the players |
1095 | @@ -472,10 +460,10 @@ |
1096 | const std::string& player_tribe = plr ? plr->tribe().name() : no_name; |
1097 | const std::string& player_name = plr ? plr->get_name() : no_name; |
1098 | const std::string& player_ai = plr ? plr->get_ai() : no_name; |
1099 | - map().set_scenario_player_tribe(p, player_tribe); |
1100 | - map().set_scenario_player_name(p, player_name); |
1101 | - map().set_scenario_player_ai(p, player_ai); |
1102 | - map().set_scenario_player_closeable(p, false); // player is already initialized. |
1103 | + mutable_map()->set_scenario_player_tribe(p, player_tribe); |
1104 | + mutable_map()->set_scenario_player_name(p, player_name); |
1105 | + mutable_map()->set_scenario_player_ai(p, player_ai); |
1106 | + mutable_map()->set_scenario_player_closeable(p, false); // player is already initialized. |
1107 | } |
1108 | |
1109 | // Run the init script, if the map provides one. |
1110 | |
1111 | === modified file 'src/logic/map.cc' |
1112 | --- src/logic/map.cc 2017-08-12 20:13:24 +0000 |
1113 | +++ src/logic/map.cc 2017-08-20 12:33:35 +0000 |
1114 | @@ -565,7 +565,7 @@ |
1115 | =============== |
1116 | */ |
1117 | template <typename functorT> |
1118 | -void Map::find_reachable(const Area<FCoords>& area, const CheckStep& checkstep, functorT& functor) { |
1119 | +void Map::find_reachable(const Area<FCoords>& area, const CheckStep& checkstep, functorT& functor) const { |
1120 | std::vector<Coords> queue; |
1121 | boost::shared_ptr<Pathfields> pathfields = pathfieldmgr_->allocate(); |
1122 | |
1123 | @@ -655,7 +655,7 @@ |
1124 | =============== |
1125 | */ |
1126 | uint32_t |
1127 | -Map::find_bobs(Area<FCoords> const area, std::vector<Bob*>* const list, const FindBob& functor) { |
1128 | +Map::find_bobs(Area<FCoords> const area, std::vector<Bob*>* const list, const FindBob& functor) const { |
1129 | FindBobsCallback cb(list, functor); |
1130 | |
1131 | find(area, cb); |
1132 | @@ -678,7 +678,7 @@ |
1133 | uint32_t Map::find_reachable_bobs(Area<FCoords> const area, |
1134 | std::vector<Bob*>* const list, |
1135 | const CheckStep& checkstep, |
1136 | - const FindBob& functor) { |
1137 | + const FindBob& functor) const { |
1138 | FindBobsCallback cb(list, functor); |
1139 | |
1140 | find_reachable(area, checkstep, cb); |
1141 | @@ -731,7 +731,7 @@ |
1142 | */ |
1143 | uint32_t Map::find_immovables(Area<FCoords> const area, |
1144 | std::vector<ImmovableFound>* const list, |
1145 | - const FindImmovable& functor) { |
1146 | + const FindImmovable& functor) const{ |
1147 | FindImmovablesCallback cb(list, functor); |
1148 | |
1149 | find(area, cb); |
1150 | @@ -752,7 +752,7 @@ |
1151 | uint32_t Map::find_reachable_immovables(Area<FCoords> const area, |
1152 | std::vector<ImmovableFound>* const list, |
1153 | const CheckStep& checkstep, |
1154 | - const FindImmovable& functor) { |
1155 | + const FindImmovable& functor) const { |
1156 | FindImmovablesCallback cb(list, functor); |
1157 | |
1158 | find_reachable(area, checkstep, cb); |
1159 | @@ -770,7 +770,7 @@ |
1160 | uint32_t Map::find_reachable_immovables_unique(const Area<FCoords> area, |
1161 | std::vector<BaseImmovable*>& list, |
1162 | const CheckStep& checkstep, |
1163 | - const FindImmovable& functor) { |
1164 | + const FindImmovable& functor) const { |
1165 | std::vector<ImmovableFound> duplist; |
1166 | FindImmovablesCallback cb(&duplist, find_immovable_always_true()); |
1167 | |
1168 | @@ -824,7 +824,7 @@ |
1169 | =============== |
1170 | */ |
1171 | uint32_t |
1172 | -Map::find_fields(Area<FCoords> const area, std::vector<Coords>* list, const FindNode& functor) { |
1173 | +Map::find_fields(Area<FCoords> const area, std::vector<Coords>* list, const FindNode& functor) const { |
1174 | FindNodesCallback cb(list, functor); |
1175 | |
1176 | find(area, cb); |
1177 | @@ -844,7 +844,7 @@ |
1178 | uint32_t Map::find_reachable_fields(Area<FCoords> const area, |
1179 | std::vector<Coords>* list, |
1180 | const CheckStep& checkstep, |
1181 | - const FindNode& functor) { |
1182 | + const FindNode& functor) const { |
1183 | FindNodesCallback cb(list, functor); |
1184 | |
1185 | find_reachable(area, checkstep, cb); |
1186 | @@ -1595,7 +1595,7 @@ |
1187 | int32_t const persist, |
1188 | Path& path, |
1189 | const CheckStep& checkstep, |
1190 | - uint32_t const flags) { |
1191 | + uint32_t const flags) const { |
1192 | FCoords start; |
1193 | FCoords end; |
1194 | int32_t upper_cost_limit; |
1195 | |
1196 | === modified file 'src/logic/map.h' |
1197 | --- src/logic/map.h 2017-08-12 06:51:08 +0000 |
1198 | +++ src/logic/map.h 2017-08-20 12:33:35 +0000 |
1199 | @@ -181,7 +181,7 @@ |
1200 | const std::string& description = _("No description defined")); |
1201 | |
1202 | void recalc_whole_map(const World& world); |
1203 | - virtual void recalc_for_field_area(const World& world, Area<FCoords>); |
1204 | + void recalc_for_field_area(const World& world, Area<FCoords>); |
1205 | |
1206 | /*** |
1207 | * Ensures that resources match their adjacent terrains. |
1208 | @@ -292,27 +292,27 @@ |
1209 | BaseImmovable* get_immovable(const Coords&) const; |
1210 | uint32_t find_bobs(const Area<FCoords>, |
1211 | std::vector<Bob*>* list, |
1212 | - const FindBob& functor = FindBobAlwaysTrue()); |
1213 | + const FindBob& functor = FindBobAlwaysTrue()) const; |
1214 | uint32_t find_reachable_bobs(const Area<FCoords>, |
1215 | std::vector<Bob*>* list, |
1216 | const CheckStep&, |
1217 | - const FindBob& functor = FindBobAlwaysTrue()); |
1218 | + const FindBob& functor = FindBobAlwaysTrue()) const; |
1219 | uint32_t find_immovables(const Area<FCoords>, |
1220 | std::vector<ImmovableFound>* list, |
1221 | - const FindImmovable& = find_immovable_always_true()); |
1222 | + const FindImmovable& = find_immovable_always_true()) const; |
1223 | uint32_t find_reachable_immovables(const Area<FCoords>, |
1224 | std::vector<ImmovableFound>* list, |
1225 | const CheckStep&, |
1226 | - const FindImmovable& = find_immovable_always_true()); |
1227 | + const FindImmovable& = find_immovable_always_true()) const; |
1228 | uint32_t find_reachable_immovables_unique(const Area<FCoords>, |
1229 | std::vector<BaseImmovable*>& list, |
1230 | const CheckStep&, |
1231 | - const FindImmovable& = find_immovable_always_true()); |
1232 | - uint32_t find_fields(const Area<FCoords>, std::vector<Coords>* list, const FindNode& functor); |
1233 | + const FindImmovable& = find_immovable_always_true()) const; |
1234 | + uint32_t find_fields(const Area<FCoords>, std::vector<Coords>* list, const FindNode& functor) const; |
1235 | uint32_t find_reachable_fields(const Area<FCoords>, |
1236 | std::vector<Coords>* list, |
1237 | const CheckStep&, |
1238 | - const FindNode&); |
1239 | + const FindNode&) const; |
1240 | |
1241 | // Field logic |
1242 | static MapIndex get_index(const Coords&, int16_t width); |
1243 | @@ -370,7 +370,7 @@ |
1244 | const int32_t persist, |
1245 | Path&, |
1246 | const CheckStep&, |
1247 | - const uint32_t flags = 0); |
1248 | + const uint32_t flags = 0) const; |
1249 | |
1250 | /** |
1251 | * We can reach a field by water either if it has MOVECAPS_SWIM or if it has |
1252 | @@ -464,11 +464,31 @@ |
1253 | /// Checks whether there are any artifacts on the map |
1254 | bool has_artifacts(); |
1255 | |
1256 | -protected: /// These functions are needed in Testclasses |
1257 | + // Visible for testing. |
1258 | void set_size(uint32_t w, uint32_t h); |
1259 | |
1260 | private: |
1261 | void recalc_border(const FCoords&); |
1262 | + void recalc_brightness(const FCoords&); |
1263 | + void recalc_nodecaps_pass1(const World& world, const FCoords&); |
1264 | + void recalc_nodecaps_pass2(const World& world, const FCoords& f); |
1265 | + NodeCaps calc_nodecaps_pass1(const World& world, const FCoords&, bool consider_mobs = true); |
1266 | + NodeCaps calc_nodecaps_pass2(const World& world, |
1267 | + const FCoords&, |
1268 | + bool consider_mobs = true, |
1269 | + NodeCaps initcaps = CAPS_NONE); |
1270 | + void check_neighbour_heights(FCoords, uint32_t& radius); |
1271 | + int calc_buildsize(const World& world, |
1272 | + const FCoords& f, |
1273 | + bool avoidnature, |
1274 | + bool* ismine = nullptr, |
1275 | + bool consider_mobs = true, |
1276 | + NodeCaps initcaps = CAPS_NONE); |
1277 | + bool is_cycle_connected(const FCoords& start, uint32_t length, const WalkingDir* dirs); |
1278 | + template <typename functorT> |
1279 | + void find_reachable(const Area<FCoords>&, const CheckStep&, functorT&) const; |
1280 | + template <typename functorT> void find(const Area<FCoords>&, functorT&) const; |
1281 | + |
1282 | |
1283 | /// # of players this map supports (!= Game's number of players!) |
1284 | PlayerNumber nrplayers_; |
1285 | @@ -501,26 +521,6 @@ |
1286 | PortSpacesSet port_spaces_; |
1287 | Objectives objectives_; |
1288 | |
1289 | - void recalc_brightness(const FCoords&); |
1290 | - void recalc_nodecaps_pass1(const World& world, const FCoords&); |
1291 | - void recalc_nodecaps_pass2(const World& world, const FCoords& f); |
1292 | - NodeCaps calc_nodecaps_pass1(const World& world, const FCoords&, bool consider_mobs = true); |
1293 | - NodeCaps calc_nodecaps_pass2(const World& world, |
1294 | - const FCoords&, |
1295 | - bool consider_mobs = true, |
1296 | - NodeCaps initcaps = CAPS_NONE); |
1297 | - void check_neighbour_heights(FCoords, uint32_t& radius); |
1298 | - int calc_buildsize(const World& world, |
1299 | - const FCoords& f, |
1300 | - bool avoidnature, |
1301 | - bool* ismine = nullptr, |
1302 | - bool consider_mobs = true, |
1303 | - NodeCaps initcaps = CAPS_NONE); |
1304 | - bool is_cycle_connected(const FCoords& start, uint32_t length, const WalkingDir* dirs); |
1305 | - template <typename functorT> |
1306 | - void find_reachable(const Area<FCoords>&, const CheckStep&, functorT&); |
1307 | - template <typename functorT> void find(const Area<FCoords>&, functorT&) const; |
1308 | - |
1309 | MapVersion map_version_; |
1310 | }; |
1311 | |
1312 | |
1313 | === modified file 'src/logic/map_objects/bob.cc' |
1314 | --- src/logic/map_objects/bob.cc 2017-06-24 08:47:46 +0000 |
1315 | +++ src/logic/map_objects/bob.cc 2017-08-20 12:33:35 +0000 |
1316 | @@ -464,7 +464,7 @@ |
1317 | |
1318 | Game& game_; |
1319 | Bob& bob_; |
1320 | - Map& map_; |
1321 | + const Map& map_; |
1322 | Coords finaldest_; |
1323 | Cache nodes_; |
1324 | int nrblocked_; |
1325 | @@ -475,13 +475,13 @@ |
1326 | explicit CheckStepBlocked(BlockedTracker& tracker) : tracker_(tracker) { |
1327 | } |
1328 | |
1329 | - bool allowed(Map&, FCoords, FCoords end, int32_t, CheckStep::StepId) const { |
1330 | + bool allowed(const Map&, FCoords, FCoords end, int32_t, CheckStep::StepId) const { |
1331 | if (end == tracker_.finaldest_) |
1332 | return true; |
1333 | |
1334 | return !tracker_.is_blocked(end); |
1335 | } |
1336 | - bool reachable_dest(Map&, FCoords) const { |
1337 | + bool reachable_dest(const Map&, FCoords) const { |
1338 | return true; |
1339 | } |
1340 | |
1341 | @@ -519,7 +519,7 @@ |
1342 | if (forceall) |
1343 | tracker.disabled_ = true; |
1344 | |
1345 | - Map& map = game.map(); |
1346 | + const Map& map = game.map(); |
1347 | if (map.findpath(position_, dest, persist, path, cstep) < 0) { |
1348 | if (!tracker.nrblocked_) |
1349 | return false; |
1350 | @@ -634,8 +634,7 @@ |
1351 | // Using probability of 1/8 and pausing it for 5, 10 or 15 seconds |
1352 | if (game.logic_rand() % 8 == 0) { |
1353 | if (is_a(Ship, this)) { |
1354 | - Map& map = game.map(); |
1355 | - const uint32_t ships_count = map.find_bobs( |
1356 | + const uint32_t ships_count = game.map().find_bobs( |
1357 | Widelands::Area<Widelands::FCoords>(get_position(), 0), nullptr, FindBobShip()); |
1358 | assert(ships_count > 0); |
1359 | if (ships_count > 1) { |
1360 | @@ -694,7 +693,7 @@ |
1361 | Vector2f Bob::calc_drawpos(const EditorGameBase& game, |
1362 | const Vector2f& field_on_dst, |
1363 | const float scale) const { |
1364 | - const Map& map = game.get_map(); |
1365 | + const Map& map = game.map(); |
1366 | const FCoords end = position_; |
1367 | FCoords start; |
1368 | Vector2f spos = field_on_dst; |
1369 | @@ -793,7 +792,7 @@ |
1370 | int32_t Bob::start_walk(Game& game, WalkingDir const dir, uint32_t const a, bool const force) { |
1371 | FCoords newnode; |
1372 | |
1373 | - Map& map = game.map(); |
1374 | + const Map& map = game.map(); |
1375 | map.get_neighbour(position_, dir, &newnode); |
1376 | |
1377 | // Move capability check |
1378 | |
1379 | === modified file 'src/logic/map_objects/checkstep.cc' |
1380 | --- src/logic/map_objects/checkstep.cc 2017-01-25 18:55:59 +0000 |
1381 | +++ src/logic/map_objects/checkstep.cc 2017-08-20 12:33:35 +0000 |
1382 | @@ -34,10 +34,10 @@ |
1383 | } |
1384 | |
1385 | struct CheckStepAlwaysFalse { |
1386 | - bool allowed(Map&, const FCoords&, const FCoords&, int32_t, CheckStep::StepId) const { |
1387 | + bool allowed(const Map&, const FCoords&, const FCoords&, int32_t, CheckStep::StepId) const { |
1388 | return false; |
1389 | } |
1390 | - bool reachable_dest(Map&, const FCoords&) const { |
1391 | + bool reachable_dest(const Map&, const FCoords&) const { |
1392 | return false; |
1393 | } |
1394 | }; |
1395 | @@ -51,7 +51,7 @@ |
1396 | subs.push_back(sub); |
1397 | } |
1398 | |
1399 | -bool CheckStepAnd::allowed(Map& map, |
1400 | +bool CheckStepAnd::allowed(const Map& map, |
1401 | const FCoords& start, |
1402 | const FCoords& end, |
1403 | int32_t const dir, |
1404 | @@ -64,7 +64,7 @@ |
1405 | return true; |
1406 | } |
1407 | |
1408 | -bool CheckStepAnd::reachable_dest(Map& map, const FCoords& dest) const { |
1409 | +bool CheckStepAnd::reachable_dest(const Map& map, const FCoords& dest) const { |
1410 | for (const CheckStep& checkstep : subs) { |
1411 | if (!checkstep.reachable_dest(map, dest)) { |
1412 | return false; |
1413 | @@ -79,7 +79,7 @@ |
1414 | =============== |
1415 | */ |
1416 | bool CheckStepDefault::allowed( |
1417 | - Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId) const { |
1418 | + const Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId) const { |
1419 | NodeCaps const endcaps = end.field->nodecaps(); |
1420 | |
1421 | if (endcaps & movecaps_) |
1422 | @@ -94,7 +94,7 @@ |
1423 | return false; |
1424 | } |
1425 | |
1426 | -bool CheckStepDefault::reachable_dest(Map& map, const FCoords& dest) const { |
1427 | +bool CheckStepDefault::reachable_dest(const Map& map, const FCoords& dest) const { |
1428 | NodeCaps const caps = dest.field->nodecaps(); |
1429 | |
1430 | if (!(caps & movecaps_)) { |
1431 | @@ -114,7 +114,7 @@ |
1432 | =============== |
1433 | */ |
1434 | bool CheckStepWalkOn::allowed( |
1435 | - Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const { |
1436 | + const Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const { |
1437 | NodeCaps const startcaps = start.field->nodecaps(); |
1438 | NodeCaps const endcaps = end.field->nodecaps(); |
1439 | |
1440 | @@ -138,13 +138,13 @@ |
1441 | return false; |
1442 | } |
1443 | |
1444 | -bool CheckStepWalkOn::reachable_dest(Map&, FCoords) const { |
1445 | +bool CheckStepWalkOn::reachable_dest(const Map&, FCoords) const { |
1446 | // Don't bother solving this. |
1447 | return true; |
1448 | } |
1449 | |
1450 | bool CheckStepRoad::allowed( |
1451 | - Map& map, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const { |
1452 | + const Map& map, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const { |
1453 | uint8_t const endcaps = player_.get_buildcaps(end); |
1454 | |
1455 | // Calculate cost and passability |
1456 | @@ -165,7 +165,7 @@ |
1457 | return true; |
1458 | } |
1459 | |
1460 | -bool CheckStepRoad::reachable_dest(Map& map, const FCoords& dest) const { |
1461 | +bool CheckStepRoad::reachable_dest(const Map& map, const FCoords& dest) const { |
1462 | NodeCaps const caps = dest.field->nodecaps(); |
1463 | |
1464 | if (!(caps & movecaps_)) { |
1465 | @@ -180,11 +180,11 @@ |
1466 | } |
1467 | |
1468 | bool CheckStepLimited::allowed( |
1469 | - Map&, const FCoords&, const FCoords& end, int32_t, CheckStep::StepId) const { |
1470 | + const Map&, const FCoords&, const FCoords& end, int32_t, CheckStep::StepId) const { |
1471 | return allowed_locations_.find(end) != allowed_locations_.end(); |
1472 | } |
1473 | |
1474 | -bool CheckStepLimited::reachable_dest(Map&, FCoords) const { |
1475 | +bool CheckStepLimited::reachable_dest(const Map&, FCoords) const { |
1476 | return true; |
1477 | } |
1478 | } |
1479 | |
1480 | === modified file 'src/logic/map_objects/checkstep.h' |
1481 | --- src/logic/map_objects/checkstep.h 2017-08-12 06:51:08 +0000 |
1482 | +++ src/logic/map_objects/checkstep.h 2017-08-20 12:33:35 +0000 |
1483 | @@ -44,21 +44,21 @@ |
1484 | virtual ~BaseCapsule() { |
1485 | } |
1486 | virtual bool |
1487 | - allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, StepId id) const = 0; |
1488 | - virtual bool reachable_dest(Map&, const FCoords& dest) const = 0; |
1489 | + allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, StepId id) const = 0; |
1490 | + virtual bool reachable_dest(const Map&, const FCoords& dest) const = 0; |
1491 | }; |
1492 | template <typename T> struct Capsule : public BaseCapsule { |
1493 | Capsule(const T& init_op) : op(init_op) { |
1494 | } |
1495 | |
1496 | - bool allowed(Map& map, |
1497 | + bool allowed(const Map& map, |
1498 | const FCoords& start, |
1499 | const FCoords& end, |
1500 | int32_t const dir, |
1501 | StepId const id) const override { |
1502 | return op.allowed(map, start, end, dir, id); |
1503 | } |
1504 | - bool reachable_dest(Map& map, const FCoords& dest) const override { |
1505 | + bool reachable_dest(const Map& map, const FCoords& dest) const override { |
1506 | return op.reachable_dest(map, dest); |
1507 | } |
1508 | |
1509 | @@ -79,7 +79,7 @@ |
1510 | * \return \c true true if moving from start to end (single step in the given |
1511 | * direction) is allowed. |
1512 | */ |
1513 | - bool allowed(Map& map, |
1514 | + bool allowed(const Map& map, |
1515 | const FCoords& start, |
1516 | const FCoords& end, |
1517 | int32_t const dir, |
1518 | @@ -91,7 +91,7 @@ |
1519 | * \return \c true if the destination field can be reached at all |
1520 | * (e.g. return false for land-based bobs when dest is in water). |
1521 | */ |
1522 | - bool reachable_dest(Map& map, const FCoords& dest) const { |
1523 | + bool reachable_dest(const Map& map, const FCoords& dest) const { |
1524 | return capsule->reachable_dest(map, dest); |
1525 | } |
1526 | }; |
1527 | @@ -104,8 +104,8 @@ |
1528 | void add(const CheckStep& sub); |
1529 | |
1530 | bool |
1531 | - allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId id) const; |
1532 | - bool reachable_dest(Map&, const FCoords& dest) const; |
1533 | + allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId id) const; |
1534 | + bool reachable_dest(const Map&, const FCoords& dest) const; |
1535 | |
1536 | private: |
1537 | std::vector<CheckStep> subs; |
1538 | @@ -123,8 +123,8 @@ |
1539 | } |
1540 | |
1541 | bool |
1542 | - allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1543 | - bool reachable_dest(Map&, const FCoords& dest) const; |
1544 | + allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1545 | + bool reachable_dest(const Map&, const FCoords& dest) const; |
1546 | |
1547 | private: |
1548 | uint8_t movecaps_; |
1549 | @@ -141,8 +141,8 @@ |
1550 | } |
1551 | |
1552 | bool |
1553 | - allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1554 | - bool reachable_dest(Map&, FCoords dest) const; |
1555 | + allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1556 | + bool reachable_dest(const Map&, FCoords dest) const; |
1557 | |
1558 | private: |
1559 | uint8_t movecaps_; |
1560 | @@ -162,8 +162,8 @@ |
1561 | } |
1562 | |
1563 | bool |
1564 | - allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1565 | - bool reachable_dest(Map&, const FCoords& dest) const; |
1566 | + allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1567 | + bool reachable_dest(const Map&, const FCoords& dest) const; |
1568 | |
1569 | private: |
1570 | const Player& player_; |
1571 | @@ -179,8 +179,8 @@ |
1572 | allowed_locations_.insert(c); |
1573 | } |
1574 | bool |
1575 | - allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1576 | - bool reachable_dest(Map&, FCoords dest) const; |
1577 | + allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const; |
1578 | + bool reachable_dest(const Map&, FCoords dest) const; |
1579 | |
1580 | private: |
1581 | // The ordering of the set does not matter, as long as it is system |
1582 | |
1583 | === modified file 'src/logic/map_objects/immovable.cc' |
1584 | --- src/logic/map_objects/immovable.cc 2017-07-04 11:34:00 +0000 |
1585 | +++ src/logic/map_objects/immovable.cc 2017-08-20 12:33:35 +0000 |
1586 | @@ -100,15 +100,16 @@ |
1587 | void BaseImmovable::set_position(EditorGameBase& egbase, const Coords& c) { |
1588 | assert(c); |
1589 | |
1590 | - Map& map = egbase.map(); |
1591 | - FCoords f = map.get_fcoords(c); |
1592 | + Map* map = egbase.mutable_map(); |
1593 | + FCoords f = map->get_fcoords(c); |
1594 | if (f.field->immovable && f.field->immovable != this) |
1595 | f.field->immovable->remove(egbase); |
1596 | |
1597 | f.field->immovable = this; |
1598 | |
1599 | - if (get_size() >= SMALL) |
1600 | - map.recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2)); |
1601 | + if (get_size() >= SMALL) { |
1602 | + map->recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2)); |
1603 | + } |
1604 | } |
1605 | |
1606 | /** |
1607 | @@ -117,8 +118,8 @@ |
1608 | * Only call this during cleanup. |
1609 | */ |
1610 | void BaseImmovable::unset_position(EditorGameBase& egbase, const Coords& c) { |
1611 | - Map& map = egbase.map(); |
1612 | - FCoords const f = map.get_fcoords(c); |
1613 | + Map* map = egbase.mutable_map(); |
1614 | + FCoords const f = map->get_fcoords(c); |
1615 | |
1616 | // this is to help to debug failing assertion below (see bug 1542238) |
1617 | if (f.field->immovable != this) { |
1618 | @@ -130,10 +131,11 @@ |
1619 | assert(f.field->immovable == this); |
1620 | |
1621 | f.field->immovable = nullptr; |
1622 | - egbase.inform_players_about_immovable(f.field - &map[0], nullptr); |
1623 | + egbase.inform_players_about_immovable(f.field - &(*map)[0], nullptr); |
1624 | |
1625 | - if (get_size() >= SMALL) |
1626 | - map.recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2)); |
1627 | + if (get_size() >= SMALL) { |
1628 | + map->recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2)); |
1629 | + } |
1630 | } |
1631 | |
1632 | /* |
1633 | |
1634 | === modified file 'src/logic/map_objects/tribes/building.cc' |
1635 | --- src/logic/map_objects/tribes/building.cc 2017-08-16 04:31:56 +0000 |
1636 | +++ src/logic/map_objects/tribes/building.cc 2017-08-20 12:33:35 +0000 |
1637 | @@ -329,7 +329,7 @@ |
1638 | PlayerImmovable::init(egbase); |
1639 | |
1640 | // Set the building onto the map |
1641 | - Map& map = egbase.map(); |
1642 | + const Map& map = egbase.map(); |
1643 | Coords neighb; |
1644 | |
1645 | set_position(egbase, position_); |
1646 | @@ -385,7 +385,7 @@ |
1647 | unset_position(egbase, position_); |
1648 | |
1649 | if (get_size() == BIG) { |
1650 | - Map& map = egbase.map(); |
1651 | + const Map& map = egbase.map(); |
1652 | Coords neighb; |
1653 | |
1654 | map.get_ln(position_, &neighb); |
1655 | @@ -421,7 +421,7 @@ |
1656 | |
1657 | rv.push_back(position_); |
1658 | if (get_size() == BIG) { |
1659 | - Map& map = egbase.map(); |
1660 | + const Map& map = egbase.map(); |
1661 | Coords neighb; |
1662 | |
1663 | map.get_ln(position_, &neighb); |
1664 | @@ -727,7 +727,7 @@ |
1665 | return; |
1666 | |
1667 | Player& player = owner(); |
1668 | - Map& map = player.egbase().map(); |
1669 | + const Map& map = player.egbase().map(); |
1670 | |
1671 | if (see) |
1672 | player.see_area(Area<FCoords>(map.get_fcoords(get_position()), descr().vision_range())); |
1673 | |
1674 | === modified file 'src/logic/map_objects/tribes/carrier.cc' |
1675 | --- src/logic/map_objects/tribes/carrier.cc 2017-04-22 06:45:52 +0000 |
1676 | +++ src/logic/map_objects/tribes/carrier.cc 2017-08-20 12:33:35 +0000 |
1677 | @@ -432,7 +432,7 @@ |
1678 | * Find the flag we are closest to (in walking time). |
1679 | */ |
1680 | int32_t Carrier::find_closest_flag(Game& game) { |
1681 | - Map& map = game.map(); |
1682 | + const Map& map = game.map(); |
1683 | CoordPath startpath(map, dynamic_cast<Road&>(*get_location(game)).get_path()); |
1684 | |
1685 | CoordPath endpath; |
1686 | |
1687 | === modified file 'src/logic/map_objects/tribes/militarysite.cc' |
1688 | --- src/logic/map_objects/tribes/militarysite.cc 2017-08-16 13:23:15 +0000 |
1689 | +++ src/logic/map_objects/tribes/militarysite.cc 2017-08-20 12:33:35 +0000 |
1690 | @@ -156,7 +156,7 @@ |
1691 | void MilitarySite::AttackTarget::enemy_soldier_approaches(const Soldier& enemy) const { |
1692 | auto& owner = military_site_->owner(); |
1693 | Game& game = dynamic_cast<Game&>(owner.egbase()); |
1694 | - Map& map = game.map(); |
1695 | + const Map& map = game.map(); |
1696 | if (enemy.get_owner() == &owner || enemy.get_battle() || |
1697 | military_site_->descr().get_conquers() <= |
1698 | map.calc_distance(enemy.get_position(), military_site_->get_position())) |
1699 | |
1700 | === modified file 'src/logic/map_objects/tribes/production_program.cc' |
1701 | --- src/logic/map_objects/tribes/production_program.cc 2017-08-16 04:31:56 +0000 |
1702 | +++ src/logic/map_objects/tribes/production_program.cc 2017-08-20 12:33:35 +0000 |
1703 | @@ -1138,7 +1138,7 @@ |
1704 | } |
1705 | |
1706 | void ProductionProgram::ActMine::execute(Game& game, ProductionSite& ps) const { |
1707 | - Map& map = game.map(); |
1708 | + Map* map = game.mutable_map(); |
1709 | |
1710 | // select one of the nodes randomly |
1711 | uint32_t totalres = 0; |
1712 | @@ -1147,7 +1147,7 @@ |
1713 | |
1714 | { |
1715 | MapRegion<Area<FCoords>> mr( |
1716 | - map, Area<FCoords>(map.get_fcoords(ps.get_position()), distance_)); |
1717 | + *map, Area<FCoords>(map->get_fcoords(ps.get_position()), distance_)); |
1718 | do { |
1719 | DescriptionIndex fres = mr.location().field->get_resources(); |
1720 | ResourceAmount amount = mr.location().field->get_resources_amount(); |
1721 | @@ -1172,7 +1172,7 @@ |
1722 | totalchance += 4; |
1723 | else if (amount <= 6) |
1724 | totalchance += 2; |
1725 | - } while (mr.advance(map)); |
1726 | + } while (mr.advance(*map)); |
1727 | } |
1728 | |
1729 | // how much is digged |
1730 | @@ -1193,7 +1193,7 @@ |
1731 | |
1732 | { |
1733 | MapRegion<Area<FCoords>> mr( |
1734 | - map, Area<FCoords>(map.get_fcoords(ps.get_position()), distance_)); |
1735 | + *map, Area<FCoords>(map->get_fcoords(ps.get_position()), distance_)); |
1736 | do { |
1737 | DescriptionIndex fres = mr.location().field->get_resources(); |
1738 | ResourceAmount amount = mr.location().field->get_resources_amount(); |
1739 | @@ -1206,10 +1206,10 @@ |
1740 | assert(amount > 0); |
1741 | |
1742 | --amount; |
1743 | - map.set_resources(mr.location(), amount); |
1744 | + map->set_resources(mr.location(), amount); |
1745 | break; |
1746 | } |
1747 | - } while (mr.advance(map)); |
1748 | + } while (mr.advance(*map)); |
1749 | } |
1750 | |
1751 | if (pick >= 0) { |
1752 | @@ -1489,10 +1489,11 @@ |
1753 | } |
1754 | |
1755 | // Look for an appropriate object in the given radius |
1756 | + const Map& map = game.map(); |
1757 | std::vector<ImmovableFound> immovables; |
1758 | CheckStepWalkOn cstep(MOVECAPS_WALK, true); |
1759 | - Area<FCoords> area(game.map().get_fcoords(psite.base_flag().get_position()), radius); |
1760 | - if (game.map().find_reachable_immovables( |
1761 | + Area<FCoords> area(map.get_fcoords(psite.base_flag().get_position()), radius); |
1762 | + if (map.find_reachable_immovables( |
1763 | area, &immovables, cstep, FindImmovableByDescr(descr))) { |
1764 | state.objvar = immovables[0].object; |
1765 | |
1766 | @@ -1502,7 +1503,6 @@ |
1767 | |
1768 | // No object found, look for a field where we can build |
1769 | std::vector<Coords> fields; |
1770 | - Map& map = game.map(); |
1771 | FindNodeAnd fna; |
1772 | // 10 is custom value to make sure the "water" is at least 10 nodes big |
1773 | fna.add(FindNodeShore(10)); |
1774 | |
1775 | === modified file 'src/logic/map_objects/tribes/ship.cc' |
1776 | --- src/logic/map_objects/tribes/ship.cc 2017-08-16 14:30:17 +0000 |
1777 | +++ src/logic/map_objects/tribes/ship.cc 2017-08-20 12:33:35 +0000 |
1778 | @@ -288,7 +288,7 @@ |
1779 | |
1780 | /// updates a ships tasks in transport mode \returns false if failed to update tasks |
1781 | bool Ship::ship_update_transport(Game& game, Bob::State& state) { |
1782 | - Map& map = game.map(); |
1783 | + const Map& map = game.map(); |
1784 | |
1785 | PortDock* dst = get_destination(game); |
1786 | if (!dst) { |
1787 | @@ -366,7 +366,7 @@ |
1788 | |
1789 | /// updates a ships tasks in expedition mode |
1790 | void Ship::ship_update_expedition(Game& game, Bob::State&) { |
1791 | - Map& map = game.map(); |
1792 | + Map* map = game.mutable_map(); |
1793 | |
1794 | assert(expedition_); |
1795 | |
1796 | @@ -374,29 +374,29 @@ |
1797 | FCoords position = get_position(); |
1798 | for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) { |
1799 | expedition_->swimmable[dir - 1] = |
1800 | - map.get_neighbour(position, dir).field->nodecaps() & MOVECAPS_SWIM; |
1801 | + map->get_neighbour(position, dir).field->nodecaps() & MOVECAPS_SWIM; |
1802 | } |
1803 | |
1804 | if (ship_state_ == ShipStates::kExpeditionScouting) { |
1805 | // Check surrounding fields for port buildspaces |
1806 | std::vector<Coords> temp_port_buildspaces; |
1807 | - MapRegion<Area<Coords>> mr(map, Area<Coords>(position, descr().vision_range())); |
1808 | + MapRegion<Area<Coords>> mr(*map, Area<Coords>(position, descr().vision_range())); |
1809 | bool new_port_space = false; |
1810 | do { |
1811 | - if (!map.is_port_space(mr.location())) { |
1812 | + if (!map->is_port_space(mr.location())) { |
1813 | continue; |
1814 | } |
1815 | |
1816 | - const FCoords fc = map.get_fcoords(mr.location()); |
1817 | + const FCoords fc = map->get_fcoords(mr.location()); |
1818 | |
1819 | // Check whether the maximum theoretical possible NodeCap of the field |
1820 | // is of the size big and whether it can theoretically be a port space |
1821 | - if ((map.get_max_nodecaps(game.world(), fc) & BUILDCAPS_SIZEMASK) != BUILDCAPS_BIG || |
1822 | - map.find_portdock(fc).empty()) { |
1823 | + if ((map->get_max_nodecaps(game.world(), fc) & BUILDCAPS_SIZEMASK) != BUILDCAPS_BIG || |
1824 | + map->find_portdock(fc).empty()) { |
1825 | continue; |
1826 | } |
1827 | |
1828 | - if (!can_build_port_here(get_owner()->player_number(), map, fc)) { |
1829 | + if (!can_build_port_here(get_owner()->player_number(), *map, fc)) { |
1830 | continue; |
1831 | } |
1832 | |
1833 | @@ -409,7 +409,7 @@ |
1834 | new_port_space = true; |
1835 | temp_port_buildspaces.insert(temp_port_buildspaces.begin(), mr.location()); |
1836 | } |
1837 | - } while (mr.advance(map)); |
1838 | + } while (mr.advance(*map)); |
1839 | |
1840 | if (new_port_space) { |
1841 | ship_state_ = ShipStates::kExpeditionPortspaceFound; |
1842 | @@ -438,10 +438,10 @@ |
1843 | |
1844 | // If we are waiting for the next transport job, check if we should move away from ships and |
1845 | // shores |
1846 | + const Map& map = game.map(); |
1847 | switch (ship_state_) { |
1848 | case ShipStates::kTransport: { |
1849 | FCoords position = get_position(); |
1850 | - Map& map = game.map(); |
1851 | unsigned int dirs[LAST_DIRECTION + 1]; |
1852 | unsigned int dirmax = 0; |
1853 | |
1854 | @@ -569,7 +569,6 @@ |
1855 | // Most likely the command was send as the ship was on an exploration and just leaving |
1856 | // the island - therefore we try to find the island again. |
1857 | FCoords position = get_position(); |
1858 | - Map& map = game.map(); |
1859 | for (uint8_t dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) { |
1860 | FCoords neighbour = map.get_neighbour(position, dir); |
1861 | for (uint8_t sur = FIRST_DIRECTION; sur <= LAST_DIRECTION; ++sur) |
1862 | @@ -612,7 +611,7 @@ |
1863 | } |
1864 | case ShipStates::kExpeditionColonizing: { |
1865 | assert(!expedition_->seen_port_buildspaces.empty()); |
1866 | - BaseImmovable* baim = game.map()[expedition_->seen_port_buildspaces.front()].get_immovable(); |
1867 | + BaseImmovable* baim = map[expedition_->seen_port_buildspaces.front()].get_immovable(); |
1868 | if (baim) { |
1869 | upcast(ConstructionSite, cs, baim); |
1870 | |
1871 | @@ -742,13 +741,13 @@ |
1872 | * Find a path to the dock @p pd, returns its length, and the path optionally. |
1873 | */ |
1874 | uint32_t Ship::calculate_sea_route(Game& game, PortDock& pd, Path* finalpath) const { |
1875 | - Map& map = game.map(); |
1876 | + Map* map = game.mutable_map(); |
1877 | StepEvalAStar se(pd.get_warehouse()->get_position()); |
1878 | se.swim_ = true; |
1879 | se.conservative_ = false; |
1880 | - se.estimator_bias_ = -5 * map.calc_cost(0); |
1881 | + se.estimator_bias_ = -5 * map->calc_cost(0); |
1882 | |
1883 | - MapAStar<StepEvalAStar> astar(map, se); |
1884 | + MapAStar<StepEvalAStar> astar(*map, se); |
1885 | |
1886 | astar.push(get_position()); |
1887 | |
1888 | |
1889 | === modified file 'src/logic/map_objects/tribes/soldier.cc' |
1890 | --- src/logic/map_objects/tribes/soldier.cc 2017-07-05 19:21:57 +0000 |
1891 | +++ src/logic/map_objects/tribes/soldier.cc 2017-08-20 12:33:35 +0000 |
1892 | @@ -735,6 +735,7 @@ |
1893 | upcast(Building, enemy, state.objvar1.get(game)); |
1894 | |
1895 | // Handle returns |
1896 | + const Map& map = game.map(); |
1897 | if (state.ivar2 > 0) { |
1898 | if (state.ivar2 == 1) { |
1899 | // Return home |
1900 | @@ -774,7 +775,7 @@ |
1901 | } |
1902 | if (state.ivar2 == 2) { |
1903 | // No more home, so return to homeland |
1904 | - upcast(Flag, flag, game.map().get_immovable(get_position())); |
1905 | + upcast(Flag, flag, map.get_immovable(get_position())); |
1906 | if (flag && flag->get_owner() == get_owner()) { |
1907 | // At a flag |
1908 | molog("[attack] Returned to own flag\n"); |
1909 | @@ -793,11 +794,10 @@ |
1910 | return pop_task(game); |
1911 | } |
1912 | // Try to find our land |
1913 | - Map* map = game.get_map(); |
1914 | std::vector<Coords> coords; |
1915 | uint32_t maxdist = descr().vision_range() * 2; |
1916 | - Area<FCoords> area(map->get_fcoords(get_position()), maxdist); |
1917 | - if (map->find_reachable_fields(area, &coords, CheckStepDefault(descr().movecaps()), |
1918 | + Area<FCoords> area(map.get_fcoords(get_position()), maxdist); |
1919 | + if (map.find_reachable_fields(area, &coords, CheckStepDefault(descr().movecaps()), |
1920 | FindNodeOwned(get_owner()->player_number()))) { |
1921 | // Found home land |
1922 | target = coords.front(); |
1923 | @@ -842,8 +842,8 @@ |
1924 | } |
1925 | // Any enemy soldier at baseflag count as defender. |
1926 | std::vector<Bob*> soldiers; |
1927 | - game.map().find_bobs( |
1928 | - Area<FCoords>(game.map().get_fcoords(enemy->base_flag().get_position()), 0), &soldiers, |
1929 | + map.find_bobs( |
1930 | + Area<FCoords>(map.get_fcoords(enemy->base_flag().get_position()), 0), &soldiers, |
1931 | FindBobEnemySoldier(get_owner())); |
1932 | defenders += soldiers.size(); |
1933 | } |
1934 | @@ -862,7 +862,7 @@ |
1935 | // valid anymore, we either "conquered" the new building, or it was |
1936 | // destroyed. |
1937 | if (state.coords) { |
1938 | - BaseImmovable* const newimm = game.map()[state.coords].get_immovable(); |
1939 | + BaseImmovable* const newimm = map[state.coords].get_immovable(); |
1940 | upcast(MilitarySite, newsite, newimm); |
1941 | if (newsite && (&newsite->owner() == &owner())) { |
1942 | const SoldierControl* soldier_control = newsite->soldier_control(); |
1943 | @@ -1182,7 +1182,7 @@ |
1944 | throw GameDataError("bad direction '%d'", dir); |
1945 | } |
1946 | |
1947 | - Map& map = game.map(); |
1948 | + const Map& map = game.map(); |
1949 | int32_t const tdelta = (map.calc_cost(get_position(), mapdir)) / 2; |
1950 | molog("[move_in_battle] dir: (%d) tdelta: (%d)\n", dir, tdelta); |
1951 | combat_walking_ = dir; |
1952 | @@ -1275,7 +1275,7 @@ |
1953 | return pop_task(game); |
1954 | } |
1955 | |
1956 | - Map& map = game.map(); |
1957 | + const Map& map = game.map(); |
1958 | Soldier& opponent = *battle_->opponent(*this); |
1959 | if (opponent.get_position() != get_position()) { |
1960 | if (is_a(Building, map[get_position()].get_immovable())) { |
1961 | |
1962 | === modified file 'src/logic/map_objects/tribes/warehouse.cc' |
1963 | --- src/logic/map_objects/tribes/warehouse.cc 2017-07-01 15:36:36 +0000 |
1964 | +++ src/logic/map_objects/tribes/warehouse.cc 2017-08-20 12:33:35 +0000 |
1965 | @@ -80,13 +80,13 @@ |
1966 | |
1967 | Player& owner = warehouse_->owner(); |
1968 | Game& game = dynamic_cast<Game&>(owner.egbase()); |
1969 | - Map& map = game.map(); |
1970 | + const Map& map = game.map(); |
1971 | if (enemy.get_owner() == &owner || enemy.get_battle() || |
1972 | warehouse_->descr().get_conquers() <= |
1973 | map.calc_distance(enemy.get_position(), warehouse_->get_position())) |
1974 | return; |
1975 | |
1976 | - if (game.map().find_bobs( |
1977 | + if (map.find_bobs( |
1978 | Area<FCoords>(map.get_fcoords(warehouse_->base_flag().get_position()), 2), nullptr, |
1979 | FindBobEnemySoldier(&owner))) |
1980 | return; |
1981 | @@ -581,8 +581,7 @@ |
1982 | void Warehouse::init_portdock(EditorGameBase& egbase) { |
1983 | molog("Setting up port dock fields\n"); |
1984 | |
1985 | - Map& map = egbase.map(); |
1986 | - std::vector<Coords> dock = map.find_portdock(get_position()); |
1987 | + std::vector<Coords> dock = egbase.map().find_portdock(get_position()); |
1988 | if (dock.empty()) { |
1989 | log("Attempting to setup port without neighboring water (coords: %3dx%3d).\n", |
1990 | get_position().x, get_position().y); |
1991 | @@ -670,7 +669,7 @@ |
1992 | planned_workers_.pop_back(); |
1993 | } |
1994 | |
1995 | - Map& map = egbase.map(); |
1996 | + const Map& map = egbase.map(); |
1997 | if (const uint32_t conquer_radius = descr().get_conquers()) |
1998 | egbase.unconquer_area( |
1999 | PlayerArea<Area<FCoords>>(owner().player_number(), |
2000 | |
2001 | === modified file 'src/logic/map_objects/tribes/worker.cc' |
2002 | --- src/logic/map_objects/tribes/worker.cc 2017-07-07 11:19:07 +0000 |
2003 | +++ src/logic/map_objects/tribes/worker.cc 2017-08-20 12:33:35 +0000 |
2004 | @@ -106,7 +106,7 @@ |
2005 | */ |
2006 | // TODO(unknown): Lots of magic numbers in here |
2007 | bool Worker::run_mine(Game& game, State& state, const Action& action) { |
2008 | - Map& map = game.map(); |
2009 | + Map* map = game.mutable_map(); |
2010 | |
2011 | // Make sure that the specified resource is available in this world |
2012 | DescriptionIndex const res = game.world().get_resource(action.sparam1.c_str()); |
2013 | @@ -119,7 +119,7 @@ |
2014 | uint32_t totalres = 0; |
2015 | uint32_t totalchance = 0; |
2016 | int32_t pick; |
2017 | - MapRegion<Area<FCoords>> mr(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1)); |
2018 | + MapRegion<Area<FCoords>> mr(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1)); |
2019 | do { |
2020 | DescriptionIndex fres = mr.location().field->get_resources(); |
2021 | ResourceAmount amount = mr.location().field->get_resources_amount(); |
2022 | @@ -143,7 +143,7 @@ |
2023 | totalchance += 4; |
2024 | else if (amount <= 6) |
2025 | totalchance += 2; |
2026 | - } while (mr.advance(map)); |
2027 | + } while (mr.advance(*map)); |
2028 | |
2029 | if (totalres == 0) { |
2030 | molog(" Run out of resources\n"); |
2031 | @@ -155,7 +155,7 @@ |
2032 | // Second pass through fields - reset mr |
2033 | pick = game.logic_rand() % totalchance; |
2034 | mr = |
2035 | - MapRegion<Area<FCoords>>(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1)); |
2036 | + MapRegion<Area<FCoords>>(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1)); |
2037 | do { |
2038 | DescriptionIndex fres = mr.location().field->get_resources(); |
2039 | if (fres != res) { |
2040 | @@ -169,10 +169,10 @@ |
2041 | assert(amount > 0); |
2042 | |
2043 | --amount; |
2044 | - map.set_resources(mr.location(), amount); |
2045 | + map->set_resources(mr.location(), amount); |
2046 | break; |
2047 | } |
2048 | - } while (mr.advance(map)); |
2049 | + } while (mr.advance(*map)); |
2050 | |
2051 | if (pick >= 0) { |
2052 | molog(" Not successful this time\n"); |
2053 | @@ -206,7 +206,7 @@ |
2054 | bool Worker::run_breed(Game& game, State& state, const Action& action) { |
2055 | molog(" Breed(%s, %i)\n", action.sparam1.c_str(), action.iparam1); |
2056 | |
2057 | - Map& map = game.map(); |
2058 | + Map* map = game.mutable_map(); |
2059 | |
2060 | // Make sure that the specified resource is available in this world |
2061 | DescriptionIndex const res = game.world().get_resource(action.sparam1.c_str()); |
2062 | @@ -219,7 +219,7 @@ |
2063 | uint32_t totalres = 0; |
2064 | uint32_t totalchance = 0; |
2065 | int32_t pick; |
2066 | - MapRegion<Area<FCoords>> mr(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1)); |
2067 | + MapRegion<Area<FCoords>> mr(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1)); |
2068 | do { |
2069 | DescriptionIndex fres = mr.location().field->get_resources(); |
2070 | ResourceAmount amount = mr.location().field->get_initial_res_amount() - |
2071 | @@ -244,7 +244,7 @@ |
2072 | totalchance += 4; |
2073 | else if (amount <= 6) |
2074 | totalchance += 2; |
2075 | - } while (mr.advance(map)); |
2076 | + } while (mr.advance(*map)); |
2077 | |
2078 | if (totalres == 0) { |
2079 | molog(" All resources full\n"); |
2080 | @@ -257,7 +257,7 @@ |
2081 | assert(totalchance); |
2082 | pick = game.logic_rand() % totalchance; |
2083 | mr = |
2084 | - MapRegion<Area<FCoords>>(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1)); |
2085 | + MapRegion<Area<FCoords>>(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1)); |
2086 | |
2087 | do { |
2088 | DescriptionIndex fres = mr.location().field->get_resources(); |
2089 | @@ -272,10 +272,10 @@ |
2090 | assert(amount > 0); |
2091 | |
2092 | --amount; |
2093 | - map.set_resources(mr.location(), mr.location().field->get_initial_res_amount() - amount); |
2094 | + map->set_resources(mr.location(), mr.location().field->get_initial_res_amount() - amount); |
2095 | break; |
2096 | } |
2097 | - } while (mr.advance(map)); |
2098 | + } while (mr.advance(*map)); |
2099 | |
2100 | if (pick >= 0) { |
2101 | molog(" Not successful this time\n"); |
2102 | @@ -341,7 +341,7 @@ |
2103 | bool Worker::run_findobject(Game& game, State& state, const Action& action) { |
2104 | CheckStepWalkOn cstep(descr().movecaps(), false); |
2105 | |
2106 | - Map& map = game.map(); |
2107 | + const Map& map = game.map(); |
2108 | Area<FCoords> area(map.get_fcoords(get_position()), 0); |
2109 | bool found_reserved = false; |
2110 | |
2111 | @@ -486,7 +486,7 @@ |
2112 | |
2113 | bool Worker::run_findspace(Game& game, State& state, const Action& action) { |
2114 | std::vector<Coords> list; |
2115 | - Map& map = game.map(); |
2116 | + const Map& map = game.map(); |
2117 | const World& world = game.world(); |
2118 | |
2119 | CheckStepDefault cstep(descr().movecaps()); |
2120 | @@ -706,7 +706,7 @@ |
2121 | } |
2122 | } |
2123 | |
2124 | - Map& map = game.map(); |
2125 | + const Map& map = game.map(); |
2126 | Coords pos = get_position(); |
2127 | FCoords fpos = map.get_fcoords(pos); |
2128 | |
2129 | @@ -863,8 +863,7 @@ |
2130 | * possible. |
2131 | */ |
2132 | bool Worker::run_geologist_find(Game& game, State& state, const Action&) { |
2133 | - const Map& map = game.map(); |
2134 | - const FCoords position = map.get_fcoords(get_position()); |
2135 | + const FCoords position = game.map().get_fcoords(get_position()); |
2136 | BaseImmovable const* const imm = position.field->get_immovable(); |
2137 | const World& world = game.world(); |
2138 | |
2139 | @@ -1285,7 +1284,7 @@ |
2140 | } |
2141 | |
2142 | void Worker::transfer_update(Game& game, State& /* state */) { |
2143 | - Map& map = game.map(); |
2144 | + const Map& map = game.map(); |
2145 | PlayerImmovable* location = get_location(game); |
2146 | |
2147 | // We expect to always have a location at this point, |
2148 | @@ -2235,7 +2234,7 @@ |
2149 | return pop_task(game); |
2150 | } |
2151 | |
2152 | - Map& map = game.map(); |
2153 | + const Map& map = game.map(); |
2154 | PlayerImmovable const* location = get_location(game); |
2155 | |
2156 | if (location && &location->owner() == &owner()) { |
2157 | @@ -2354,7 +2353,7 @@ |
2158 | } |
2159 | |
2160 | // |
2161 | - Map& map = game.map(); |
2162 | + const Map& map = game.map(); |
2163 | const World& world = game.world(); |
2164 | Area<FCoords> owner_area( |
2165 | map.get_fcoords(dynamic_cast<Flag&>(*get_location(game)).get_position()), state.ivar2); |
2166 | @@ -2482,7 +2481,7 @@ |
2167 | return pop_task(game); |
2168 | } |
2169 | |
2170 | - Map& map = game.map(); |
2171 | + const Map& map = game.map(); |
2172 | |
2173 | // If not yet time to go home |
2174 | if (static_cast<int32_t>(state.ivar2 - game.get_gametime()) > 0) { |
2175 | |
2176 | === modified file 'src/logic/player.cc' |
2177 | --- src/logic/player.cc 2017-08-16 04:31:56 +0000 |
2178 | +++ src/logic/player.cc 2017-08-20 12:33:35 +0000 |
2179 | @@ -60,7 +60,7 @@ |
2180 | const Widelands::PlayerNumber player_number, |
2181 | const Widelands::Coords& location, |
2182 | const Widelands::BuildingDescr* descr) { |
2183 | - Widelands::Map& map = egbase.map(); |
2184 | + const Widelands::Map& map = egbase.map(); |
2185 | Widelands::FCoords c[4]; // Big buildings occupy 4 locations. |
2186 | c[0] = map.get_fcoords(location); |
2187 | map.get_brn(c[0], &c[1]); |
2188 | @@ -412,7 +412,7 @@ |
2189 | =============== |
2190 | */ |
2191 | Road* Player::build_road(const Path& path) { |
2192 | - Map& map = egbase().map(); |
2193 | + const Map& map = egbase().map(); |
2194 | FCoords fc = map.get_fcoords(path.get_start()); |
2195 | if (upcast(Flag, start, fc.field->get_immovable())) { |
2196 | if (upcast(Flag, end, map.get_immovable(path.get_end()))) { |
2197 | @@ -441,7 +441,7 @@ |
2198 | } |
2199 | |
2200 | Road& Player::force_road(const Path& path) { |
2201 | - Map& map = egbase().map(); |
2202 | + const Map& map = egbase().map(); |
2203 | FCoords c = map.get_fcoords(path.get_start()); |
2204 | Flag& start = force_flag(c); |
2205 | Flag& end = force_flag(map.get_fcoords(path.get_end())); |
2206 | @@ -466,7 +466,7 @@ |
2207 | |
2208 | Building& Player::force_building(Coords const location, |
2209 | const BuildingDescr::FormerBuildings& former_buildings) { |
2210 | - Map& map = egbase().map(); |
2211 | + const Map& map = egbase().map(); |
2212 | DescriptionIndex idx = former_buildings.back(); |
2213 | const BuildingDescr* descr = egbase().tribes().get_building_descr(idx); |
2214 | terraform_for_building(egbase(), player_number(), location, descr); |
2215 | @@ -481,7 +481,7 @@ |
2216 | DescriptionIndex b_idx, |
2217 | const BuildingDescr::FormerBuildings& former_buildings) { |
2218 | EditorGameBase& eg = egbase(); |
2219 | - Map& map = eg.map(); |
2220 | + const Map& map = eg.map(); |
2221 | const Tribes& tribes = eg.tribes(); |
2222 | const PlayerNumber pn = player_number(); |
2223 | |
2224 | @@ -833,7 +833,7 @@ |
2225 | if (soldiers) |
2226 | soldiers->clear(); |
2227 | |
2228 | - Map& map = egbase().map(); |
2229 | + const Map& map = egbase().map(); |
2230 | std::vector<BaseImmovable*> flags; |
2231 | |
2232 | map.find_reachable_immovables_unique(Area<FCoords>(map.get_fcoords(flag.get_position()), 25), |
2233 | |
2234 | === modified file 'src/logic/replay_game_controller.cc' |
2235 | --- src/logic/replay_game_controller.cc 2017-06-24 10:38:19 +0000 |
2236 | +++ src/logic/replay_game_controller.cc 2017-08-20 12:33:35 +0000 |
2237 | @@ -31,9 +31,6 @@ |
2238 | speed_(1000), |
2239 | paused_(false) { |
2240 | game_.set_game_controller(this); |
2241 | - |
2242 | - // We have to create an empty map, otherwise nothing will load properly |
2243 | - game.set_map(new Widelands::Map); |
2244 | replayreader_.reset(new Widelands::ReplayReader(game_, filename)); |
2245 | } |
2246 | |
2247 | |
2248 | === modified file 'src/map_io/map_bob_packet.cc' |
2249 | --- src/map_io/map_bob_packet.cc 2017-01-25 18:55:59 +0000 |
2250 | +++ src/map_io/map_bob_packet.cc 2017-08-20 12:33:35 +0000 |
2251 | @@ -75,13 +75,13 @@ |
2252 | FileRead fr; |
2253 | fr.open(fs, "binary/bob"); |
2254 | |
2255 | - Map& map = egbase.map(); |
2256 | - map.recalc_whole_map(egbase.world()); // for movecaps checks in ReadBob |
2257 | + Map* map = egbase.mutable_map(); |
2258 | + map->recalc_whole_map(egbase.world()); // for movecaps checks in ReadBob |
2259 | try { |
2260 | uint16_t const packet_version = fr.unsigned_16(); |
2261 | if (packet_version == kCurrentPacketVersion) |
2262 | - for (uint16_t y = 0; y < map.get_height(); ++y) { |
2263 | - for (uint16_t x = 0; x < map.get_width(); ++x) { |
2264 | + for (uint16_t y = 0; y < map->get_height(); ++y) { |
2265 | + for (uint16_t x = 0; x < map->get_width(); ++x) { |
2266 | uint32_t const nr_bobs = fr.unsigned_32(); |
2267 | for (uint32_t i = 0; i < nr_bobs; ++i) |
2268 | read_bob(fr, egbase, mol, Coords(x, y), lookup_table); |
2269 | |
2270 | === modified file 'src/map_io/map_building_packet.cc' |
2271 | --- src/map_io/map_building_packet.cc 2017-01-25 18:55:59 +0000 |
2272 | +++ src/map_io/map_building_packet.cc 2017-08-20 12:33:35 +0000 |
2273 | @@ -60,7 +60,7 @@ |
2274 | try { |
2275 | uint16_t const packet_version = fr.unsigned_16(); |
2276 | if (packet_version == kCurrentPacketVersion) { |
2277 | - Map& map = egbase.map(); |
2278 | + const Map& map = egbase.map(); |
2279 | uint16_t const width = map.get_width(); |
2280 | uint16_t const height = map.get_height(); |
2281 | FCoords c; |
2282 | |
2283 | === modified file 'src/map_io/map_buildingdata_packet.cc' |
2284 | --- src/map_io/map_buildingdata_packet.cc 2017-08-16 13:23:15 +0000 |
2285 | +++ src/map_io/map_buildingdata_packet.cc 2017-08-20 12:33:35 +0000 |
2286 | @@ -434,9 +434,10 @@ |
2287 | } |
2288 | } |
2289 | |
2290 | + const Map& map = game.map(); |
2291 | + |
2292 | if (uint32_t const conquer_radius = warehouse.descr().get_conquers()) { |
2293 | // Add to map of military influence. |
2294 | - const Map& map = game.map(); |
2295 | Area<FCoords> a(map.get_fcoords(warehouse.get_position()), conquer_radius); |
2296 | const Field& first_map_field = map[0]; |
2297 | Player::Field* const player_fields = player.fields_; |
2298 | @@ -447,7 +448,7 @@ |
2299 | while (mr.advance(map)); |
2300 | } |
2301 | player.see_area(Area<FCoords>( |
2302 | - game.map().get_fcoords(warehouse.get_position()), warehouse.descr().vision_range())); |
2303 | + map.get_fcoords(warehouse.get_position()), warehouse.descr().vision_range())); |
2304 | warehouse.next_military_act_ = game.get_gametime(); |
2305 | } else { |
2306 | throw UnhandledVersionError( |
2307 | @@ -830,7 +831,7 @@ |
2308 | fw.unsigned_16(kCurrentPacketVersion); |
2309 | |
2310 | // Walk the map again |
2311 | - Map& map = egbase.map(); |
2312 | + const Map& map = egbase.map(); |
2313 | const uint32_t mapwidth = map.get_width(); |
2314 | MapIndex const max_index = map.max_index(); |
2315 | for (MapIndex i = 0; i < max_index; ++i) { |
2316 | |
2317 | === modified file 'src/map_io/map_elemental_packet.cc' |
2318 | --- src/map_io/map_elemental_packet.cc 2017-08-16 13:23:15 +0000 |
2319 | +++ src/map_io/map_elemental_packet.cc 2017-08-20 12:33:35 +0000 |
2320 | @@ -114,7 +114,7 @@ |
2321 | } |
2322 | |
2323 | void MapElementalPacket::read(FileSystem& fs, EditorGameBase& egbase, bool, MapObjectLoader&) { |
2324 | - pre_read(fs, &egbase.map()); |
2325 | + pre_read(fs, egbase.mutable_map()); |
2326 | } |
2327 | |
2328 | void MapElementalPacket::write(FileSystem& fs, EditorGameBase& egbase, MapObjectSaver&) { |
2329 | |
2330 | === modified file 'src/map_io/map_exploration_packet.cc' |
2331 | --- src/map_io/map_exploration_packet.cc 2017-01-25 18:55:59 +0000 |
2332 | +++ src/map_io/map_exploration_packet.cc 2017-08-20 12:33:35 +0000 |
2333 | @@ -50,7 +50,7 @@ |
2334 | } |
2335 | |
2336 | static_assert(kMaxPlayers < 32, "assert(MAX_PLAYERS < 32) failed."); |
2337 | - Map& map = egbase.map(); |
2338 | + const Map& map = egbase.map(); |
2339 | PlayerNumber const nr_players = map.get_nrplayers(); |
2340 | MapIndex const max_index = map.max_index(); |
2341 | try { |
2342 | @@ -82,7 +82,7 @@ |
2343 | fw.unsigned_16(kCurrentPacketVersion); |
2344 | |
2345 | static_assert(kMaxPlayers < 32, "assert(MAX_PLAYERS < 32) failed."); |
2346 | - Map& map = egbase.map(); |
2347 | + const Map& map = egbase.map(); |
2348 | PlayerNumber const nr_players = map.get_nrplayers(); |
2349 | MapIndex const max_index = map.max_index(); |
2350 | for (MapIndex i = 0; i < max_index; ++i) { |
2351 | |
2352 | === modified file 'src/map_io/map_heights_packet.cc' |
2353 | --- src/map_io/map_heights_packet.cc 2017-01-25 18:55:59 +0000 |
2354 | +++ src/map_io/map_heights_packet.cc 2017-08-20 12:33:35 +0000 |
2355 | @@ -38,7 +38,7 @@ |
2356 | try { |
2357 | uint16_t const packet_version = fr.unsigned_16(); |
2358 | if (packet_version == kCurrentPacketVersion) { |
2359 | - Map& map = egbase.map(); |
2360 | + const Map& map = egbase.map(); |
2361 | MapIndex const max_index = map.max_index(); |
2362 | for (MapIndex i = 0; i < max_index; ++i) |
2363 | map[i].set_height(fr.unsigned_8()); |
2364 | @@ -60,7 +60,7 @@ |
2365 | |
2366 | fw.unsigned_16(kCurrentPacketVersion); |
2367 | |
2368 | - Map& map = egbase.map(); |
2369 | + const Map& map = egbase.map(); |
2370 | MapIndex const max_index = map.max_index(); |
2371 | for (MapIndex i = 0; i < max_index; ++i) |
2372 | fw.unsigned_8(map[i].get_height()); |
2373 | |
2374 | === modified file 'src/map_io/map_node_ownership_packet.cc' |
2375 | --- src/map_io/map_node_ownership_packet.cc 2017-01-25 18:55:59 +0000 |
2376 | +++ src/map_io/map_node_ownership_packet.cc 2017-08-20 12:33:35 +0000 |
2377 | @@ -51,7 +51,7 @@ |
2378 | try { |
2379 | uint16_t const packet_version = fr.unsigned_16(); |
2380 | if (packet_version == kCurrentPacketVersion) { |
2381 | - Map& map = egbase.map(); |
2382 | + const Map& map = egbase.map(); |
2383 | MapIndex const max_index = map.max_index(); |
2384 | for (MapIndex i = 0; i < max_index; ++i) |
2385 | map[i].set_owned_by(fr.unsigned_8()); |
2386 | @@ -69,7 +69,7 @@ |
2387 | |
2388 | fw.unsigned_16(kCurrentPacketVersion); |
2389 | |
2390 | - Map& map = egbase.map(); |
2391 | + const Map& map = egbase.map(); |
2392 | MapIndex const max_index = map.max_index(); |
2393 | for (MapIndex i = 0; i < max_index; ++i) |
2394 | fw.unsigned_8(map[i].get_owned_by()); |
2395 | |
2396 | === modified file 'src/map_io/map_objective_packet.cc' |
2397 | --- src/map_io/map_objective_packet.cc 2017-01-25 18:55:59 +0000 |
2398 | +++ src/map_io/map_objective_packet.cc 2017-08-20 12:33:35 +0000 |
2399 | @@ -45,7 +45,7 @@ |
2400 | char const* const name = s->get_name(); |
2401 | try { |
2402 | std::unique_ptr<Objective> objective(new Objective(name)); |
2403 | - Map::Objectives* objectives = egbase.map().mutable_objectives(); |
2404 | + Map::Objectives* objectives = egbase.mutable_map()->mutable_objectives(); |
2405 | if (objectives->count(name)) { |
2406 | throw GameDataError("duplicated"); |
2407 | } |
2408 | |
2409 | === modified file 'src/map_io/map_player_names_and_tribes_packet.cc' |
2410 | --- src/map_io/map_player_names_and_tribes_packet.cc 2017-01-25 18:55:59 +0000 |
2411 | +++ src/map_io/map_player_names_and_tribes_packet.cc 2017-08-20 12:33:35 +0000 |
2412 | @@ -44,7 +44,7 @@ |
2413 | EditorGameBase& egbase, |
2414 | bool const skip, |
2415 | MapObjectLoader&) { |
2416 | - pre_read(fs, egbase.get_map(), skip); |
2417 | + pre_read(fs, egbase.mutable_map(), skip); |
2418 | } |
2419 | |
2420 | void MapPlayerNamesAndTribesPacket::pre_read(FileSystem& fs, Map* const map, bool const skip) { |
2421 | |
2422 | === modified file 'src/map_io/map_player_position_packet.cc' |
2423 | --- src/map_io/map_player_position_packet.cc 2017-01-25 18:55:59 +0000 |
2424 | +++ src/map_io/map_player_position_packet.cc 2017-08-20 12:33:35 +0000 |
2425 | @@ -42,12 +42,12 @@ |
2426 | // Read all the positions |
2427 | // This could bring trouble if one player position/ is not set (this |
2428 | // is possible in the editor), is also -1, -1. |
2429 | - Map& map = egbase.map(); |
2430 | - Extent const extent = map.extent(); |
2431 | - PlayerNumber const nr_players = map.get_nrplayers(); |
2432 | + Map* map = egbase.mutable_map(); |
2433 | + Extent const extent = map->extent(); |
2434 | + PlayerNumber const nr_players = map->get_nrplayers(); |
2435 | iterate_player_numbers(p, nr_players) { |
2436 | try { |
2437 | - map.set_starting_pos( |
2438 | + map->set_starting_pos( |
2439 | p, |
2440 | get_safe_coords((boost::format("player_%u") % static_cast<unsigned int>(p)).str(), |
2441 | extent, &s)); |
2442 | |
2443 | === modified file 'src/map_io/map_port_spaces_packet.cc' |
2444 | --- src/map_io/map_port_spaces_packet.cc 2017-01-25 18:55:59 +0000 |
2445 | +++ src/map_io/map_port_spaces_packet.cc 2017-08-20 12:33:35 +0000 |
2446 | @@ -39,8 +39,8 @@ |
2447 | prof.read("port_spaces", nullptr, fs); |
2448 | Section& s1 = prof.get_safe_section("global"); |
2449 | |
2450 | - Map& map = egbase.map(); |
2451 | - Extent ext(map.extent()); |
2452 | + Map* map = egbase.mutable_map(); |
2453 | + Extent ext(map->extent()); |
2454 | |
2455 | try { |
2456 | int32_t const packet_version = s1.get_int("packet_version"); |
2457 | @@ -51,7 +51,7 @@ |
2458 | |
2459 | Section& s2 = prof.get_safe_section("port_spaces"); |
2460 | for (uint16_t i = 0; i < num; ++i) { |
2461 | - map.set_port_space( |
2462 | + map->set_port_space( |
2463 | get_safe_coords(std::to_string(static_cast<unsigned int>(i)), ext, &s2), true); |
2464 | } |
2465 | } else { |
2466 | @@ -69,7 +69,7 @@ |
2467 | Section& s1 = prof.create_section("global"); |
2468 | s1.set_int("packet_version", kCurrentPacketVersion); |
2469 | |
2470 | - Map& map = egbase.map(); |
2471 | + const Map& map = egbase.map(); |
2472 | const uint16_t num = map.get_port_spaces().size(); |
2473 | s1.set_int("number_of_port_spaces", num); |
2474 | |
2475 | |
2476 | === modified file 'src/map_io/map_resources_packet.cc' |
2477 | --- src/map_io/map_resources_packet.cc 2017-01-25 18:55:59 +0000 |
2478 | +++ src/map_io/map_resources_packet.cc 2017-08-20 12:33:35 +0000 |
2479 | @@ -39,7 +39,7 @@ |
2480 | FileRead fr; |
2481 | fr.open(fs, "binary/resource"); |
2482 | |
2483 | - Map& map = egbase.map(); |
2484 | + Map* map = egbase.mutable_map(); |
2485 | const World& world = egbase.world(); |
2486 | |
2487 | try { |
2488 | @@ -63,8 +63,8 @@ |
2489 | smap[id] = res; |
2490 | } |
2491 | |
2492 | - for (uint16_t y = 0; y < map.get_height(); ++y) { |
2493 | - for (uint16_t x = 0; x < map.get_width(); ++x) { |
2494 | + for (uint16_t y = 0; y < map->get_height(); ++y) { |
2495 | + for (uint16_t x = 0; x < map->get_width(); ++x) { |
2496 | DescriptionIndex const id = fr.unsigned_8(); |
2497 | ResourceAmount const found_amount = fr.unsigned_8(); |
2498 | ResourceAmount const amount = found_amount; |
2499 | @@ -85,9 +85,9 @@ |
2500 | |
2501 | if (0xa < set_id) |
2502 | throw "Unknown resource in map file. It is not in world!\n"; |
2503 | - const auto fcoords = map.get_fcoords(Coords(x, y)); |
2504 | - map.initialize_resources(fcoords, set_id, set_start_amount); |
2505 | - map.set_resources(fcoords, set_amount); |
2506 | + const auto fcoords = map->get_fcoords(Coords(x, y)); |
2507 | + map->initialize_resources(fcoords, set_id, set_start_amount); |
2508 | + map->set_resources(fcoords, set_amount); |
2509 | } |
2510 | } |
2511 | } else { |
2512 | |
2513 | === modified file 'src/map_io/map_roaddata_packet.cc' |
2514 | --- src/map_io/map_roaddata_packet.cc 2017-01-25 18:55:59 +0000 |
2515 | +++ src/map_io/map_roaddata_packet.cc 2017-08-20 12:33:35 +0000 |
2516 | @@ -104,7 +104,7 @@ |
2517 | Path p(road.flags_[0]->get_position()); |
2518 | for (Path::StepVector::size_type i = nr_steps; i; --i) |
2519 | try { |
2520 | - p.append(egbase.map(), read_direction_8(&fr)); |
2521 | + p.append(map, read_direction_8(&fr)); |
2522 | } catch (const WException& e) { |
2523 | throw GameDataError( |
2524 | "step #%lu: %s", static_cast<long unsigned int>(nr_steps - i), e.what()); |
2525 | |
2526 | === modified file 'src/map_io/map_saver.cc' |
2527 | --- src/map_io/map_saver.cc 2017-01-25 18:55:59 +0000 |
2528 | +++ src/map_io/map_saver.cc 2017-08-20 12:33:35 +0000 |
2529 | @@ -70,8 +70,9 @@ |
2530 | } |
2531 | |
2532 | void MapSaver::save() { |
2533 | + const Map& map = egbase_.map(); |
2534 | std::string timer_message = "MapSaver::save() for '"; |
2535 | - timer_message += egbase_.map().get_name(); |
2536 | + timer_message += map.get_name(); |
2537 | timer_message += "' took %ums"; |
2538 | ScopedTimer timer(timer_message); |
2539 | |
2540 | @@ -160,9 +161,6 @@ |
2541 | |
2542 | // We don't save these when saving a map in the editor. |
2543 | if (is_game) { |
2544 | - |
2545 | - const Map& map = egbase_.map(); |
2546 | - |
2547 | PlayerNumber const nr_players = map.get_nrplayers(); |
2548 | |
2549 | // allowed worker types |
2550 | @@ -285,7 +283,7 @@ |
2551 | log("took %ums\n ", timer.ms_since_last_query()); |
2552 | |
2553 | log("Writing map images ... "); |
2554 | - save_map_images(&fs_, egbase_.map().filesystem()); |
2555 | + save_map_images(&fs_, map.filesystem()); |
2556 | log("took %ums\n ", timer.ms_since_last_query()); |
2557 | |
2558 | if (is_game) { |
2559 | |
2560 | === modified file 'src/map_io/map_terrain_packet.cc' |
2561 | --- src/map_io/map_terrain_packet.cc 2017-01-25 18:55:59 +0000 |
2562 | +++ src/map_io/map_terrain_packet.cc 2017-08-20 12:33:35 +0000 |
2563 | @@ -41,7 +41,7 @@ |
2564 | FileRead fr; |
2565 | fr.open(fs, "binary/terrain"); |
2566 | |
2567 | - Map& map = egbase.map(); |
2568 | + const Map& map = egbase.map(); |
2569 | const World& world = egbase.world(); |
2570 | |
2571 | try { |
2572 | |
2573 | === modified file 'src/map_io/map_version_packet.cc' |
2574 | --- src/map_io/map_version_packet.cc 2017-01-25 18:55:59 +0000 |
2575 | +++ src/map_io/map_version_packet.cc 2017-08-20 12:33:35 +0000 |
2576 | @@ -42,9 +42,9 @@ |
2577 | try { |
2578 | prof.read("version", nullptr, fs); |
2579 | } catch (...) { |
2580 | - Map& map = egbase.map(); |
2581 | - map.map_version_.map_version_timestamp = 0; |
2582 | - map.map_version_.map_creator_version = "unknown"; |
2583 | + Map* map = egbase.mutable_map(); |
2584 | + map->map_version_.map_version_timestamp = 0; |
2585 | + map->map_version_.map_creator_version = "unknown"; |
2586 | return; |
2587 | } |
2588 | |
2589 | @@ -55,14 +55,14 @@ |
2590 | if ((packet_version == kCurrentPacketVersion) || |
2591 | (packet_version > kCurrentPacketVersion && |
2592 | forward_compatibility <= kCurrentPacketVersion)) { |
2593 | - Map& map = egbase.map(); |
2594 | - map.map_version_.map_source_url = globv.get_safe_string("map_source_url"); |
2595 | - map.map_version_.map_source_release = globv.get_safe_string("map_release"); |
2596 | - map.map_version_.map_creator_version = globv.get_safe_string("map_creator_version"); |
2597 | - map.map_version_.map_version_major = globv.get_safe_int("map_version_major"); |
2598 | - map.map_version_.map_version_minor = globv.get_safe_int("map_version_minor"); |
2599 | + Map* map = egbase.mutable_map(); |
2600 | + map->map_version_.map_source_url = globv.get_safe_string("map_source_url"); |
2601 | + map->map_version_.map_source_release = globv.get_safe_string("map_release"); |
2602 | + map->map_version_.map_creator_version = globv.get_safe_string("map_creator_version"); |
2603 | + map->map_version_.map_version_major = globv.get_safe_int("map_version_major"); |
2604 | + map->map_version_.map_version_minor = globv.get_safe_int("map_version_minor"); |
2605 | uint32_t ts = static_cast<uint32_t>(globv.get_safe_int("map_version_timestamp")); |
2606 | - map.map_version_.map_version_timestamp = ts; |
2607 | + map->map_version_.map_version_timestamp = ts; |
2608 | } else { |
2609 | throw UnhandledVersionError("MapVersionPacket", packet_version, kCurrentPacketVersion); |
2610 | } |
2611 | @@ -108,7 +108,7 @@ |
2612 | // TODO(unknown): -- we could store the unix time in uint32, as a partial fix to 2038 problem. |
2613 | // There seems to be a get_safe_natural method, but not corresponding setter. |
2614 | |
2615 | - Map& map = egbase.map(); |
2616 | + const Map& map = egbase.map(); |
2617 | globs.set_string("map_source_url", map.map_version_.map_source_url); |
2618 | globs.set_string("map_release", map.map_version_.map_source_release); |
2619 | globs.set_string("map_creator_version", map.map_version_.map_creator_version); |
2620 | |
2621 | === modified file 'src/scripting/lua_bases.cc' |
2622 | --- src/scripting/lua_bases.cc 2017-01-30 14:40:12 +0000 |
2623 | +++ src/scripting/lua_bases.cc 2017-08-20 12:33:35 +0000 |
2624 | @@ -458,7 +458,7 @@ |
2625 | */ |
2626 | int LuaPlayerBase::place_road(lua_State* L) { |
2627 | EditorGameBase& egbase = get_egbase(L); |
2628 | - Map& map = egbase.map(); |
2629 | + const Map& map = egbase.map(); |
2630 | |
2631 | Flag* starting_flag = (*get_user_class<LuaMaps::LuaFlag>(L, 2))->get(L, egbase); |
2632 | Coords current = starting_flag->get_position(); |
2633 | |
2634 | === modified file 'src/scripting/lua_game.cc' |
2635 | --- src/scripting/lua_game.cc 2017-08-17 15:34:45 +0000 |
2636 | +++ src/scripting/lua_game.cc 2017-08-20 12:33:35 +0000 |
2637 | @@ -565,8 +565,7 @@ |
2638 | int LuaPlayer::add_objective(lua_State* L) { |
2639 | Game& game = get_game(L); |
2640 | |
2641 | - Map* map = game.get_map(); |
2642 | - Map::Objectives* objectives = map->mutable_objectives(); |
2643 | + Map::Objectives* objectives = game.mutable_map()->mutable_objectives(); |
2644 | |
2645 | const std::string name = luaL_checkstring(L, 2); |
2646 | if (objectives->count(name)) |
2647 | @@ -596,13 +595,13 @@ |
2648 | int LuaPlayer::reveal_fields(lua_State* L) { |
2649 | EditorGameBase& egbase = get_egbase(L); |
2650 | Player& p = get(L, egbase); |
2651 | - Map& m = egbase.map(); |
2652 | + const Map& map = egbase.map(); |
2653 | |
2654 | luaL_checktype(L, 2, LUA_TTABLE); |
2655 | |
2656 | lua_pushnil(L); /* first key */ |
2657 | while (lua_next(L, 2) != 0) { |
2658 | - p.see_node(m, m[0], (*get_user_class<LuaField>(L, -1))->fcoords(L), egbase.get_gametime()); |
2659 | + p.see_node(map, map[0], (*get_user_class<LuaField>(L, -1))->fcoords(L), egbase.get_gametime()); |
2660 | lua_pop(L, 1); |
2661 | } |
2662 | |
2663 | @@ -626,14 +625,13 @@ |
2664 | int LuaPlayer::hide_fields(lua_State* L) { |
2665 | EditorGameBase& egbase = get_egbase(L); |
2666 | Player& p = get(L, egbase); |
2667 | - Map& m = egbase.map(); |
2668 | |
2669 | luaL_checktype(L, 2, LUA_TTABLE); |
2670 | const bool mode = !lua_isnone(L, 3) && luaL_checkboolean(L, 3); |
2671 | |
2672 | lua_pushnil(L); /* first key */ |
2673 | while (lua_next(L, 2) != 0) { |
2674 | - p.unsee_node((*get_user_class<LuaField>(L, -1))->fcoords(L).field - &m[0], |
2675 | + p.unsee_node((*get_user_class<LuaField>(L, -1))->fcoords(L).field - &egbase.map()[0], |
2676 | egbase.get_gametime(), |
2677 | mode ? Player::UnseeNodeMode::kUnexplore : Player::UnseeNodeMode::kUnsee); |
2678 | lua_pop(L, 1); |
2679 | @@ -691,15 +689,15 @@ |
2680 | */ |
2681 | int LuaPlayer::get_ships(lua_State* L) { |
2682 | EditorGameBase& egbase = get_egbase(L); |
2683 | - Map* map = egbase.get_map(); |
2684 | + const Map& map = egbase.map(); |
2685 | PlayerNumber p = (get(L, egbase)).player_number(); |
2686 | lua_newtable(L); |
2687 | uint32_t cidx = 1; |
2688 | |
2689 | std::set<OPtr<Ship>> found_ships; |
2690 | - for (int16_t y = 0; y < map->get_height(); ++y) { |
2691 | - for (int16_t x = 0; x < map->get_width(); ++x) { |
2692 | - FCoords f = map->get_fcoords(Coords(x, y)); |
2693 | + for (int16_t y = 0; y < map.get_height(); ++y) { |
2694 | + for (int16_t x = 0; x < map.get_width(); ++x) { |
2695 | + FCoords f = map.get_fcoords(Coords(x, y)); |
2696 | // there are too many bobs on the map so we investigate |
2697 | // only bobs on water |
2698 | if (f.field->nodecaps() & MOVECAPS_SWIM) { |
2699 | @@ -734,7 +732,6 @@ |
2700 | */ |
2701 | int LuaPlayer::get_buildings(lua_State* L) { |
2702 | EditorGameBase& egbase = get_egbase(L); |
2703 | - Map* map = egbase.get_map(); |
2704 | Player& p = get(L, egbase); |
2705 | |
2706 | // if only one string, convert to array so that we can use |
2707 | @@ -770,7 +767,7 @@ |
2708 | continue; |
2709 | |
2710 | lua_pushuint32(L, cidx++); |
2711 | - upcasted_map_object_to_lua(L, (*map)[vec[l].pos].get_immovable()); |
2712 | + upcasted_map_object_to_lua(L, egbase.map()[vec[l].pos].get_immovable()); |
2713 | lua_rawset(L, -3); |
2714 | } |
2715 | |
2716 | @@ -1087,7 +1084,7 @@ |
2717 | std::string filename = _("%1% (%2%)"); |
2718 | i18n::Textdomain td("maps"); |
2719 | filename = |
2720 | - (boost::format(filename) % _(get_egbase(L).get_map()->get_name()) % o.descname().c_str()) |
2721 | + (boost::format(filename) % _(get_egbase(L).map().get_name()) % o.descname().c_str()) |
2722 | .str(); |
2723 | get_game(L).save_handler().request_save(filename); |
2724 | } |
2725 | @@ -1103,7 +1100,7 @@ |
2726 | Game& g = get_game(L); |
2727 | // The next call checks if the Objective still exists |
2728 | get(L, g); |
2729 | - g.map().mutable_objectives()->erase(name_); |
2730 | + g.mutable_map()->mutable_objectives()->erase(name_); |
2731 | return 0; |
2732 | } |
2733 | |
2734 | @@ -1125,7 +1122,7 @@ |
2735 | ========================================================== |
2736 | */ |
2737 | Objective& LuaObjective::get(lua_State* L, Widelands::Game& g) { |
2738 | - Map::Objectives* objectives = g.map().mutable_objectives(); |
2739 | + Map::Objectives* objectives = g.mutable_map()->mutable_objectives(); |
2740 | Map::Objectives::iterator i = objectives->find(name_); |
2741 | if (i == objectives->end()) { |
2742 | report_error(L, "Objective with name '%s' doesn't exist!", name_.c_str()); |
2743 | |
2744 | === modified file 'src/scripting/lua_map.cc' |
2745 | --- src/scripting/lua_map.cc 2017-08-16 04:31:56 +0000 |
2746 | +++ src/scripting/lua_map.cc 2017-08-20 12:33:35 +0000 |
2747 | @@ -1171,10 +1171,10 @@ |
2748 | for each player defined in the map. |
2749 | */ |
2750 | int LuaMap::get_player_slots(lua_State* L) { |
2751 | - Map& m = get_egbase(L).map(); |
2752 | + const Map& map = get_egbase(L).map(); |
2753 | |
2754 | - lua_createtable(L, m.get_nrplayers(), 0); |
2755 | - for (Widelands::PlayerNumber i = 0; i < m.get_nrplayers(); i++) { |
2756 | + lua_createtable(L, map.get_nrplayers(), 0); |
2757 | + for (Widelands::PlayerNumber i = 0; i < map.get_nrplayers(); i++) { |
2758 | lua_pushuint32(L, i + 1); |
2759 | to_lua<LuaMaps::LuaPlayerSlot>(L, new LuaMaps::LuaPlayerSlot(i + 1)); |
2760 | lua_settable(L, -3); |
2761 | @@ -1252,11 +1252,11 @@ |
2762 | uint32_t x = luaL_checkuint32(L, 2); |
2763 | uint32_t y = luaL_checkuint32(L, 3); |
2764 | |
2765 | - Map& m = get_egbase(L).map(); |
2766 | + const Map& map = get_egbase(L).map(); |
2767 | |
2768 | - if (x >= static_cast<uint32_t>(m.get_width())) |
2769 | + if (x >= static_cast<uint32_t>(map.get_width())) |
2770 | report_error(L, "x coordinate out of range!"); |
2771 | - if (y >= static_cast<uint32_t>(m.get_height())) |
2772 | + if (y >= static_cast<uint32_t>(map.get_height())) |
2773 | report_error(L, "y coordinate out of range!"); |
2774 | |
2775 | return to_lua<LuaMaps::LuaField>(L, new LuaMaps::LuaField(x, y)); |
2776 | @@ -1272,7 +1272,7 @@ |
2777 | // TODO(unknown): do we really want this function? |
2778 | int LuaMap::recalculate(lua_State* L) { |
2779 | EditorGameBase& egbase = get_egbase(L); |
2780 | - egbase.map().recalc_whole_map(egbase.world()); |
2781 | + egbase.mutable_map()->recalc_whole_map(egbase.world()); |
2782 | return 0; |
2783 | } |
2784 | |
2785 | @@ -5787,7 +5787,7 @@ |
2786 | report_error(L, "height must be <= %i", MAX_FIELD_HEIGHT); |
2787 | |
2788 | EditorGameBase& egbase = get_egbase(L); |
2789 | - egbase.map().set_height(egbase.world(), f, height); |
2790 | + egbase.mutable_map()->set_height(egbase.world(), f, height); |
2791 | |
2792 | return 0; |
2793 | } |
2794 | @@ -5865,9 +5865,9 @@ |
2795 | |
2796 | auto c = fcoords(L); |
2797 | const auto current_amount = c.field->get_resources_amount(); |
2798 | - auto& map = egbase.map(); |
2799 | - map.initialize_resources(c, res, c.field->get_initial_res_amount()); |
2800 | - map.set_resources(c, current_amount); |
2801 | + auto* map = egbase.mutable_map(); |
2802 | + map->initialize_resources(c, res, c.field->get_initial_res_amount()); |
2803 | + map->set_resources(c, current_amount); |
2804 | return 0; |
2805 | } |
2806 | |
2807 | @@ -5894,12 +5894,12 @@ |
2808 | report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount, |
2809 | static_cast<unsigned int>(max_amount)); |
2810 | |
2811 | - auto& map = egbase.map(); |
2812 | + auto* map = egbase.mutable_map(); |
2813 | if (is_a(Game, &egbase)) { |
2814 | - map.set_resources(c, amount); |
2815 | + map->set_resources(c, amount); |
2816 | } else { |
2817 | // in editor, reset also initial amount |
2818 | - map.initialize_resources(c, res, amount); |
2819 | + map->initialize_resources(c, res, amount); |
2820 | } |
2821 | return 0; |
2822 | } |
2823 | @@ -5972,7 +5972,7 @@ |
2824 | if (td == static_cast<DescriptionIndex>(-1)) |
2825 | report_error(L, "Unknown terrain '%s'", name); |
2826 | |
2827 | - egbase.map().change_terrain(world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::R), td); |
2828 | + egbase.mutable_map()->change_terrain(world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::R), td); |
2829 | |
2830 | lua_pushstring(L, name); |
2831 | return 1; |
2832 | @@ -5991,7 +5991,8 @@ |
2833 | if (td == static_cast<DescriptionIndex>(INVALID_INDEX)) |
2834 | report_error(L, "Unknown terrain '%s'", name); |
2835 | |
2836 | - egbase.map().change_terrain(world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::D), td); |
2837 | + egbase.mutable_map()->change_terrain( |
2838 | + world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::D), td); |
2839 | |
2840 | lua_pushstring(L, name); |
2841 | return 1; |
2842 | @@ -6058,7 +6059,7 @@ |
2843 | */ |
2844 | int LuaField::get_claimers(lua_State* L) { |
2845 | EditorGameBase& egbase = get_egbase(L); |
2846 | - Map& map = egbase.map(); |
2847 | + const Map& map = egbase.map(); |
2848 | |
2849 | std::vector<PlrInfluence> claimers; |
2850 | |
2851 | @@ -6187,7 +6188,7 @@ |
2852 | ========================================================== |
2853 | */ |
2854 | int LuaField::region(lua_State* L, uint32_t radius) { |
2855 | - Map& map = get_egbase(L).map(); |
2856 | + const Map& map = get_egbase(L).map(); |
2857 | MapRegion<Area<FCoords>> mr(map, Area<FCoords>(fcoords(L), radius)); |
2858 | |
2859 | lua_newtable(L); |
2860 | @@ -6203,7 +6204,7 @@ |
2861 | } |
2862 | |
2863 | int LuaField::hollow_region(lua_State* L, uint32_t radius, uint32_t inner_radius) { |
2864 | - Map& map = get_egbase(L).map(); |
2865 | + const Map& map = get_egbase(L).map(); |
2866 | HollowArea<Area<>> har(Area<>(coords_, radius), inner_radius); |
2867 | |
2868 | MapHollowRegion<Area<>> mr(map, har); |
2869 | @@ -6265,7 +6266,7 @@ |
2870 | (RO) The name of the tribe suggested for this player in this map |
2871 | */ |
2872 | int LuaPlayerSlot::get_tribe_name(lua_State* L) { |
2873 | - lua_pushstring(L, get_egbase(L).get_map()->get_scenario_player_tribe(player_number_)); |
2874 | + lua_pushstring(L, get_egbase(L).map().get_scenario_player_tribe(player_number_)); |
2875 | return 1; |
2876 | } |
2877 | |
2878 | @@ -6275,7 +6276,7 @@ |
2879 | (RO) The name for this player as suggested in this map |
2880 | */ |
2881 | int LuaPlayerSlot::get_name(lua_State* L) { |
2882 | - lua_pushstring(L, get_egbase(L).get_map()->get_scenario_player_name(player_number_)); |
2883 | + lua_pushstring(L, get_egbase(L).map().get_scenario_player_name(player_number_)); |
2884 | return 1; |
2885 | } |
2886 | |
2887 | |
2888 | === modified file 'src/website/map_info.cc' |
2889 | --- src/website/map_info.cc 2017-01-25 18:55:59 +0000 |
2890 | +++ src/website/map_info.cc 2017-08-20 12:33:35 +0000 |
2891 | @@ -75,9 +75,8 @@ |
2892 | FileSystem* in_out_filesystem = &FileSystem::create(map_dir); |
2893 | g_fs->add_file_system(in_out_filesystem); |
2894 | |
2895 | - Map* map = new Map(); |
2896 | EditorGameBase egbase(nullptr); |
2897 | - egbase.set_map(map); |
2898 | + auto* map = egbase.mutable_map(); |
2899 | std::unique_ptr<Widelands::MapLoader> ml(map->get_correct_loader(map_file)); |
2900 | |
2901 | if (!ml) { |
2902 | |
2903 | === modified file 'src/wui/attack_box.cc' |
2904 | --- src/wui/attack_box.cc 2017-02-25 13:27:40 +0000 |
2905 | +++ src/wui/attack_box.cc 2017-08-20 12:33:35 +0000 |
2906 | @@ -40,17 +40,16 @@ |
2907 | uint32_t const y) |
2908 | : UI::Box(parent, x, y, UI::Box::Vertical), |
2909 | player_(player), |
2910 | - map_(&player_->egbase().map()), |
2911 | + map_(player_->egbase().map()), |
2912 | node_coordinates_(target), |
2913 | lastupdate_(0) { |
2914 | init(); |
2915 | } |
2916 | |
2917 | uint32_t AttackBox::get_max_attackers() { |
2918 | - assert(map_); |
2919 | assert(player_); |
2920 | |
2921 | - if (upcast(Building, building, map_->get_immovable(*node_coordinates_))) |
2922 | + if (upcast(Building, building, map_.get_immovable(*node_coordinates_))) |
2923 | return player_->find_attack_soldiers(building->base_flag()); |
2924 | return 0; |
2925 | } |
2926 | |
2927 | === modified file 'src/wui/attack_box.h' |
2928 | --- src/wui/attack_box.h 2017-05-20 22:42:49 +0000 |
2929 | +++ src/wui/attack_box.h 2017-08-20 12:33:35 +0000 |
2930 | @@ -80,7 +80,7 @@ |
2931 | |
2932 | private: |
2933 | Widelands::Player* player_; |
2934 | - Widelands::Map* map_; |
2935 | + const Widelands::Map& map_; |
2936 | Widelands::FCoords* node_coordinates_; |
2937 | |
2938 | std::unique_ptr<UI::Slider> soldiers_slider_; |
2939 | |
2940 | === modified file 'src/wui/building_statistics_menu.cc' |
2941 | --- src/wui/building_statistics_menu.cc 2017-08-17 15:34:45 +0000 |
2942 | +++ src/wui/building_statistics_menu.cc 2017-08-20 12:33:35 +0000 |
2943 | @@ -540,7 +540,6 @@ |
2944 | void BuildingStatisticsMenu::update() { |
2945 | const Player& player = iplayer().player(); |
2946 | const TribeDescr& tribe = player.tribe(); |
2947 | - const Map& map = iplayer().game().map(); |
2948 | const DescriptionIndex nr_buildings = iplayer().egbase().tribes().nrbuildings(); |
2949 | |
2950 | owned_label_.set_visible(false); |
2951 | @@ -581,7 +580,7 @@ |
2952 | ++nr_build; |
2953 | else { |
2954 | ++nr_owned; |
2955 | - BaseImmovable& immovable = *map[stats_vector[l].pos].get_immovable(); |
2956 | + BaseImmovable& immovable = *iplayer().game().map()[stats_vector[l].pos].get_immovable(); |
2957 | if (building.type() == MapObjectType::PRODUCTIONSITE || |
2958 | building.type() == MapObjectType::TRAININGSITE) { |
2959 | ProductionSite& productionsite = dynamic_cast<ProductionSite&>(immovable); |
2960 | |
2961 | === modified file 'src/wui/fieldaction.cc' |
2962 | --- src/wui/fieldaction.cc 2017-08-17 15:34:45 +0000 |
2963 | +++ src/wui/fieldaction.cc 2017-08-20 12:33:35 +0000 |
2964 | @@ -195,7 +195,7 @@ |
2965 | void reset_mouse_and_die(); |
2966 | |
2967 | Widelands::Player* player_; |
2968 | - Widelands::Map* map_; |
2969 | + const Widelands::Map& map_; |
2970 | FieldOverlayManager& field_overlay_manager_; |
2971 | |
2972 | Widelands::FCoords node_; |
2973 | @@ -246,9 +246,9 @@ |
2974 | UI::UniqueWindow::Registry* const registry) |
2975 | : UI::UniqueWindow(ib, "field_action", registry, 68, 34, _("Action")), |
2976 | player_(plr), |
2977 | - map_(&ib->egbase().map()), |
2978 | + map_(ib->egbase().map()), |
2979 | field_overlay_manager_(*ib->mutable_field_overlay_manager()), |
2980 | - node_(ib->get_sel_pos().node, &(*map_)[ib->get_sel_pos().node]), |
2981 | + node_(ib->get_sel_pos().node, &map_[ib->get_sel_pos().node]), |
2982 | tabpanel_(this, g_gr->images().get("images/ui_basic/but1.png")), |
2983 | fastclick_(true), |
2984 | best_tab_(0), |
2985 | @@ -305,7 +305,7 @@ |
2986 | const Widelands::PlayerNumber owner = node_.field->get_owned_by(); |
2987 | |
2988 | if (!igbase || igbase->can_see(owner)) { |
2989 | - Widelands::BaseImmovable* const imm = map_->get_immovable(node_); |
2990 | + Widelands::BaseImmovable* const imm = map_.get_immovable(node_); |
2991 | const bool can_act = igbase ? igbase->can_act(owner) : true; |
2992 | |
2993 | // The box with road-building buttons |
2994 | @@ -380,7 +380,7 @@ |
2995 | void FieldActionWindow::add_buttons_attack() { |
2996 | UI::Box& a_box = *new UI::Box(&tabpanel_, 0, 0, UI::Box::Horizontal); |
2997 | |
2998 | - if (upcast(Widelands::Building, building, map_->get_immovable(node_))) { |
2999 | + if (upcast(Widelands::Building, building, map_.get_immovable(node_))) { |
3000 | if (const Widelands::AttackTarget* attack_target = building->attack_target()) { |
3001 | if (player_ && player_->is_hostile(building->owner()) && |
3002 | attack_target->can_be_attacked()) { |
3003 | |
3004 | === modified file 'src/wui/game_debug_ui.cc' |
3005 | --- src/wui/game_debug_ui.cc 2017-06-28 07:17:12 +0000 |
3006 | +++ src/wui/game_debug_ui.cc 2017-08-20 12:33:35 +0000 |
3007 | @@ -198,7 +198,7 @@ |
3008 | void open_bob(uint32_t); |
3009 | |
3010 | private: |
3011 | - Widelands::Map& map_; |
3012 | + const Widelands::Map& map_; |
3013 | Widelands::FCoords const coords_; |
3014 | |
3015 | UI::MultilineTextarea ui_field_; |
3016 | |
3017 | === modified file 'src/wui/game_main_menu_save_game.cc' |
3018 | --- src/wui/game_main_menu_save_game.cc 2017-06-24 11:18:12 +0000 |
3019 | +++ src/wui/game_main_menu_save_game.cc 2017-08-20 12:33:35 +0000 |
3020 | @@ -113,7 +113,7 @@ |
3021 | { |
3022 | // Try to translate the map name. |
3023 | i18n::Textdomain td("maps"); |
3024 | - mapname_.set_text(_(parent.game().get_map()->get_name())); |
3025 | + mapname_.set_text(_(parent.game().map().get_name())); |
3026 | } |
3027 | uint32_t gametime = parent.game().get_gametime(); |
3028 | gametime_.set_text(gametimestring(gametime)); |
3029 | |
3030 | === modified file 'src/wui/interactive_base.cc' |
3031 | --- src/wui/interactive_base.cc 2017-08-18 02:28:27 +0000 |
3032 | +++ src/wui/interactive_base.cc 2017-08-20 12:33:35 +0000 |
3033 | @@ -144,7 +144,7 @@ |
3034 | } |
3035 | |
3036 | void InteractiveBase::set_sel_pos(Widelands::NodeAndTriangle<> const center) { |
3037 | - Map& map = egbase().map(); |
3038 | + const Map& map = egbase().map(); |
3039 | |
3040 | // Remove old sel pointer |
3041 | if (sel_.jobid) |
3042 | @@ -278,7 +278,7 @@ |
3043 | default: |
3044 | throw wexception("Encountered unexpected WorkareaInfo size %i", workareas_nrs); |
3045 | } |
3046 | - Widelands::Map& map = egbase_.map(); |
3047 | + const Widelands::Map& map = egbase_.map(); |
3048 | FieldOverlayManager::OverlayId overlay_id = field_overlay_manager_->next_overlay_id(); |
3049 | |
3050 | Widelands::HollowArea<> hollow_area(Widelands::Area<>(coords, 0), 0); |
3051 | @@ -606,7 +606,7 @@ |
3052 | bool InteractiveBase::append_build_road(Coords const field) { |
3053 | assert(buildroad_); |
3054 | |
3055 | - Map& map = egbase().map(); |
3056 | + const Map& map = egbase().map(); |
3057 | const Widelands::Player& player = egbase().player(road_build_player_); |
3058 | |
3059 | { // find a path to the clicked-on node |
3060 | @@ -708,7 +708,7 @@ |
3061 | assert(buildroad_); |
3062 | assert(road_building_preview_.empty()); |
3063 | |
3064 | - Map& map = egbase().map(); |
3065 | + const Map& map = egbase().map(); |
3066 | |
3067 | // preview of the road |
3068 | const CoordPath::StepVector::size_type nr_steps = buildroad_->get_nsteps(); |
3069 | |
3070 | === modified file 'src/wui/interactive_gamebase.cc' |
3071 | --- src/wui/interactive_gamebase.cc 2017-08-17 15:34:45 +0000 |
3072 | +++ src/wui/interactive_gamebase.cc 2017-08-20 12:33:35 +0000 |
3073 | @@ -137,7 +137,6 @@ |
3074 | * during single/multiplayer/scenario). |
3075 | */ |
3076 | void InteractiveGameBase::postload() { |
3077 | - Widelands::Map& map = egbase().map(); |
3078 | auto* overlay_manager = mutable_field_overlay_manager(); |
3079 | show_buildhelp(false); |
3080 | on_buildhelp_changed(buildhelp()); |
3081 | @@ -146,7 +145,7 @@ |
3082 | boost::bind(&InteractiveGameBase::calculate_buildcaps, this, _1)); |
3083 | |
3084 | // Recalc whole map for changed owner stuff |
3085 | - map.recalc_whole_map(egbase().world()); |
3086 | + egbase().mutable_map()->recalc_whole_map(egbase().world()); |
3087 | |
3088 | // Close game-relevant UI windows (but keep main menu open) |
3089 | fieldaction_.destroy(); |
3090 | @@ -224,7 +223,7 @@ |
3091 | * If so, do it and return true; otherwise, return false. |
3092 | */ |
3093 | bool InteractiveGameBase::try_show_ship_window() { |
3094 | - Widelands::Map& map(game().map()); |
3095 | + const Widelands::Map& map= game().map(); |
3096 | Widelands::Area<Widelands::FCoords> area(map.get_fcoords(get_sel_pos().node), 1); |
3097 | |
3098 | if (!(area.field->nodecaps() & Widelands::MOVECAPS_SWIM)) |
3099 | |
3100 | === modified file 'src/wui/watchwindow.cc' |
3101 | --- src/wui/watchwindow.cc 2017-08-17 15:34:45 +0000 |
3102 | +++ src/wui/watchwindow.cc 2017-08-20 12:33:35 +0000 |
3103 | @@ -210,11 +210,11 @@ |
3104 | } |
3105 | |
3106 | if (upcast(Widelands::Bob, bob, views_[cur_index_].tracking.get(game()))) { |
3107 | + const Widelands::Map& map = game().map(); |
3108 | const Vector2f field_position = |
3109 | - MapviewPixelFunctions::to_map_pixel(game().map(), bob->get_position()); |
3110 | + MapviewPixelFunctions::to_map_pixel(map, bob->get_position()); |
3111 | const Vector2f pos = bob->calc_drawpos(game(), field_position, 1.f); |
3112 | |
3113 | - Widelands::Map& map = game().map(); |
3114 | // Drop the tracking if it leaves our vision range |
3115 | InteractivePlayer* ipl = game().get_ipl(); |
3116 | if (ipl && 1 >= ipl->player().vision(map.get_index(bob->get_position(), map.get_width()))) { |
3117 | @@ -253,7 +253,7 @@ |
3118 | // Find the nearest bob. Other object types can not move and are |
3119 | // therefore not of interest. |
3120 | Vector2f center_map_pixel = mapview_.view_area().rect().center(); |
3121 | - Widelands::Map& map = g.map(); |
3122 | + const Widelands::Map& map = g.map(); |
3123 | MapviewPixelFunctions::normalize_pix(map, ¢er_map_pixel); |
3124 | std::vector<Widelands::Bob*> bobs; |
3125 | // Scan progressively larger circles around the given position for |
Continuous integration builds have changed state:
Travis build 2583. State: failed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 266392703. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ cleanup_ map-2405.
Appveyor build 2405. State: failed. Details: https:/