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

Proposed by SirVer
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
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.

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

Continuous integration builds have changed state:

Travis build 2583. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/266392703.
Appveyor build 2405. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_cleanup_map-2405.

Revision history for this message
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.

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2586. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/266460706.
Appveyor build 2408. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_cleanup_map-2408.

Revision history for this message
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

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/ai/ai_help_structs.cc'
--- src/ai/ai_help_structs.cc 2017-08-19 23:24:28 +0000
+++ src/ai/ai_help_structs.cc 2017-08-20 12:33:35 +0000
@@ -41,7 +41,7 @@
41}41}
4242
43bool CheckStepRoadAI::allowed(43bool CheckStepRoadAI::allowed(
44 Map& map, FCoords start, FCoords end, int32_t, CheckStep::StepId const id) const {44 const Map& map, FCoords start, FCoords end, int32_t, CheckStep::StepId const id) const {
45 uint8_t endcaps = player->get_buildcaps(end);45 uint8_t endcaps = player->get_buildcaps(end);
4646
47 // we should not cross fields with road or flags (or any other immovable)47 // we should not cross fields with road or flags (or any other immovable)
4848
=== modified file 'src/ai/ai_help_structs.h'
--- src/ai/ai_help_structs.h 2017-08-19 19:33:37 +0000
+++ src/ai/ai_help_structs.h 2017-08-20 12:33:35 +0000
@@ -131,7 +131,7 @@
131struct CheckStepRoadAI {131struct CheckStepRoadAI {
132 CheckStepRoadAI(Player* const pl, uint8_t const mc, bool const oe);132 CheckStepRoadAI(Player* const pl, uint8_t const mc, bool const oe);
133133
134 bool allowed(Map&, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) const;134 bool allowed(const Map&, FCoords start, FCoords end, int32_t dir, CheckStep::StepId) const;
135 bool reachable_dest(const Map&, const FCoords& dest) const;135 bool reachable_dest(const Map&, const FCoords& dest) const;
136136
137 Player* player;137 Player* player;
138138
=== modified file 'src/ai/defaultai.cc'
--- src/ai/defaultai.cc 2017-08-19 19:33:37 +0000
+++ src/ai/defaultai.cc 2017-08-20 12:33:35 +0000
@@ -244,8 +244,6 @@
244244
245 const int32_t delay_time = gametime - taskPool.front().due_time;245 const int32_t delay_time = gametime - taskPool.front().due_time;
246246
247 Map& map = game().map();
248
249 // Here we decide how many jobs will be run now (none - 5)247 // Here we decide how many jobs will be run now (none - 5)
250 // in case no job is due now, it can be zero248 // in case no job is due now, it can be zero
251 uint32_t jobs_to_run_count = (delay_time < 0) ? 0 : 1;249 uint32_t jobs_to_run_count = (delay_time < 0) ? 0 : 1;
@@ -446,7 +444,7 @@
446 { // statistics for spotted warehouses444 { // statistics for spotted warehouses
447 uint16_t conquered_wh = 0;445 uint16_t conquered_wh = 0;
448 for (auto coords : enemy_warehouses) {446 for (auto coords : enemy_warehouses) {
449 if (get_land_owner(map, coords) == player_number()) {447 if (get_land_owner(game().map(), coords) == player_number()) {
450 ++conquered_wh;448 ++conquered_wh;
451 }449 }
452 };450 };
@@ -690,7 +688,7 @@
690 for (const DescriptionIndex& temp_output : prod.output_ware_types()) {688 for (const DescriptionIndex& temp_output : prod.output_ware_types()) {
691 bo.outputs.push_back(temp_output);689 bo.outputs.push_back(temp_output);
692 }690 }
693 for (const auto temp_position : prod.working_positions()) {691 for (const auto& temp_position : prod.working_positions()) {
694 bo.positions.push_back(temp_position.first);692 bo.positions.push_back(temp_position.first);
695 }693 }
696694
@@ -925,7 +923,7 @@
925 taskPool.push_back(SchedulerTask(923 taskPool.push_back(SchedulerTask(
926 std::max<uint32_t>(gametime, 10 * 1000), SchedulerTaskId::kUpdateStats, 15, "review"));924 std::max<uint32_t>(gametime, 10 * 1000), SchedulerTaskId::kUpdateStats, 15, "review"));
927925
928 Map& map = game().map();926 const Map& map = game().map();
929927
930 // here we generate list of all ports and their vicinity from entire map928 // here we generate list of all ports and their vicinity from entire map
931 for (const Coords& c : map.get_port_spaces()) {929 for (const Coords& c : map.get_port_spaces()) {
@@ -1185,7 +1183,7 @@
1185/// Updates one buildable field1183/// Updates one buildable field
1186void DefaultAI::update_buildable_field(BuildableField& field) {1184void DefaultAI::update_buildable_field(BuildableField& field) {
1187 // look if there is any unowned land nearby1185 // look if there is any unowned land nearby
1188 Map& map = game().map();1186 const Map& map = game().map();
1189 const uint32_t gametime = game().get_gametime();1187 const uint32_t gametime = game().get_gametime();
1190 FindNodeUnownedWalkable find_unowned_walkable(player_, game());1188 FindNodeUnownedWalkable find_unowned_walkable(player_, game());
1191 FindEnemyNodeWalkable find_enemy_owned_walkable(player_, game());1189 FindEnemyNodeWalkable find_enemy_owned_walkable(player_, game());
@@ -1813,7 +1811,7 @@
1813void DefaultAI::update_mineable_field(MineableField& field) {1811void DefaultAI::update_mineable_field(MineableField& field) {
1814 // collect information about resources in the area1812 // collect information about resources in the area
1815 std::vector<ImmovableFound> immovables;1813 std::vector<ImmovableFound> immovables;
1816 Map& map = game().map();1814 const Map& map = game().map();
1817 map.find_immovables(Area<FCoords>(field.coords, 5), &immovables);1815 map.find_immovables(Area<FCoords>(field.coords, 5), &immovables);
1818 field.preferred = false;1816 field.preferred = false;
1819 field.mines_nearby = 0;1817 field.mines_nearby = 0;
@@ -1948,7 +1946,7 @@
1948 bool mine = false;1946 bool mine = false;
1949 uint32_t consumers_nearby_count = 0;1947 uint32_t consumers_nearby_count = 0;
19501948
1951 Map& map = game().map();1949 const Map& map = game().map();
19521950
1953 for (int32_t i = 0; i < 4; ++i)1951 for (int32_t i = 0; i < 4; ++i)
1954 spots_avail.at(i) = 0;1952 spots_avail.at(i) = 0;
@@ -3226,7 +3224,6 @@
3226 } else {3224 } else {
3227 checkradius = 15;3225 checkradius = 15;
3228 }3226 }
3229 Map& map = game().map();
32303227
3231 // algorithm to walk on roads3228 // algorithm to walk on roads
3232 while (!queue.empty()) {3229 while (!queue.empty()) {
@@ -3270,7 +3267,7 @@
3270 endflag = &near_road->get_flag(Road::FlagEnd);3267 endflag = &near_road->get_flag(Road::FlagEnd);
3271 }3268 }
32723269
3273 int32_t dist = map.calc_distance(roadstartflag.get_position(), endflag->get_position());3270 int32_t dist = game().map().calc_distance(roadstartflag.get_position(), endflag->get_position());
32743271
3275 if (dist > checkradius) { // out of range of interest3272 if (dist > checkradius) { // out of range of interest
3276 continue;3273 continue;
@@ -3371,7 +3368,7 @@
3371 checkradius += 2;3368 checkradius += 2;
3372 }3369 }
33733370
3374 Map& map = game().map();3371 const Map& map = game().map();
33753372
3376 // initializing new object of FlagsForRoads, we will push there all candidate flags3373 // initializing new object of FlagsForRoads, we will push there all candidate flags
3377 Widelands::FlagsForRoads RoadCandidates(min_reduction);3374 Widelands::FlagsForRoads RoadCandidates(min_reduction);
@@ -3514,7 +3511,7 @@
3514 // first we block the field and vicinity for 15 minutes, probably it is not a good place to3511 // first we block the field and vicinity for 15 minutes, probably it is not a good place to
3515 // build on3512 // build on
3516 MapRegion<Area<FCoords>> mr(3513 MapRegion<Area<FCoords>> mr(
3517 game().map(), Area<FCoords>(map.get_fcoords(bld->get_position()), 2));3514 map, Area<FCoords>(map.get_fcoords(bld->get_position()), 2));
3518 do {3515 do {
3519 blocked_fields.add(mr.location(), game().get_gametime() + 15 * 60 * 1000);3516 blocked_fields.add(mr.location(), game().get_gametime() + 15 * 60 * 1000);
3520 } while (mr.advance(map));3517 } while (mr.advance(map));
@@ -3605,7 +3602,7 @@
3605 }3602 }
3606 }3603 }
36073604
3608 Map& map = game().map();3605 const Map& map = game().map();
36093606
3610 // The code here is bit complicated3607 // The code here is bit complicated
3611 // a) Either this site is pending for upgrade, if ready, order the upgrade3608 // a) Either this site is pending for upgrade, if ready, order the upgrade
@@ -5437,7 +5434,7 @@
5437 uint16_t* mineable_fields_count,5434 uint16_t* mineable_fields_count,
5438 const Coords& starting_spot,5435 const Coords& starting_spot,
5439 const WalkSearch& type) {5436 const WalkSearch& type) {
5440 Map& map = game().map();5437 const Map& map = game().map();
5441 std::list<uint32_t> queue;5438 std::list<uint32_t> queue;
5442 std::unordered_set<uint32_t> done;5439 std::unordered_set<uint32_t> done;
5443 queue.push_front(starting_spot.hash());5440 queue.push_front(starting_spot.hash());
@@ -5640,7 +5637,7 @@
5640 ++num_ports;5637 ++num_ports;
5641 seafaring_economy = true;5638 seafaring_economy = true;
5642 // unblock nearby fields, might be used for other buildings...5639 // unblock nearby fields, might be used for other buildings...
5643 Map& map = game().map();5640 const Map& map = game().map();
5644 MapRegion<Area<FCoords>> mr(5641 MapRegion<Area<FCoords>> mr(
5645 map, Area<FCoords>(map.get_fcoords(warehousesites.back().site->get_position()), 3));5642 map, Area<FCoords>(map.get_fcoords(warehousesites.back().site->get_position()), 3));
5646 do {5643 do {
@@ -5809,9 +5806,8 @@
5809 return;5806 return;
5810 }5807 }
5811 player_statistics.set_update_time(gametime);5808 player_statistics.set_update_time(gametime);
5812 Map& map = game().map();
5813 Widelands::PlayerNumber const pn = player_number();5809 Widelands::PlayerNumber const pn = player_number();
5814 PlayerNumber const nr_players = map.get_nrplayers();5810 PlayerNumber const nr_players = game().map().get_nrplayers();
5815 uint32_t plr_in_game = 0;5811 uint32_t plr_in_game = 0;
5816 iterate_players_existing_novar(p, nr_players, game())++ plr_in_game;5812 iterate_players_existing_novar(p, nr_players, game())++ plr_in_game;
58175813
58185814
=== modified file 'src/ai/defaultai_seafaring.cc'
--- src/ai/defaultai_seafaring.cc 2017-06-26 15:09:21 +0000
+++ src/ai/defaultai_seafaring.cc 2017-08-20 12:33:35 +0000
@@ -26,7 +26,7 @@
26// this scores spot for potential colony26// this scores spot for potential colony
27uint8_t DefaultAI::spot_scoring(Widelands::Coords candidate_spot) {27uint8_t DefaultAI::spot_scoring(Widelands::Coords candidate_spot) {
2828
29 Map& map = game().map();29 const Map& map = game().map();
30 PlayerNumber const pn = player_->player_number();30 PlayerNumber const pn = player_->player_number();
31 uint8_t score = 0;31 uint8_t score = 0;
32 uint16_t mineable_fields_count = 0;32 uint16_t mineable_fields_count = 0;
@@ -421,7 +421,6 @@
421// navigation decisions (these notifications are processes not in 'real time')421// navigation decisions (these notifications are processes not in 'real time')
422void DefaultAI::expedition_management(ShipObserver& so) {422void DefaultAI::expedition_management(ShipObserver& so) {
423423
424 Map& map = game().map();
425 const int32_t gametime = game().get_gametime();424 const int32_t gametime = game().get_gametime();
426 PlayerNumber const pn = player_->player_number();425 PlayerNumber const pn = player_->player_number();
427 // probability for island exploration repetition426 // probability for island exploration repetition
@@ -484,6 +483,7 @@
484 // we head for open sea again483 // we head for open sea again
485 } else {484 } else {
486 // determine swimmable directions485 // determine swimmable directions
486 const Map& map = game().map();
487 std::vector<Direction> possible_directions;487 std::vector<Direction> possible_directions;
488 for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {488 for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
489 // testing distance of 8 fields489 // testing distance of 8 fields
490490
=== modified file 'src/ai/defaultai_warfare.cc'
--- src/ai/defaultai_warfare.cc 2017-08-19 13:27:38 +0000
+++ src/ai/defaultai_warfare.cc 2017-08-20 12:33:35 +0000
@@ -23,7 +23,7 @@
2323
24bool DefaultAI::check_enemy_sites(uint32_t const gametime) {24bool DefaultAI::check_enemy_sites(uint32_t const gametime) {
2525
26 Map& map = game().map();26 const Map& map = game().map();
2727
28 PlayerNumber const nr_players = map.get_nrplayers();28 PlayerNumber const nr_players = map.get_nrplayers();
29 uint32_t plr_in_game = 0;29 uint32_t plr_in_game = 0;
@@ -777,7 +777,6 @@
777777
778 // Check next militarysite778 // Check next militarysite
779 bool changed = false;779 bool changed = false;
780 Map& map = game().map();
781 MilitarySite* ms = militarysites.front().site;780 MilitarySite* ms = militarysites.front().site;
782781
783 // Don't do anything if last change took place lately782 // Don't do anything if last change took place lately
@@ -787,7 +786,7 @@
787 return false;786 return false;
788 }787 }
789788
790 FCoords f = map.get_fcoords(ms->get_position());789 FCoords f = game().map().get_fcoords(ms->get_position());
791790
792 BuildableField bf(f);791 BuildableField bf(f);
793 update_buildable_field(bf);792 update_buildable_field(bf);
794793
=== modified file 'src/economy/economy.cc'
--- src/economy/economy.cc 2017-06-20 08:17:02 +0000
+++ src/economy/economy.cc 2017-08-20 12:33:35 +0000
@@ -136,8 +136,6 @@
136136
137void Economy::check_splits() {137void Economy::check_splits() {
138 EditorGameBase& egbase = owner().egbase();138 EditorGameBase& egbase = owner().egbase();
139 Map& map = egbase.map();
140
141 while (split_checks_.size()) {139 while (split_checks_.size()) {
142 Flag* f1 = split_checks_.back().first.get(egbase);140 Flag* f1 = split_checks_.back().first.get(egbase);
143 Flag* f2 = split_checks_.back().second.get(egbase);141 Flag* f2 = split_checks_.back().second.get(egbase);
@@ -172,7 +170,7 @@
172 // reached from f1. These nodes induce a connected subgraph.170 // reached from f1. These nodes induce a connected subgraph.
173 // This means that the newly created economy, which contains all the171 // This means that the newly created economy, which contains all the
174 // flags that have been split, is already connected.172 // flags that have been split, is already connected.
175 RouteAStar<AStarEstimator> astar(*router_, wwWORKER, AStarEstimator(map, *f2));173 RouteAStar<AStarEstimator> astar(*router_, wwWORKER, AStarEstimator(*egbase.mutable_map(), *f2));
176 astar.push(*f1);174 astar.push(*f1);
177 std::set<OPtr<Flag>> reachable;175 std::set<OPtr<Flag>> reachable;
178176
@@ -198,10 +196,8 @@
198 Flag& start, Flag& end, Route* const route, WareWorker const type, int32_t const cost_cutoff) {196 Flag& start, Flag& end, Route* const route, WareWorker const type, int32_t const cost_cutoff) {
199 assert(start.get_economy() == this);197 assert(start.get_economy() == this);
200 assert(end.get_economy() == this);198 assert(end.get_economy() == this);
201199 return router_->find_route(
202 Map& map = owner().egbase().map();200 start, end, route, type, cost_cutoff, *owner().egbase().mutable_map());
203
204 return router_->find_route(start, end, route, type, cost_cutoff, map);
205}201}
206202
207struct ZeroEstimator {203struct ZeroEstimator {
@@ -604,7 +600,6 @@
604 Route* best_route = nullptr;600 Route* best_route = nullptr;
605 int32_t best_cost = -1;601 int32_t best_cost = -1;
606 Flag& target_flag = req.target_flag();602 Flag& target_flag = req.target_flag();
607 Map& map = game.map();
608603
609 available_supplies_.clear();604 available_supplies_.clear();
610605
@@ -626,7 +621,7 @@
626 const Widelands::Coords provider_position =621 const Widelands::Coords provider_position =
627 supp.get_position(game)->base_flag().get_position();622 supp.get_position(game)->base_flag().get_position();
628623
629 const uint32_t dist = map.calc_distance(target_flag.get_position(), provider_position);624 const uint32_t dist = game.map().calc_distance(target_flag.get_position(), provider_position);
630625
631 UniqueDistance ud = {dist, supp.get_position(game)->serial(), provider};626 UniqueDistance ud = {dist, supp.get_position(game)->serial(), provider};
632627
633628
=== modified file 'src/economy/fleet.cc'
--- src/economy/fleet.cc 2017-08-09 19:25:04 +0000
+++ src/economy/fleet.cc 2017-08-20 12:33:35 +0000
@@ -138,9 +138,7 @@
138 * of the same player.138 * of the same player.
139 */139 */
140void Fleet::find_other_fleet(EditorGameBase& egbase) {140void Fleet::find_other_fleet(EditorGameBase& egbase) {
141 Map& map = egbase.map();141 MapAStar<StepEvalFindFleet> astar(*egbase.mutable_map(), StepEvalFindFleet());
142 MapAStar<StepEvalFindFleet> astar(map, StepEvalFindFleet());
143
144 for (const Ship* temp_ship : ships_) {142 for (const Ship* temp_ship : ships_) {
145 astar.push(temp_ship->get_position());143 astar.push(temp_ship->get_position());
146 }144 }
@@ -443,7 +441,6 @@
443 * because path finding is flaky during map loading.441 * because path finding is flaky during map loading.
444 */442 */
445void Fleet::connect_port(EditorGameBase& egbase, uint32_t idx) {443void Fleet::connect_port(EditorGameBase& egbase, uint32_t idx) {
446 Map& map = egbase.map();
447 StepEvalFindPorts se;444 StepEvalFindPorts se;
448445
449 for (uint32_t i = 0; i < ports_.size(); ++i) {446 for (uint32_t i = 0; i < ports_.size(); ++i) {
@@ -463,7 +460,7 @@
463 if (se.targets.empty())460 if (se.targets.empty())
464 return;461 return;
465462
466 MapAStar<StepEvalFindPorts> astar(map, se);463 MapAStar<StepEvalFindPorts> astar(*egbase.mutable_map(), se);
467464
468 BaseImmovable::PositionList src(ports_[idx]->get_positions(egbase));465 BaseImmovable::PositionList src(ports_[idx]->get_positions(egbase));
469 for (const Coords& temp_pos : src) {466 for (const Coords& temp_pos : src) {
470467
=== modified file 'src/economy/road.cc'
--- src/economy/road.cc 2017-04-23 12:11:19 +0000
+++ src/economy/road.cc 2017-08-20 12:33:35 +0000
@@ -109,7 +109,7 @@
109}109}
110110
111BaseImmovable::PositionList Road::get_positions(const EditorGameBase& egbase) const {111BaseImmovable::PositionList Road::get_positions(const EditorGameBase& egbase) const {
112 Map& map = egbase.map();112 const Map& map = egbase.map();
113 Coords curf = map.get_fcoords(path_.get_start());113 Coords curf = map.get_fcoords(path_.get_start());
114114
115 PositionList rv;115 PositionList rv;
@@ -155,7 +155,7 @@
155 * Add road markings to the map155 * Add road markings to the map
156*/156*/
157void Road::mark_map(EditorGameBase& egbase) {157void Road::mark_map(EditorGameBase& egbase) {
158 Map& map = egbase.map();158 const Map& map = egbase.map();
159 FCoords curf = map.get_fcoords(path_.get_start());159 FCoords curf = map.get_fcoords(path_.get_start());
160160
161 const Path::StepVector::size_type nr_steps = path_.get_nsteps();161 const Path::StepVector::size_type nr_steps = path_.get_nsteps();
@@ -189,7 +189,7 @@
189 * Remove road markings from the map189 * Remove road markings from the map
190*/190*/
191void Road::unmark_map(EditorGameBase& egbase) {191void Road::unmark_map(EditorGameBase& egbase) {
192 Map& map = egbase.map();192 const Map& map = egbase.map();
193 FCoords curf(path_.get_start(), &map[path_.get_start()]);193 FCoords curf(path_.get_start(), &map[path_.get_start()]);
194194
195 const Path::StepVector::size_type nr_steps = path_.get_nsteps();195 const Path::StepVector::size_type nr_steps = path_.get_nsteps();
@@ -425,7 +425,7 @@
425 oldend.detach_road(flagidx_[FlagEnd]);425 oldend.detach_road(flagidx_[FlagEnd]);
426426
427 // build our new path and the new road's path427 // build our new path and the new road's path
428 Map& map = game.map();428 const Map& map = game.map();
429 CoordPath path(map, path_);429 CoordPath path(map, path_);
430 CoordPath secondpath(path);430 CoordPath secondpath(path);
431 int32_t const index = path.get_index(flag.get_position());431 int32_t const index = path.get_index(flag.get_position());
432432
=== modified file 'src/economy/test/test_road.cc'
--- src/economy/test/test_road.cc 2017-06-22 16:49:12 +0000
+++ src/economy/test/test_road.cc 2017-08-20 12:33:35 +0000
@@ -45,14 +45,6 @@
45 set_flag_position(c);45 set_flag_position(c);
46 }46 }
47};47};
48struct TestingMap : public Map {
49 TestingMap(int const w, int const h) : Map() {
50 set_size(w, h);
51 }
52
53 void recalc_for_field_area(const World&, Area<FCoords>) override {
54 }
55};
5648
57/*************************************************************************/49/*************************************************************************/
58/* TESTS */50/* TESTS */
@@ -69,11 +61,9 @@
6961
70struct SimpleRoadTestsFixture : public WlTestFixture {62struct SimpleRoadTestsFixture : public WlTestFixture {
71 SimpleRoadTestsFixture() : g(nullptr), path(Coords(5, 5)) {63 SimpleRoadTestsFixture() : g(nullptr), path(Coords(5, 5)) {
72 map = new TestingMap(32, 32);64 g.mutable_map()->set_size(32, 32);
73 g.set_map(map);65 path.append(g.map(), WALK_E);
7466 path.append(g.map(), WALK_E);
75 path.append(*map, WALK_E);
76 path.append(*map, WALK_E);
7767
78 start = new TestingFlag(g, Coords(5, 5));68 start = new TestingFlag(g, Coords(5, 5));
79 end = new TestingFlag(g, Coords(7, 5));69 end = new TestingFlag(g, Coords(7, 5));
@@ -84,7 +74,6 @@
84 // Map is deleted by EditorGameBase74 // Map is deleted by EditorGameBase
85 }75 }
8676
87 TestingMap* map;
88 EditorGameBase g;77 EditorGameBase g;
89 Road r;78 Road r;
90 Path path;79 Path path;
9180
=== modified file 'src/editor/editorinteractive.cc'
--- src/editor/editorinteractive.cc 2017-08-17 15:34:45 +0000
+++ src/editor/editorinteractive.cc 2017-08-20 12:33:35 +0000
@@ -177,21 +177,21 @@
177}177}
178178
179void EditorInteractive::register_overlays() {179void EditorInteractive::register_overlays() {
180 Widelands::Map& map = egbase().map();180 Widelands::Map* map = egbase().mutable_map();
181181
182 // Starting locations182 // Starting locations
183 Widelands::PlayerNumber const nr_players = map.get_nrplayers();183 Widelands::PlayerNumber const nr_players = map->get_nrplayers();
184 assert(nr_players <= kMaxPlayers);184 assert(nr_players <= kMaxPlayers);
185 iterate_player_numbers(p, nr_players) {185 iterate_player_numbers(p, nr_players) {
186 if (Widelands::Coords const sp = map.get_starting_pos(p)) {186 if (Widelands::Coords const sp = map->get_starting_pos(p)) {
187 tools_->set_starting_pos.set_starting_pos(*this, p, sp, &map);187 tools_->set_starting_pos.set_starting_pos(*this, p, sp, map);
188 }188 }
189 }189 }
190190
191 // Resources: we do not calculate default resources, therefore we do not191 // Resources: we do not calculate default resources, therefore we do not
192 // expect to meet them here.192 // expect to meet them here.
193 Widelands::Extent const extent = map.extent();193 Widelands::Extent const extent = map->extent();
194 iterate_Map_FCoords(map, extent, fc) {194 iterate_Map_FCoords(*map, extent, fc) {
195 if (uint8_t const amount = fc.field->get_resources_amount()) {195 if (uint8_t const amount = fc.field->get_resources_amount()) {
196 const std::string& immname =196 const std::string& immname =
197 egbase().world().get_resource(fc.field->get_resources())->editor_image(amount);197 egbase().world().get_resource(fc.field->get_resources())->editor_image(amount);
@@ -206,11 +206,11 @@
206void EditorInteractive::load(const std::string& filename) {206void EditorInteractive::load(const std::string& filename) {
207 assert(filename.size());207 assert(filename.size());
208208
209 Widelands::Map& map = egbase().map();209 Widelands::Map* map = egbase().mutable_map();
210210
211 cleanup_for_load();211 cleanup_for_load();
212212
213 std::unique_ptr<Widelands::MapLoader> ml(map.get_correct_loader(filename));213 std::unique_ptr<Widelands::MapLoader> ml(map->get_correct_loader(filename));
214 if (!ml.get())214 if (!ml.get())
215 throw WLWarning(215 throw WLWarning(
216 _("Unsupported format"),216 _("Unsupported format"),
@@ -228,8 +228,8 @@
228228
229 // Create the players. TODO(SirVer): this must be managed better229 // Create the players. TODO(SirVer): this must be managed better
230 loader_ui.step(_("Creating players"));230 loader_ui.step(_("Creating players"));
231 iterate_player_numbers(p, map.get_nrplayers()) {231 iterate_player_numbers(p, map->get_nrplayers()) {
232 egbase().add_player(p, 0, map.get_scenario_player_tribe(p), map.get_scenario_player_name(p));232 egbase().add_player(p, 0, map->get_scenario_player_tribe(p), map->get_scenario_player_name(p));
233 }233 }
234234
235 ml->load_map_complete(egbase(), Widelands::MapLoader::LoadType::kEditor);235 ml->load_map_complete(egbase(), Widelands::MapLoader::LoadType::kEditor);
@@ -288,8 +288,8 @@
288}288}
289289
290void EditorInteractive::map_clicked(bool should_draw) {290void EditorInteractive::map_clicked(bool should_draw) {
291 history_->do_action(tools_->current(), tools_->use_tool, egbase().map(), egbase().world(),291 history_->do_action(tools_->current(), tools_->use_tool, *egbase().mutable_map(),
292 get_sel_pos(), *this, should_draw);292 egbase().world(), get_sel_pos(), *this, should_draw);
293 set_need_save(true);293 set_need_save(true);
294}294}
295295
@@ -523,11 +523,10 @@
523 toolsize_menu.update(toolsize_menu.value());523 toolsize_menu.update(toolsize_menu.value());
524 }524 }
525 }525 }
526 Widelands::Map& map = egbase().map();
527 // A new tool has been selected. Remove all registered overlay callback526 // A new tool has been selected. Remove all registered overlay callback
528 // functions.527 // functions.
529 mutable_field_overlay_manager()->register_overlay_callback_function(nullptr);528 mutable_field_overlay_manager()->register_overlay_callback_function(nullptr);
530 map.recalc_whole_map(egbase().world());529 egbase().mutable_map()->recalc_whole_map(egbase().world());
531 }530 }
532 tools_->current_pointer = &primary;531 tools_->current_pointer = &primary;
533 tools_->use_tool = which;532 tools_->use_tool = which;
@@ -603,16 +602,15 @@
603 GameTips editortips(loader_ui, tipstext);602 GameTips editortips(loader_ui, tipstext);
604603
605 {604 {
606 Widelands::Map& map = *new Widelands::Map;
607 egbase.set_map(&map);
608 if (filename.empty()) {605 if (filename.empty()) {
609 loader_ui.step(_("Creating empty map…"));606 loader_ui.step(_("Creating empty map…"));
610 map.create_empty_map(egbase.world(), 64, 64, 0,607 egbase.mutable_map()->create_empty_map(
611 /** TRANSLATORS: Default name for new map */608 egbase.world(), 64, 64, 0,
612 _("No Name"),609 /** TRANSLATORS: Default name for new map */
613 /** TRANSLATORS: Map author name when it hasn't been set yet */610 _("No Name"),
614 g_options.pull_section("global").get_string(611 /** TRANSLATORS: Map author name when it hasn't been set yet */
615 "realname", pgettext("author_name", "Unknown")));612 g_options.pull_section("global").get_string(
613 "realname", pgettext("author_name", "Unknown")));
616614
617 load_all_tribes(&egbase, &loader_ui);615 load_all_tribes(&egbase, &loader_ui);
618616
619617
=== modified file 'src/editor/ui_menus/main_menu_map_options.cc'
--- src/editor/ui_menus/main_menu_map_options.cc 2017-06-11 20:09:05 +0000
+++ src/editor/ui_menus/main_menu_map_options.cc 2017-08-20 12:33:35 +0000
@@ -193,16 +193,16 @@
193}193}
194194
195void MainMenuMapOptions::clicked_ok() {195void MainMenuMapOptions::clicked_ok() {
196 eia().egbase().map().set_name(name_.text());196 eia().egbase().mutable_map()->set_name(name_.text());
197 eia().egbase().map().set_author(author_.text());197 eia().egbase().mutable_map()->set_author(author_.text());
198 g_options.pull_section("global").set_string("realname", author_.text());198 g_options.pull_section("global").set_string("realname", author_.text());
199 eia().egbase().map().set_description(descr_->get_text());199 eia().egbase().mutable_map()->set_description(descr_->get_text());
200 eia().egbase().map().set_hint(hint_->get_text());200 eia().egbase().mutable_map()->set_hint(hint_->get_text());
201201
202 eia().egbase().map().clear_tags();202 eia().egbase().mutable_map()->clear_tags();
203 for (const auto& tag : tags_checkboxes_) {203 for (const auto& tag : tags_checkboxes_) {
204 if (tag.second->get_state()) {204 if (tag.second->get_state()) {
205 eia().egbase().map().add_tag(tag.first);205 eia().egbase().mutable_map()->add_tag(tag.first);
206 }206 }
207 }207 }
208208
209209
=== modified file 'src/editor/ui_menus/main_menu_new_map.cc'
--- src/editor/ui_menus/main_menu_new_map.cc 2017-02-25 11:17:28 +0000
+++ src/editor/ui_menus/main_menu_new_map.cc 2017-08-20 12:33:35 +0000
@@ -138,14 +138,14 @@
138void MainMenuNewMap::clicked_create_map() {138void MainMenuNewMap::clicked_create_map() {
139 EditorInteractive& parent = eia();139 EditorInteractive& parent = eia();
140 Widelands::EditorGameBase& egbase = parent.egbase();140 Widelands::EditorGameBase& egbase = parent.egbase();
141 Widelands::Map& map = egbase.map();141 Widelands::Map* map = egbase.mutable_map();
142 UI::ProgressWindow loader_ui;142 UI::ProgressWindow loader_ui;
143143
144 loader_ui.step(_("Creating empty map…"));144 loader_ui.step(_("Creating empty map…"));
145145
146 parent.cleanup_for_load();146 parent.cleanup_for_load();
147147
148 map.create_empty_map(148 map->create_empty_map(
149 egbase.world(), width_.get_value() > 0 ? width_.get_value() : Widelands::kMapDimensions[0],149 egbase.world(), width_.get_value() > 0 ? width_.get_value() : Widelands::kMapDimensions[0],
150 height_.get_value() > 0 ? height_.get_value() : Widelands::kMapDimensions[0],150 height_.get_value() > 0 ? height_.get_value() : Widelands::kMapDimensions[0],
151 list_.get_selected(), _("No Name"),151 list_.get_selected(), _("No Name"),
@@ -154,7 +154,7 @@
154 egbase.postload();154 egbase.postload();
155 egbase.load_graphics(loader_ui);155 egbase.load_graphics(loader_ui);
156156
157 map.recalc_whole_map(egbase.world());157 map->recalc_whole_map(egbase.world());
158 parent.map_changed(EditorInteractive::MapWas::kReplaced);158 parent.map_changed(EditorInteractive::MapWas::kReplaced);
159 die();159 die();
160}160}
161161
=== modified file 'src/editor/ui_menus/main_menu_random_map.cc'
--- src/editor/ui_menus/main_menu_random_map.cc 2017-06-20 08:18:38 +0000
+++ src/editor/ui_menus/main_menu_random_map.cc 2017-08-20 12:33:35 +0000
@@ -231,8 +231,7 @@
231 width_.set_value_list(Widelands::kMapDimensions);231 width_.set_value_list(Widelands::kMapDimensions);
232 height_.set_value_list(Widelands::kMapDimensions);232 height_.set_value_list(Widelands::kMapDimensions);
233 {233 {
234 const Widelands::Map& map = parent.egbase().map();234 Widelands::Extent const map_extent = parent.egbase().map().extent();
235 Widelands::Extent const map_extent = map.extent();
236 width_.set_value(find_dimension_index(map_extent.w));235 width_.set_value(find_dimension_index(map_extent.w));
237 height_.set_value(find_dimension_index(map_extent.h));236 height_.set_value(find_dimension_index(map_extent.h));
238 }237 }
@@ -512,7 +511,7 @@
512 cancel_button_.set_enabled(false);511 cancel_button_.set_enabled(false);
513 EditorInteractive& eia = dynamic_cast<EditorInteractive&>(*get_parent());512 EditorInteractive& eia = dynamic_cast<EditorInteractive&>(*get_parent());
514 Widelands::EditorGameBase& egbase = eia.egbase();513 Widelands::EditorGameBase& egbase = eia.egbase();
515 Widelands::Map& map = egbase.map();514 Widelands::Map* map = egbase.mutable_map();
516 UI::ProgressWindow loader_ui;515 UI::ProgressWindow loader_ui;
517516
518 eia.cleanup_for_load();517 eia.cleanup_for_load();
@@ -528,12 +527,12 @@
528 << "Resources = " << resources_.get_title() << "\n"527 << "Resources = " << resources_.get_title() << "\n"
529 << "ID = " << map_id_edit_.text() << "\n";528 << "ID = " << map_id_edit_.text() << "\n";
530529
531 MapGenerator gen(map, map_info, egbase);530 MapGenerator gen(*map, map_info, egbase);
532 map.create_empty_map(531 map->create_empty_map(
533 egbase.world(), map_info.w, map_info.h, 0, _("No Name"),532 egbase.world(), map_info.w, map_info.h, 0, _("No Name"),
534 g_options.pull_section("global").get_string("realname", pgettext("author_name", "Unknown")),533 g_options.pull_section("global").get_string("realname", pgettext("author_name", "Unknown")),
535 sstrm.str().c_str());534 sstrm.str().c_str());
536 loader_ui.step(_("Generating random map…"));535 loader_ui.step(_("Generating random map…"));
537536
538 log("============== Generating Map ==============\n");537 log("============== Generating Map ==============\n");
539 log("ID: %s\n", map_id_edit_.text().c_str());538 log("ID: %s\n", map_id_edit_.text().c_str());
@@ -564,7 +563,7 @@
564 egbase.postload();563 egbase.postload();
565 egbase.load_graphics(loader_ui);564 egbase.load_graphics(loader_ui);
566565
567 map.recalc_whole_map(egbase.world());566 map->recalc_whole_map(egbase.world());
568 eia.map_changed(EditorInteractive::MapWas::kReplaced);567 eia.map_changed(EditorInteractive::MapWas::kReplaced);
569 UI::WLMessageBox mbox(568 UI::WLMessageBox mbox(
570 &eia,569 &eia,
571570
=== modified file 'src/editor/ui_menus/main_menu_save_map.cc'
--- src/editor/ui_menus/main_menu_save_map.cc 2017-02-26 12:16:09 +0000
+++ src/editor/ui_menus/main_menu_save_map.cc 2017-08-20 12:33:35 +0000
@@ -129,10 +129,10 @@
129 set_current_directory(complete_filename);129 set_current_directory(complete_filename);
130 fill_table();130 fill_table();
131 } else { // Ok, save this map131 } else { // Ok, save this map
132 Widelands::Map& map = eia().egbase().map();132 Widelands::Map* map = eia().egbase().mutable_map();
133 if (map.get_name() == _("No Name")) {133 if (map->get_name() == _("No Name")) {
134 std::string::size_type const filename_size = filename.size();134 std::string::size_type const filename_size = filename.size();
135 map.set_name(4 <= filename_size && boost::iends_with(filename, WLMF_SUFFIX) ?135 map->set_name(4 <= filename_size && boost::iends_with(filename, WLMF_SUFFIX) ?
136 filename.substr(0, filename_size - 4) :136 filename.substr(0, filename_size - 4) :
137 filename);137 filename);
138 }138 }
@@ -272,23 +272,23 @@
272 }272 }
273273
274 Widelands::EditorGameBase& egbase = eia().egbase();274 Widelands::EditorGameBase& egbase = eia().egbase();
275 Widelands::Map& map = egbase.map();275 Widelands::Map* map = egbase.mutable_map();
276276
277 { // fs scope277 { // fs scope
278 std::unique_ptr<FileSystem> fs(278 std::unique_ptr<FileSystem> fs(
279 g_fs->create_sub_file_system(tmp_name, binary ? FileSystem::ZIP : FileSystem::DIR));279 g_fs->create_sub_file_system(tmp_name, binary ? FileSystem::ZIP : FileSystem::DIR));
280280
281 // Recompute seafaring tag281 // Recompute seafaring tag
282 if (map.allows_seafaring()) {282 if (map->allows_seafaring()) {
283 map.add_tag("seafaring");283 map->add_tag("seafaring");
284 } else {284 } else {
285 map.delete_tag("seafaring");285 map->delete_tag("seafaring");
286 }286 }
287287
288 if (map.has_artifacts()) {288 if (map->has_artifacts()) {
289 map.add_tag("artifacts");289 map->add_tag("artifacts");
290 } else {290 } else {
291 map.delete_tag("artifacts");291 map->delete_tag("artifacts");
292 }292 }
293293
294 try {294 try {
@@ -297,14 +297,14 @@
297 delete wms;297 delete wms;
298 // Reset filesystem to avoid file locks on saves298 // Reset filesystem to avoid file locks on saves
299 fs.reset();299 fs.reset();
300 map.reset_filesystem();300 map->reset_filesystem();
301 eia().set_need_save(false);301 eia().set_need_save(false);
302 g_fs->fs_unlink(complete_filename);302 g_fs->fs_unlink(complete_filename);
303 g_fs->fs_rename(tmp_name, complete_filename);303 g_fs->fs_rename(tmp_name, complete_filename);
304 // Also change fs, as we assign it to the map below304 // Also change fs, as we assign it to the map below
305 fs.reset(g_fs->make_sub_file_system(complete_filename));305 fs.reset(g_fs->make_sub_file_system(complete_filename));
306 // Set the filesystem of the map to the current save file / directory306 // Set the filesystem of the map to the current save file / directory
307 map.swap_filesystem(fs);307 map->swap_filesystem(fs);
308 // DONT use fs as of here, its garbage now!308 // DONT use fs as of here, its garbage now!
309309
310 } catch (const std::exception& e) {310 } catch (const std::exception& e) {
311311
=== modified file 'src/editor/ui_menus/player_menu.cc'
--- src/editor/ui_menus/player_menu.cc 2017-08-18 02:28:27 +0000
+++ src/editor/ui_menus/player_menu.cc 2017-08-20 12:33:35 +0000
@@ -110,8 +110,8 @@
110 if (is_minimal())110 if (is_minimal())
111 return;111 return;
112112
113 Widelands::Map& map = eia().egbase().map();113 Widelands::Map* map = eia().egbase().mutable_map();
114 Widelands::PlayerNumber const nr_players = map.get_nrplayers();114 Widelands::PlayerNumber const nr_players = map->get_nrplayers();
115 {115 {
116 assert(nr_players <= 99); // 2 decimal digits116 assert(nr_players <= 99); // 2 decimal digits
117 char text[3];117 char text[3];
@@ -147,7 +147,7 @@
147 plr_names_[p - 1]->changed.connect(147 plr_names_[p - 1]->changed.connect(
148 boost::bind(&EditorPlayerMenu::name_changed, this, p - 1));148 boost::bind(&EditorPlayerMenu::name_changed, this, p - 1));
149 posx += 140 + spacing;149 posx += 140 + spacing;
150 plr_names_[p - 1]->set_text(map.get_scenario_player_name(p));150 plr_names_[p - 1]->set_text(map->get_scenario_player_name(p));
151 }151 }
152152
153 if (!plr_set_tribes_buts_[p - 1]) {153 if (!plr_set_tribes_buts_[p - 1]) {
@@ -160,19 +160,19 @@
160 }160 }
161161
162 // Get/Set (localized) tribe names162 // Get/Set (localized) tribe names
163 if (map.get_scenario_player_tribe(p) != UNDEFINED_TRIBE_NAME) {163 if (map->get_scenario_player_tribe(p) != UNDEFINED_TRIBE_NAME) {
164 selected_tribes_[p - 1] = map.get_scenario_player_tribe(p);164 selected_tribes_[p - 1] = map->get_scenario_player_tribe(p);
165 } else {165 } else {
166 selected_tribes_[p - 1] = tribenames_[0];166 selected_tribes_[p - 1] = tribenames_[0];
167 map.set_scenario_player_tribe(p, selected_tribes_[p - 1]);167 map->set_scenario_player_tribe(p, selected_tribes_[p - 1]);
168 }168 }
169169
170 plr_set_tribes_buts_[p - 1]->set_title(170 plr_set_tribes_buts_[p - 1]->set_title(
171 Widelands::get_tribeinfo(selected_tribes_[p - 1]).descname);171 Widelands::get_tribeinfo(selected_tribes_[p - 1]).descname);
172172
173 // Set default AI and closeable to false (always default - should be changed by hand)173 // Set default AI and closeable to false (always default - should be changed by hand)
174 map.set_scenario_player_ai(p, "");174 map->set_scenario_player_ai(p, "");
175 map.set_scenario_player_closeable(p, false);175 map->set_scenario_player_closeable(p, false);
176176
177 // Set Starting pos button.177 // Set Starting pos button.
178 if (!plr_set_pos_buts_[p - 1]) {178 if (!plr_set_pos_buts_[p - 1]) {
@@ -195,18 +195,18 @@
195}195}
196196
197void EditorPlayerMenu::clicked_add_player() {197void EditorPlayerMenu::clicked_add_player() {
198 Widelands::Map& map = eia().egbase().map();198 Widelands::Map* map = eia().egbase().mutable_map();
199 Widelands::PlayerNumber const nr_players = map.get_nrplayers() + 1;199 Widelands::PlayerNumber const nr_players = map->get_nrplayers() + 1;
200 assert(nr_players <= kMaxPlayers);200 assert(nr_players <= kMaxPlayers);
201 map.set_nrplayers(nr_players);201 map->set_nrplayers(nr_players);
202 { // register new default name for this players202 { // register new default name for this players
203 assert(nr_players <= 99); // 2 decimal digits203 assert(nr_players <= 99); // 2 decimal digits
204 /** TRANSLATORS: Default player name, e.g. Player 1 */204 /** TRANSLATORS: Default player name, e.g. Player 1 */
205 const std::string name =205 const std::string name =
206 (boost::format(_("Player %u")) % static_cast<unsigned int>(nr_players)).str();206 (boost::format(_("Player %u")) % static_cast<unsigned int>(nr_players)).str();
207 map.set_scenario_player_name(nr_players, name);207 map->set_scenario_player_name(nr_players, name);
208 }208 }
209 map.set_scenario_player_tribe(nr_players, tribenames_[0]);209 map->set_scenario_player_tribe(nr_players, tribenames_[0]);
210 eia().set_need_save(true);210 eia().set_need_save(true);
211 add_player_.set_enabled(nr_players < kMaxPlayers);211 add_player_.set_enabled(nr_players < kMaxPlayers);
212 remove_last_player_.set_enabled(true);212 remove_last_player_.set_enabled(true);
@@ -215,13 +215,13 @@
215215
216void EditorPlayerMenu::clicked_remove_last_player() {216void EditorPlayerMenu::clicked_remove_last_player() {
217 EditorInteractive& menu = eia();217 EditorInteractive& menu = eia();
218 Widelands::Map& map = menu.egbase().map();218 Widelands::Map* map = menu.egbase().mutable_map();
219 Widelands::PlayerNumber const old_nr_players = map.get_nrplayers();219 Widelands::PlayerNumber const old_nr_players = map->get_nrplayers();
220 Widelands::PlayerNumber const nr_players = old_nr_players - 1;220 Widelands::PlayerNumber const nr_players = old_nr_players - 1;
221 assert(1 <= nr_players);221 assert(1 <= nr_players);
222222
223 if (!menu.is_player_tribe_referenced(old_nr_players)) {223 if (!menu.is_player_tribe_referenced(old_nr_players)) {
224 if (const Widelands::Coords sp = map.get_starting_pos(old_nr_players)) {224 if (const Widelands::Coords sp = map->get_starting_pos(old_nr_players)) {
225 // Remove starting position marker.225 // Remove starting position marker.
226 const Image* player_image =226 const Image* player_image =
227 playercolor_image(old_nr_players - 1, "images/players/player_position.png");227 playercolor_image(old_nr_players - 1, "images/players/player_position.png");
@@ -232,7 +232,7 @@
232 if (old_nr_players == menu.tools()->set_starting_pos.get_current_player())232 if (old_nr_players == menu.tools()->set_starting_pos.get_current_player())
233 set_starting_pos_clicked(nr_players);233 set_starting_pos_clicked(nr_players);
234 }234 }
235 map.set_nrplayers(nr_players);235 map->set_nrplayers(nr_players);
236 add_player_.set_enabled(nr_players < kMaxPlayers);236 add_player_.set_enabled(nr_players < kMaxPlayers);
237 remove_last_player_.set_enabled(1 < nr_players);237 remove_last_player_.set_enabled(1 < nr_players);
238 update();238 update();
@@ -257,7 +257,7 @@
257 }257 }
258 }258 }
259 selected_tribes_[n] = i == tribenames_.size() - 1 ? tribenames_[0] : tribenames_[++i];259 selected_tribes_[n] = i == tribenames_.size() - 1 ? tribenames_[0] : tribenames_[++i];
260 menu.egbase().map().set_scenario_player_tribe(n + 1, selected_tribes_[n]);260 menu.egbase().mutable_map()->set_scenario_player_tribe(n + 1, selected_tribes_[n]);
261 menu.set_need_save(true);261 menu.set_need_save(true);
262 } else {262 } else {
263 UI::WLMessageBox mmb(&menu, _("Error!"),263 UI::WLMessageBox mmb(&menu, _("Error!"),
@@ -275,8 +275,8 @@
275void EditorPlayerMenu::set_starting_pos_clicked(uint8_t n) {275void EditorPlayerMenu::set_starting_pos_clicked(uint8_t n) {
276 EditorInteractive& menu = eia();276 EditorInteractive& menu = eia();
277 // jump to the current node277 // jump to the current node
278 Widelands::Map& map = menu.egbase().map();278 Widelands::Map* map = menu.egbase().mutable_map();
279 if (Widelands::Coords const sp = map.get_starting_pos(n)) {279 if (Widelands::Coords const sp = map->get_starting_pos(n)) {
280 menu.map_view()->scroll_to_field(sp, MapView::Transition::Smooth);280 menu.map_view()->scroll_to_field(sp, MapView::Transition::Smooth);
281 }281 }
282282
@@ -290,8 +290,8 @@
290 // Register callback function to make sure that only valid locations are290 // Register callback function to make sure that only valid locations are
291 // selected.291 // selected.
292 menu.mutable_field_overlay_manager()->register_overlay_callback_function(292 menu.mutable_field_overlay_manager()->register_overlay_callback_function(
293 boost::bind(&editor_tool_set_starting_pos_callback, _1, boost::ref(map)));293 boost::bind(&editor_tool_set_starting_pos_callback, _1, boost::ref(*map)));
294 map.recalc_whole_map(menu.egbase().world());294 map->recalc_whole_map(menu.egbase().world());
295 update();295 update();
296}296}
297297
@@ -302,8 +302,8 @@
302 // Player name has been changed.302 // Player name has been changed.
303 std::string text = plr_names_[m]->text();303 std::string text = plr_names_[m]->text();
304 EditorInteractive& menu = eia();304 EditorInteractive& menu = eia();
305 Widelands::Map& map = menu.egbase().map();305 Widelands::Map* map = menu.egbase().mutable_map();
306 map.set_scenario_player_name(m + 1, text);306 map->set_scenario_player_name(m + 1, text);
307 plr_names_[m]->set_text(map.get_scenario_player_name(m + 1));307 plr_names_[m]->set_text(map->get_scenario_player_name(m + 1));
308 menu.set_need_save(true);308 menu.set_need_save(true);
309}309}
310310
=== modified file 'src/editor/ui_menus/tool_change_resources_options_menu.cc'
--- src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-08-13 18:02:53 +0000
+++ src/editor/ui_menus/tool_change_resources_options_menu.cc 2017-08-20 12:33:35 +0000
@@ -154,16 +154,16 @@
154 increase_tool_.decrease_tool().set_cur_res(resource_index);154 increase_tool_.decrease_tool().set_cur_res(resource_index);
155155
156 Widelands::EditorGameBase& egbase = eia().egbase();156 Widelands::EditorGameBase& egbase = eia().egbase();
157 Widelands::Map& map = egbase.map();157 Widelands::Map* map = egbase.mutable_map();
158 eia().mutable_field_overlay_manager()->register_overlay_callback_function(158 eia().mutable_field_overlay_manager()->register_overlay_callback_function(
159 [resource_index, &map, &egbase](const Widelands::FCoords& fc) -> uint32_t {159 [resource_index, map, &egbase](const Widelands::FCoords& fc) -> uint32_t {
160 if (map.is_resource_valid(egbase.world(), fc, resource_index)) {160 if (map->is_resource_valid(egbase.world(), fc, resource_index)) {
161 return fc.field->nodecaps();161 return fc.field->nodecaps();
162 }162 }
163 return 0;163 return 0;
164 });164 });
165165
166 map.recalc_whole_map(egbase.world());166 map->recalc_whole_map(egbase.world());
167 select_correct_tool();167 select_correct_tool();
168 update();168 update();
169}169}
170170
=== modified file 'src/editor/ui_menus/tool_menu.cc'
--- src/editor/ui_menus/tool_menu.cc 2017-08-13 18:02:53 +0000
+++ src/editor/ui_menus/tool_menu.cc 2017-08-20 12:33:35 +0000
@@ -142,10 +142,10 @@
142 parent.select_tool(*current_tool_pointer, EditorTool::First);142 parent.select_tool(*current_tool_pointer, EditorTool::First);
143 if (current_tool_pointer == &parent.tools()->set_port_space) {143 if (current_tool_pointer == &parent.tools()->set_port_space) {
144 // Set correct overlay144 // Set correct overlay
145 Widelands::Map& map = parent.egbase().map();145 Widelands::Map* map = parent.egbase().mutable_map();
146 parent.mutable_field_overlay_manager()->register_overlay_callback_function(146 parent.mutable_field_overlay_manager()->register_overlay_callback_function(
147 boost::bind(&editor_tool_set_port_space_callback, _1, boost::ref(map)));147 boost::bind(&editor_tool_set_port_space_callback, _1, boost::ref(*map)));
148 map.recalc_whole_map(parent.egbase().world());148 map->recalc_whole_map(parent.egbase().world());
149 }149 }
150150
151 if (current_registry_pointer) {151 if (current_registry_pointer) {
152152
=== modified file 'src/game_io/game_map_packet.cc'
--- src/game_io/game_map_packet.cc 2017-01-25 18:55:59 +0000
+++ src/game_io/game_map_packet.cc 2017-08-20 12:33:35 +0000
@@ -41,7 +41,7 @@
41 // Now Load the map as it would be a normal map saving.41 // Now Load the map as it would be a normal map saving.
42 delete wml_;42 delete wml_;
4343
44 wml_ = new WidelandsMapLoader(fs.make_sub_file_system("map"), &game.map());44 wml_ = new WidelandsMapLoader(fs.make_sub_file_system("map"), game.mutable_map());
4545
46 wml_->preload_map(true);46 wml_->preload_map(true);
4747
4848
=== modified file 'src/game_io/game_player_ai_persistent_packet.cc'
--- src/game_io/game_player_ai_persistent_packet.cc 2017-06-28 08:50:42 +0000
+++ src/game_io/game_player_ai_persistent_packet.cc 2017-08-20 12:33:35 +0000
@@ -32,8 +32,7 @@
3232
33void GamePlayerAiPersistentPacket::read(FileSystem& fs, Game& game, MapObjectLoader*) {33void GamePlayerAiPersistentPacket::read(FileSystem& fs, Game& game, MapObjectLoader*) {
34 try {34 try {
35 const Map& map = game.map();35 PlayerNumber const nr_players = game.map().get_nrplayers();
36 PlayerNumber const nr_players = map.get_nrplayers();
3736
38 FileRead fr;37 FileRead fr;
39 fr.open(fs, "binary/player_ai");38 fr.open(fs, "binary/player_ai");
@@ -125,8 +124,7 @@
125124
126 fw.unsigned_16(kCurrentPacketVersion);125 fw.unsigned_16(kCurrentPacketVersion);
127126
128 const Map& map = game.map();127 PlayerNumber const nr_players = game.map().get_nrplayers();
129 PlayerNumber const nr_players = map.get_nrplayers();
130 iterate_players_existing_const(p, nr_players, game, player) {128 iterate_players_existing_const(p, nr_players, game, player) {
131 fw.unsigned_8(player->ai_data.initialized);129 fw.unsigned_8(player->ai_data.initialized);
132 fw.unsigned_32(player->ai_data.colony_scan_area);130 fw.unsigned_32(player->ai_data.colony_scan_area);
133131
=== modified file 'src/graphic/game_renderer.cc'
--- src/graphic/game_renderer.cc 2017-08-16 08:59:09 +0000
+++ src/graphic/game_renderer.cc 2017-08-20 12:33:35 +0000
@@ -340,7 +340,7 @@
340 const int surface_width = surface->width();340 const int surface_width = surface->width();
341 const int surface_height = surface->height();341 const int surface_height = surface->height();
342342
343 Map& map = egbase.map();343 const Map& map = egbase.map();
344 const uint32_t gametime = egbase.get_gametime();344 const uint32_t gametime = egbase.get_gametime();
345345
346 const float scale = 1.f / zoom;346 const float scale = 1.f / zoom;
347347
=== modified file 'src/graphic/minimap_renderer.cc'
--- src/graphic/minimap_renderer.cc 2017-08-09 19:25:04 +0000
+++ src/graphic/minimap_renderer.cc 2017-08-20 12:33:35 +0000
@@ -158,7 +158,7 @@
158 const Widelands::Map& map = egbase.map();158 const Widelands::Map& map = egbase.map();
159 const uint16_t surface_h = texture->height();159 const uint16_t surface_h = texture->height();
160 const uint16_t surface_w = texture->width();160 const uint16_t surface_w = texture->width();
161 const int32_t mapwidth = egbase.get_map().get_width();161 const int32_t mapwidth = map.get_width();
162162
163 for (uint32_t y = 0; y < surface_h; ++y) {163 for (uint32_t y = 0; y < surface_h; ++y) {
164 Widelands::FCoords f(164 Widelands::FCoords f(
165165
=== modified file 'src/logic/editor_game_base.cc'
--- src/logic/editor_game_base.cc 2017-06-25 08:20:25 +0000
+++ src/logic/editor_game_base.cc 2017-08-20 12:33:35 +0000
@@ -67,14 +67,12 @@
67 : gametime_(0),67 : gametime_(0),
68 lua_(lua_interface),68 lua_(lua_interface),
69 player_manager_(new PlayersManager(*this)),69 player_manager_(new PlayersManager(*this)),
70 ibase_(nullptr),70 ibase_(nullptr) {
71 map_(nullptr) {
72 if (!lua_) // TODO(SirVer): this is sooo ugly, I can't say71 if (!lua_) // TODO(SirVer): this is sooo ugly, I can't say
73 lua_.reset(new LuaEditorInterface(this));72 lua_.reset(new LuaEditorInterface(this));
74}73}
7574
76EditorGameBase::~EditorGameBase() {75EditorGameBase::~EditorGameBase() {
77 delete map_;
78 delete player_manager_.release();76 delete player_manager_.release();
79}77}
8078
@@ -187,19 +185,6 @@
187 }185 }
188}186}
189187
190/**
191 * Replaces the current map with the given one. Ownership of the map is transferred
192 * to the EditorGameBase object.
193 */
194void EditorGameBase::set_map(Map* const new_map) {
195 assert(new_map != map_);
196 assert(new_map);
197
198 delete map_;
199
200 map_ = new_map;
201}
202
203void EditorGameBase::allocate_player_maps() {188void EditorGameBase::allocate_player_maps() {
204 iterate_players_existing(plnum, kMaxPlayers, *this, p) {189 iterate_players_existing(plnum, kMaxPlayers, *this, p) {
205 p->allocate_map();190 p->allocate_map();
@@ -412,8 +397,7 @@
412397
413 player_manager_->cleanup();398 player_manager_->cleanup();
414399
415 if (map_)400 map_.cleanup();
416 map_->cleanup();
417}401}
418402
419void EditorGameBase::set_road(const FCoords& f, uint8_t const direction, uint8_t const roadtype) {403void EditorGameBase::set_road(const FCoords& f, uint8_t const direction, uint8_t const roadtype) {
@@ -566,7 +550,7 @@
566 // This must reach one step beyond the conquered area to adjust the borders550 // This must reach one step beyond the conquered area to adjust the borders
567 // of neighbour players.551 // of neighbour players.
568 ++player_area.radius;552 ++player_area.radius;
569 map().recalc_for_field_area(world(), player_area);553 map_.recalc_for_field_area(world(), player_area);
570}554}
571555
572/// Conquers the given area for that player; does the actual work.556/// Conquers the given area for that player; does the actual work.
@@ -642,21 +626,20 @@
642 // This must reach one step beyond the conquered area to adjust the borders626 // This must reach one step beyond the conquered area to adjust the borders
643 // of neighbour players.627 // of neighbour players.
644 ++player_area.radius;628 ++player_area.radius;
645 map().recalc_for_field_area(world(), player_area);629 map_.recalc_for_field_area(world(), player_area);
646}630}
647631
648/// Makes sure that buildings cannot exist outside their owner's territory.632/// Makes sure that buildings cannot exist outside their owner's territory.
649void EditorGameBase::cleanup_playerimmovables_area(PlayerArea<Area<FCoords>> const area) {633void EditorGameBase::cleanup_playerimmovables_area(PlayerArea<Area<FCoords>> const area) {
650 std::vector<ImmovableFound> immovables;634 std::vector<ImmovableFound> immovables;
651 std::vector<PlayerImmovable*> burnlist;635 std::vector<PlayerImmovable*> burnlist;
652 Map& m = map();
653636
654 // find all immovables that need fixing637 // find all immovables that need fixing
655 m.find_immovables(area, &immovables, FindImmovablePlayerImmovable());638 map_.find_immovables(area, &immovables, FindImmovablePlayerImmovable());
656639
657 for (const ImmovableFound& temp_imm : immovables) {640 for (const ImmovableFound& temp_imm : immovables) {
658 upcast(PlayerImmovable, imm, temp_imm.object);641 upcast(PlayerImmovable, imm, temp_imm.object);
659 if (!m[temp_imm.coords].is_interior(imm->owner().player_number())) {642 if (!map_[temp_imm.coords].is_interior(imm->owner().player_number())) {
660 if (std::find(burnlist.begin(), burnlist.end(), imm) == burnlist.end()) {643 if (std::find(burnlist.begin(), burnlist.end(), imm) == burnlist.end()) {
661 burnlist.push_back(imm);644 burnlist.push_back(imm);
662 }645 }
663646
=== modified file 'src/logic/editor_game_base.h'
--- src/logic/editor_game_base.h 2017-06-25 19:12:30 +0000
+++ src/logic/editor_game_base.h 2017-08-20 12:33:35 +0000
@@ -84,16 +84,11 @@
84 explicit EditorGameBase(LuaInterface* lua);84 explicit EditorGameBase(LuaInterface* lua);
85 virtual ~EditorGameBase();85 virtual ~EditorGameBase();
8686
87 void set_map(Map*);87 const Map& map() const {
88 // TODO(sirver): this should just be const Map& map() and Map* mutable_map().
89 Map& map() const {
90 return *map_;
91 }
92 Map* get_map() {
93 return map_;88 return map_;
94 }89 }
95 Map& get_map() const {90 Map* mutable_map() {
96 return *map_;91 return &map_;
97 }92 }
98 const ObjectManager& objects() const {93 const ObjectManager& objects() const {
99 return objects_;94 return objects_;
@@ -258,7 +253,7 @@
258 std::unique_ptr<World> world_;253 std::unique_ptr<World> world_;
259 std::unique_ptr<Tribes> tribes_;254 std::unique_ptr<Tribes> tribes_;
260 std::unique_ptr<InteractiveBase> ibase_;255 std::unique_ptr<InteractiveBase> ibase_;
261 Map* map_;256 Map map_;
262257
263 DISALLOW_COPY_AND_ASSIGN(EditorGameBase);258 DISALLOW_COPY_AND_ASSIGN(EditorGameBase);
264};259};
265260
=== modified file 'src/logic/game.cc'
--- src/logic/game.cc 2017-08-18 02:28:27 +0000
+++ src/logic/game.cc 2017-08-20 12:33:35 +0000
@@ -192,14 +192,10 @@
192192
193bool Game::run_splayer_scenario_direct(const std::string& mapname,193bool Game::run_splayer_scenario_direct(const std::string& mapname,
194 const std::string& script_to_run) {194 const std::string& script_to_run) {
195 assert(!get_map());
196
197 // Replays can't handle scenarios195 // Replays can't handle scenarios
198 set_write_replay(false);196 set_write_replay(false);
199197
200 set_map(new Map);198 std::unique_ptr<MapLoader> maploader(mutable_map()->get_correct_loader(mapname));
201
202 std::unique_ptr<MapLoader> maploader(map().get_correct_loader(mapname));
203 if (!maploader)199 if (!maploader)
204 throw wexception("could not load \"%s\"", mapname.c_str());200 throw wexception("could not load \"%s\"", mapname.c_str());
205 UI::ProgressWindow loader_ui;201 UI::ProgressWindow loader_ui;
@@ -252,10 +248,7 @@
252248
253 loader_ui->step(_("Preloading map"));249 loader_ui->step(_("Preloading map"));
254250
255 assert(!get_map());251 std::unique_ptr<MapLoader> maploader(mutable_map()->get_correct_loader(settings.mapfilename));
256 set_map(new Map);
257
258 std::unique_ptr<MapLoader> maploader(map().get_correct_loader(settings.mapfilename));
259 assert(maploader != nullptr);252 assert(maploader != nullptr);
260 maploader->preload_map(settings.scenario);253 maploader->preload_map(settings.scenario);
261254
@@ -325,8 +318,6 @@
325318
326 loader_ui->step(_("Preloading map"));319 loader_ui->step(_("Preloading map"));
327320
328 assert(!get_map());
329 set_map(new Map);
330 try {321 try {
331 GameLoader gl(settings.mapfilename, *this);322 GameLoader gl(settings.mapfilename, *this);
332 Widelands::GamePreloadPacket gpdp;323 Widelands::GamePreloadPacket gpdp;
@@ -355,9 +346,6 @@
355346
356 loader_ui.step(_("Preloading map"));347 loader_ui.step(_("Preloading map"));
357348
358 // We have to create an empty map, otherwise nothing will load properly
359 set_map(new Map);
360
361 {349 {
362 GameLoader gl(filename, *this);350 GameLoader gl(filename, *this);
363351
@@ -462,7 +450,7 @@
462 }450 }
463451
464 // Prepare the map, set default textures452 // Prepare the map, set default textures
465 map().recalc_default_resources(world());453 mutable_map()->recalc_default_resources(world());
466454
467 // Finally, set the scenario names and tribes to represent455 // Finally, set the scenario names and tribes to represent
468 // the correct names of the players456 // the correct names of the players
@@ -472,10 +460,10 @@
472 const std::string& player_tribe = plr ? plr->tribe().name() : no_name;460 const std::string& player_tribe = plr ? plr->tribe().name() : no_name;
473 const std::string& player_name = plr ? plr->get_name() : no_name;461 const std::string& player_name = plr ? plr->get_name() : no_name;
474 const std::string& player_ai = plr ? plr->get_ai() : no_name;462 const std::string& player_ai = plr ? plr->get_ai() : no_name;
475 map().set_scenario_player_tribe(p, player_tribe);463 mutable_map()->set_scenario_player_tribe(p, player_tribe);
476 map().set_scenario_player_name(p, player_name);464 mutable_map()->set_scenario_player_name(p, player_name);
477 map().set_scenario_player_ai(p, player_ai);465 mutable_map()->set_scenario_player_ai(p, player_ai);
478 map().set_scenario_player_closeable(p, false); // player is already initialized.466 mutable_map()->set_scenario_player_closeable(p, false); // player is already initialized.
479 }467 }
480468
481 // Run the init script, if the map provides one.469 // Run the init script, if the map provides one.
482470
=== modified file 'src/logic/map.cc'
--- src/logic/map.cc 2017-08-12 20:13:24 +0000
+++ src/logic/map.cc 2017-08-20 12:33:35 +0000
@@ -565,7 +565,7 @@
565===============565===============
566*/566*/
567template <typename functorT>567template <typename functorT>
568void Map::find_reachable(const Area<FCoords>& area, const CheckStep& checkstep, functorT& functor) {568void Map::find_reachable(const Area<FCoords>& area, const CheckStep& checkstep, functorT& functor) const {
569 std::vector<Coords> queue;569 std::vector<Coords> queue;
570 boost::shared_ptr<Pathfields> pathfields = pathfieldmgr_->allocate();570 boost::shared_ptr<Pathfields> pathfields = pathfieldmgr_->allocate();
571571
@@ -655,7 +655,7 @@
655===============655===============
656*/656*/
657uint32_t657uint32_t
658Map::find_bobs(Area<FCoords> const area, std::vector<Bob*>* const list, const FindBob& functor) {658Map::find_bobs(Area<FCoords> const area, std::vector<Bob*>* const list, const FindBob& functor) const {
659 FindBobsCallback cb(list, functor);659 FindBobsCallback cb(list, functor);
660660
661 find(area, cb);661 find(area, cb);
@@ -678,7 +678,7 @@
678uint32_t Map::find_reachable_bobs(Area<FCoords> const area,678uint32_t Map::find_reachable_bobs(Area<FCoords> const area,
679 std::vector<Bob*>* const list,679 std::vector<Bob*>* const list,
680 const CheckStep& checkstep,680 const CheckStep& checkstep,
681 const FindBob& functor) {681 const FindBob& functor) const {
682 FindBobsCallback cb(list, functor);682 FindBobsCallback cb(list, functor);
683683
684 find_reachable(area, checkstep, cb);684 find_reachable(area, checkstep, cb);
@@ -731,7 +731,7 @@
731*/731*/
732uint32_t Map::find_immovables(Area<FCoords> const area,732uint32_t Map::find_immovables(Area<FCoords> const area,
733 std::vector<ImmovableFound>* const list,733 std::vector<ImmovableFound>* const list,
734 const FindImmovable& functor) {734 const FindImmovable& functor) const{
735 FindImmovablesCallback cb(list, functor);735 FindImmovablesCallback cb(list, functor);
736736
737 find(area, cb);737 find(area, cb);
@@ -752,7 +752,7 @@
752uint32_t Map::find_reachable_immovables(Area<FCoords> const area,752uint32_t Map::find_reachable_immovables(Area<FCoords> const area,
753 std::vector<ImmovableFound>* const list,753 std::vector<ImmovableFound>* const list,
754 const CheckStep& checkstep,754 const CheckStep& checkstep,
755 const FindImmovable& functor) {755 const FindImmovable& functor) const {
756 FindImmovablesCallback cb(list, functor);756 FindImmovablesCallback cb(list, functor);
757757
758 find_reachable(area, checkstep, cb);758 find_reachable(area, checkstep, cb);
@@ -770,7 +770,7 @@
770uint32_t Map::find_reachable_immovables_unique(const Area<FCoords> area,770uint32_t Map::find_reachable_immovables_unique(const Area<FCoords> area,
771 std::vector<BaseImmovable*>& list,771 std::vector<BaseImmovable*>& list,
772 const CheckStep& checkstep,772 const CheckStep& checkstep,
773 const FindImmovable& functor) {773 const FindImmovable& functor) const {
774 std::vector<ImmovableFound> duplist;774 std::vector<ImmovableFound> duplist;
775 FindImmovablesCallback cb(&duplist, find_immovable_always_true());775 FindImmovablesCallback cb(&duplist, find_immovable_always_true());
776776
@@ -824,7 +824,7 @@
824===============824===============
825*/825*/
826uint32_t826uint32_t
827Map::find_fields(Area<FCoords> const area, std::vector<Coords>* list, const FindNode& functor) {827Map::find_fields(Area<FCoords> const area, std::vector<Coords>* list, const FindNode& functor) const {
828 FindNodesCallback cb(list, functor);828 FindNodesCallback cb(list, functor);
829829
830 find(area, cb);830 find(area, cb);
@@ -844,7 +844,7 @@
844uint32_t Map::find_reachable_fields(Area<FCoords> const area,844uint32_t Map::find_reachable_fields(Area<FCoords> const area,
845 std::vector<Coords>* list,845 std::vector<Coords>* list,
846 const CheckStep& checkstep,846 const CheckStep& checkstep,
847 const FindNode& functor) {847 const FindNode& functor) const {
848 FindNodesCallback cb(list, functor);848 FindNodesCallback cb(list, functor);
849849
850 find_reachable(area, checkstep, cb);850 find_reachable(area, checkstep, cb);
@@ -1595,7 +1595,7 @@
1595 int32_t const persist,1595 int32_t const persist,
1596 Path& path,1596 Path& path,
1597 const CheckStep& checkstep,1597 const CheckStep& checkstep,
1598 uint32_t const flags) {1598 uint32_t const flags) const {
1599 FCoords start;1599 FCoords start;
1600 FCoords end;1600 FCoords end;
1601 int32_t upper_cost_limit;1601 int32_t upper_cost_limit;
16021602
=== modified file 'src/logic/map.h'
--- src/logic/map.h 2017-08-12 06:51:08 +0000
+++ src/logic/map.h 2017-08-20 12:33:35 +0000
@@ -181,7 +181,7 @@
181 const std::string& description = _("No description defined"));181 const std::string& description = _("No description defined"));
182182
183 void recalc_whole_map(const World& world);183 void recalc_whole_map(const World& world);
184 virtual void recalc_for_field_area(const World& world, Area<FCoords>);184 void recalc_for_field_area(const World& world, Area<FCoords>);
185185
186 /***186 /***
187 * Ensures that resources match their adjacent terrains.187 * Ensures that resources match their adjacent terrains.
@@ -292,27 +292,27 @@
292 BaseImmovable* get_immovable(const Coords&) const;292 BaseImmovable* get_immovable(const Coords&) const;
293 uint32_t find_bobs(const Area<FCoords>,293 uint32_t find_bobs(const Area<FCoords>,
294 std::vector<Bob*>* list,294 std::vector<Bob*>* list,
295 const FindBob& functor = FindBobAlwaysTrue());295 const FindBob& functor = FindBobAlwaysTrue()) const;
296 uint32_t find_reachable_bobs(const Area<FCoords>,296 uint32_t find_reachable_bobs(const Area<FCoords>,
297 std::vector<Bob*>* list,297 std::vector<Bob*>* list,
298 const CheckStep&,298 const CheckStep&,
299 const FindBob& functor = FindBobAlwaysTrue());299 const FindBob& functor = FindBobAlwaysTrue()) const;
300 uint32_t find_immovables(const Area<FCoords>,300 uint32_t find_immovables(const Area<FCoords>,
301 std::vector<ImmovableFound>* list,301 std::vector<ImmovableFound>* list,
302 const FindImmovable& = find_immovable_always_true());302 const FindImmovable& = find_immovable_always_true()) const;
303 uint32_t find_reachable_immovables(const Area<FCoords>,303 uint32_t find_reachable_immovables(const Area<FCoords>,
304 std::vector<ImmovableFound>* list,304 std::vector<ImmovableFound>* list,
305 const CheckStep&,305 const CheckStep&,
306 const FindImmovable& = find_immovable_always_true());306 const FindImmovable& = find_immovable_always_true()) const;
307 uint32_t find_reachable_immovables_unique(const Area<FCoords>,307 uint32_t find_reachable_immovables_unique(const Area<FCoords>,
308 std::vector<BaseImmovable*>& list,308 std::vector<BaseImmovable*>& list,
309 const CheckStep&,309 const CheckStep&,
310 const FindImmovable& = find_immovable_always_true());310 const FindImmovable& = find_immovable_always_true()) const;
311 uint32_t find_fields(const Area<FCoords>, std::vector<Coords>* list, const FindNode& functor);311 uint32_t find_fields(const Area<FCoords>, std::vector<Coords>* list, const FindNode& functor) const;
312 uint32_t find_reachable_fields(const Area<FCoords>,312 uint32_t find_reachable_fields(const Area<FCoords>,
313 std::vector<Coords>* list,313 std::vector<Coords>* list,
314 const CheckStep&,314 const CheckStep&,
315 const FindNode&);315 const FindNode&) const;
316316
317 // Field logic317 // Field logic
318 static MapIndex get_index(const Coords&, int16_t width);318 static MapIndex get_index(const Coords&, int16_t width);
@@ -370,7 +370,7 @@
370 const int32_t persist,370 const int32_t persist,
371 Path&,371 Path&,
372 const CheckStep&,372 const CheckStep&,
373 const uint32_t flags = 0);373 const uint32_t flags = 0) const;
374374
375 /**375 /**
376 * We can reach a field by water either if it has MOVECAPS_SWIM or if it has376 * We can reach a field by water either if it has MOVECAPS_SWIM or if it has
@@ -464,11 +464,31 @@
464 /// Checks whether there are any artifacts on the map464 /// Checks whether there are any artifacts on the map
465 bool has_artifacts();465 bool has_artifacts();
466466
467protected: /// These functions are needed in Testclasses467 // Visible for testing.
468 void set_size(uint32_t w, uint32_t h);468 void set_size(uint32_t w, uint32_t h);
469469
470private:470private:
471 void recalc_border(const FCoords&);471 void recalc_border(const FCoords&);
472 void recalc_brightness(const FCoords&);
473 void recalc_nodecaps_pass1(const World& world, const FCoords&);
474 void recalc_nodecaps_pass2(const World& world, const FCoords& f);
475 NodeCaps calc_nodecaps_pass1(const World& world, const FCoords&, bool consider_mobs = true);
476 NodeCaps calc_nodecaps_pass2(const World& world,
477 const FCoords&,
478 bool consider_mobs = true,
479 NodeCaps initcaps = CAPS_NONE);
480 void check_neighbour_heights(FCoords, uint32_t& radius);
481 int calc_buildsize(const World& world,
482 const FCoords& f,
483 bool avoidnature,
484 bool* ismine = nullptr,
485 bool consider_mobs = true,
486 NodeCaps initcaps = CAPS_NONE);
487 bool is_cycle_connected(const FCoords& start, uint32_t length, const WalkingDir* dirs);
488 template <typename functorT>
489 void find_reachable(const Area<FCoords>&, const CheckStep&, functorT&) const;
490 template <typename functorT> void find(const Area<FCoords>&, functorT&) const;
491
472492
473 /// # of players this map supports (!= Game's number of players!)493 /// # of players this map supports (!= Game's number of players!)
474 PlayerNumber nrplayers_;494 PlayerNumber nrplayers_;
@@ -501,26 +521,6 @@
501 PortSpacesSet port_spaces_;521 PortSpacesSet port_spaces_;
502 Objectives objectives_;522 Objectives objectives_;
503523
504 void recalc_brightness(const FCoords&);
505 void recalc_nodecaps_pass1(const World& world, const FCoords&);
506 void recalc_nodecaps_pass2(const World& world, const FCoords& f);
507 NodeCaps calc_nodecaps_pass1(const World& world, const FCoords&, bool consider_mobs = true);
508 NodeCaps calc_nodecaps_pass2(const World& world,
509 const FCoords&,
510 bool consider_mobs = true,
511 NodeCaps initcaps = CAPS_NONE);
512 void check_neighbour_heights(FCoords, uint32_t& radius);
513 int calc_buildsize(const World& world,
514 const FCoords& f,
515 bool avoidnature,
516 bool* ismine = nullptr,
517 bool consider_mobs = true,
518 NodeCaps initcaps = CAPS_NONE);
519 bool is_cycle_connected(const FCoords& start, uint32_t length, const WalkingDir* dirs);
520 template <typename functorT>
521 void find_reachable(const Area<FCoords>&, const CheckStep&, functorT&);
522 template <typename functorT> void find(const Area<FCoords>&, functorT&) const;
523
524 MapVersion map_version_;524 MapVersion map_version_;
525};525};
526526
527527
=== modified file 'src/logic/map_objects/bob.cc'
--- src/logic/map_objects/bob.cc 2017-06-24 08:47:46 +0000
+++ src/logic/map_objects/bob.cc 2017-08-20 12:33:35 +0000
@@ -464,7 +464,7 @@
464464
465 Game& game_;465 Game& game_;
466 Bob& bob_;466 Bob& bob_;
467 Map& map_;467 const Map& map_;
468 Coords finaldest_;468 Coords finaldest_;
469 Cache nodes_;469 Cache nodes_;
470 int nrblocked_;470 int nrblocked_;
@@ -475,13 +475,13 @@
475 explicit CheckStepBlocked(BlockedTracker& tracker) : tracker_(tracker) {475 explicit CheckStepBlocked(BlockedTracker& tracker) : tracker_(tracker) {
476 }476 }
477477
478 bool allowed(Map&, FCoords, FCoords end, int32_t, CheckStep::StepId) const {478 bool allowed(const Map&, FCoords, FCoords end, int32_t, CheckStep::StepId) const {
479 if (end == tracker_.finaldest_)479 if (end == tracker_.finaldest_)
480 return true;480 return true;
481481
482 return !tracker_.is_blocked(end);482 return !tracker_.is_blocked(end);
483 }483 }
484 bool reachable_dest(Map&, FCoords) const {484 bool reachable_dest(const Map&, FCoords) const {
485 return true;485 return true;
486 }486 }
487487
@@ -519,7 +519,7 @@
519 if (forceall)519 if (forceall)
520 tracker.disabled_ = true;520 tracker.disabled_ = true;
521521
522 Map& map = game.map();522 const Map& map = game.map();
523 if (map.findpath(position_, dest, persist, path, cstep) < 0) {523 if (map.findpath(position_, dest, persist, path, cstep) < 0) {
524 if (!tracker.nrblocked_)524 if (!tracker.nrblocked_)
525 return false;525 return false;
@@ -634,8 +634,7 @@
634 // Using probability of 1/8 and pausing it for 5, 10 or 15 seconds634 // Using probability of 1/8 and pausing it for 5, 10 or 15 seconds
635 if (game.logic_rand() % 8 == 0) {635 if (game.logic_rand() % 8 == 0) {
636 if (is_a(Ship, this)) {636 if (is_a(Ship, this)) {
637 Map& map = game.map();637 const uint32_t ships_count = game.map().find_bobs(
638 const uint32_t ships_count = map.find_bobs(
639 Widelands::Area<Widelands::FCoords>(get_position(), 0), nullptr, FindBobShip());638 Widelands::Area<Widelands::FCoords>(get_position(), 0), nullptr, FindBobShip());
640 assert(ships_count > 0);639 assert(ships_count > 0);
641 if (ships_count > 1) {640 if (ships_count > 1) {
@@ -694,7 +693,7 @@
694Vector2f Bob::calc_drawpos(const EditorGameBase& game,693Vector2f Bob::calc_drawpos(const EditorGameBase& game,
695 const Vector2f& field_on_dst,694 const Vector2f& field_on_dst,
696 const float scale) const {695 const float scale) const {
697 const Map& map = game.get_map();696 const Map& map = game.map();
698 const FCoords end = position_;697 const FCoords end = position_;
699 FCoords start;698 FCoords start;
700 Vector2f spos = field_on_dst;699 Vector2f spos = field_on_dst;
@@ -793,7 +792,7 @@
793int32_t Bob::start_walk(Game& game, WalkingDir const dir, uint32_t const a, bool const force) {792int32_t Bob::start_walk(Game& game, WalkingDir const dir, uint32_t const a, bool const force) {
794 FCoords newnode;793 FCoords newnode;
795794
796 Map& map = game.map();795 const Map& map = game.map();
797 map.get_neighbour(position_, dir, &newnode);796 map.get_neighbour(position_, dir, &newnode);
798797
799 // Move capability check798 // Move capability check
800799
=== modified file 'src/logic/map_objects/checkstep.cc'
--- src/logic/map_objects/checkstep.cc 2017-01-25 18:55:59 +0000
+++ src/logic/map_objects/checkstep.cc 2017-08-20 12:33:35 +0000
@@ -34,10 +34,10 @@
34}34}
3535
36struct CheckStepAlwaysFalse {36struct CheckStepAlwaysFalse {
37 bool allowed(Map&, const FCoords&, const FCoords&, int32_t, CheckStep::StepId) const {37 bool allowed(const Map&, const FCoords&, const FCoords&, int32_t, CheckStep::StepId) const {
38 return false;38 return false;
39 }39 }
40 bool reachable_dest(Map&, const FCoords&) const {40 bool reachable_dest(const Map&, const FCoords&) const {
41 return false;41 return false;
42 }42 }
43};43};
@@ -51,7 +51,7 @@
51 subs.push_back(sub);51 subs.push_back(sub);
52}52}
5353
54bool CheckStepAnd::allowed(Map& map,54bool CheckStepAnd::allowed(const Map& map,
55 const FCoords& start,55 const FCoords& start,
56 const FCoords& end,56 const FCoords& end,
57 int32_t const dir,57 int32_t const dir,
@@ -64,7 +64,7 @@
64 return true;64 return true;
65}65}
6666
67bool CheckStepAnd::reachable_dest(Map& map, const FCoords& dest) const {67bool CheckStepAnd::reachable_dest(const Map& map, const FCoords& dest) const {
68 for (const CheckStep& checkstep : subs) {68 for (const CheckStep& checkstep : subs) {
69 if (!checkstep.reachable_dest(map, dest)) {69 if (!checkstep.reachable_dest(map, dest)) {
70 return false;70 return false;
@@ -79,7 +79,7 @@
79===============79===============
80*/80*/
81bool CheckStepDefault::allowed(81bool CheckStepDefault::allowed(
82 Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId) const {82 const Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId) const {
83 NodeCaps const endcaps = end.field->nodecaps();83 NodeCaps const endcaps = end.field->nodecaps();
8484
85 if (endcaps & movecaps_)85 if (endcaps & movecaps_)
@@ -94,7 +94,7 @@
94 return false;94 return false;
95}95}
9696
97bool CheckStepDefault::reachable_dest(Map& map, const FCoords& dest) const {97bool CheckStepDefault::reachable_dest(const Map& map, const FCoords& dest) const {
98 NodeCaps const caps = dest.field->nodecaps();98 NodeCaps const caps = dest.field->nodecaps();
9999
100 if (!(caps & movecaps_)) {100 if (!(caps & movecaps_)) {
@@ -114,7 +114,7 @@
114===============114===============
115*/115*/
116bool CheckStepWalkOn::allowed(116bool CheckStepWalkOn::allowed(
117 Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const {117 const Map&, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const {
118 NodeCaps const startcaps = start.field->nodecaps();118 NodeCaps const startcaps = start.field->nodecaps();
119 NodeCaps const endcaps = end.field->nodecaps();119 NodeCaps const endcaps = end.field->nodecaps();
120120
@@ -138,13 +138,13 @@
138 return false;138 return false;
139}139}
140140
141bool CheckStepWalkOn::reachable_dest(Map&, FCoords) const {141bool CheckStepWalkOn::reachable_dest(const Map&, FCoords) const {
142 // Don't bother solving this.142 // Don't bother solving this.
143 return true;143 return true;
144}144}
145145
146bool CheckStepRoad::allowed(146bool CheckStepRoad::allowed(
147 Map& map, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const {147 const Map& map, const FCoords& start, const FCoords& end, int32_t, CheckStep::StepId const id) const {
148 uint8_t const endcaps = player_.get_buildcaps(end);148 uint8_t const endcaps = player_.get_buildcaps(end);
149149
150 // Calculate cost and passability150 // Calculate cost and passability
@@ -165,7 +165,7 @@
165 return true;165 return true;
166}166}
167167
168bool CheckStepRoad::reachable_dest(Map& map, const FCoords& dest) const {168bool CheckStepRoad::reachable_dest(const Map& map, const FCoords& dest) const {
169 NodeCaps const caps = dest.field->nodecaps();169 NodeCaps const caps = dest.field->nodecaps();
170170
171 if (!(caps & movecaps_)) {171 if (!(caps & movecaps_)) {
@@ -180,11 +180,11 @@
180}180}
181181
182bool CheckStepLimited::allowed(182bool CheckStepLimited::allowed(
183 Map&, const FCoords&, const FCoords& end, int32_t, CheckStep::StepId) const {183 const Map&, const FCoords&, const FCoords& end, int32_t, CheckStep::StepId) const {
184 return allowed_locations_.find(end) != allowed_locations_.end();184 return allowed_locations_.find(end) != allowed_locations_.end();
185}185}
186186
187bool CheckStepLimited::reachable_dest(Map&, FCoords) const {187bool CheckStepLimited::reachable_dest(const Map&, FCoords) const {
188 return true;188 return true;
189}189}
190}190}
191191
=== modified file 'src/logic/map_objects/checkstep.h'
--- src/logic/map_objects/checkstep.h 2017-08-12 06:51:08 +0000
+++ src/logic/map_objects/checkstep.h 2017-08-20 12:33:35 +0000
@@ -44,21 +44,21 @@
44 virtual ~BaseCapsule() {44 virtual ~BaseCapsule() {
45 }45 }
46 virtual bool46 virtual bool
47 allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, StepId id) const = 0;47 allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, StepId id) const = 0;
48 virtual bool reachable_dest(Map&, const FCoords& dest) const = 0;48 virtual bool reachable_dest(const Map&, const FCoords& dest) const = 0;
49 };49 };
50 template <typename T> struct Capsule : public BaseCapsule {50 template <typename T> struct Capsule : public BaseCapsule {
51 Capsule(const T& init_op) : op(init_op) {51 Capsule(const T& init_op) : op(init_op) {
52 }52 }
5353
54 bool allowed(Map& map,54 bool allowed(const Map& map,
55 const FCoords& start,55 const FCoords& start,
56 const FCoords& end,56 const FCoords& end,
57 int32_t const dir,57 int32_t const dir,
58 StepId const id) const override {58 StepId const id) const override {
59 return op.allowed(map, start, end, dir, id);59 return op.allowed(map, start, end, dir, id);
60 }60 }
61 bool reachable_dest(Map& map, const FCoords& dest) const override {61 bool reachable_dest(const Map& map, const FCoords& dest) const override {
62 return op.reachable_dest(map, dest);62 return op.reachable_dest(map, dest);
63 }63 }
6464
@@ -79,7 +79,7 @@
79 * \return \c true true if moving from start to end (single step in the given79 * \return \c true true if moving from start to end (single step in the given
80 * direction) is allowed.80 * direction) is allowed.
81 */81 */
82 bool allowed(Map& map,82 bool allowed(const Map& map,
83 const FCoords& start,83 const FCoords& start,
84 const FCoords& end,84 const FCoords& end,
85 int32_t const dir,85 int32_t const dir,
@@ -91,7 +91,7 @@
91 * \return \c true if the destination field can be reached at all91 * \return \c true if the destination field can be reached at all
92 * (e.g. return false for land-based bobs when dest is in water).92 * (e.g. return false for land-based bobs when dest is in water).
93 */93 */
94 bool reachable_dest(Map& map, const FCoords& dest) const {94 bool reachable_dest(const Map& map, const FCoords& dest) const {
95 return capsule->reachable_dest(map, dest);95 return capsule->reachable_dest(map, dest);
96 }96 }
97};97};
@@ -104,8 +104,8 @@
104 void add(const CheckStep& sub);104 void add(const CheckStep& sub);
105105
106 bool106 bool
107 allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId id) const;107 allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId id) const;
108 bool reachable_dest(Map&, const FCoords& dest) const;108 bool reachable_dest(const Map&, const FCoords& dest) const;
109109
110private:110private:
111 std::vector<CheckStep> subs;111 std::vector<CheckStep> subs;
@@ -123,8 +123,8 @@
123 }123 }
124124
125 bool125 bool
126 allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;126 allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;
127 bool reachable_dest(Map&, const FCoords& dest) const;127 bool reachable_dest(const Map&, const FCoords& dest) const;
128128
129private:129private:
130 uint8_t movecaps_;130 uint8_t movecaps_;
@@ -141,8 +141,8 @@
141 }141 }
142142
143 bool143 bool
144 allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;144 allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;
145 bool reachable_dest(Map&, FCoords dest) const;145 bool reachable_dest(const Map&, FCoords dest) const;
146146
147private:147private:
148 uint8_t movecaps_;148 uint8_t movecaps_;
@@ -162,8 +162,8 @@
162 }162 }
163163
164 bool164 bool
165 allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;165 allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;
166 bool reachable_dest(Map&, const FCoords& dest) const;166 bool reachable_dest(const Map&, const FCoords& dest) const;
167167
168private:168private:
169 const Player& player_;169 const Player& player_;
@@ -179,8 +179,8 @@
179 allowed_locations_.insert(c);179 allowed_locations_.insert(c);
180 }180 }
181 bool181 bool
182 allowed(Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;182 allowed(const Map&, const FCoords& start, const FCoords& end, int32_t dir, CheckStep::StepId) const;
183 bool reachable_dest(Map&, FCoords dest) const;183 bool reachable_dest(const Map&, FCoords dest) const;
184184
185private:185private:
186 // The ordering of the set does not matter, as long as it is system186 // The ordering of the set does not matter, as long as it is system
187187
=== modified file 'src/logic/map_objects/immovable.cc'
--- src/logic/map_objects/immovable.cc 2017-07-04 11:34:00 +0000
+++ src/logic/map_objects/immovable.cc 2017-08-20 12:33:35 +0000
@@ -100,15 +100,16 @@
100void BaseImmovable::set_position(EditorGameBase& egbase, const Coords& c) {100void BaseImmovable::set_position(EditorGameBase& egbase, const Coords& c) {
101 assert(c);101 assert(c);
102102
103 Map& map = egbase.map();103 Map* map = egbase.mutable_map();
104 FCoords f = map.get_fcoords(c);104 FCoords f = map->get_fcoords(c);
105 if (f.field->immovable && f.field->immovable != this)105 if (f.field->immovable && f.field->immovable != this)
106 f.field->immovable->remove(egbase);106 f.field->immovable->remove(egbase);
107107
108 f.field->immovable = this;108 f.field->immovable = this;
109109
110 if (get_size() >= SMALL)110 if (get_size() >= SMALL) {
111 map.recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2));111 map->recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2));
112 }
112}113}
113114
114/**115/**
@@ -117,8 +118,8 @@
117 * Only call this during cleanup.118 * Only call this during cleanup.
118*/119*/
119void BaseImmovable::unset_position(EditorGameBase& egbase, const Coords& c) {120void BaseImmovable::unset_position(EditorGameBase& egbase, const Coords& c) {
120 Map& map = egbase.map();121 Map* map = egbase.mutable_map();
121 FCoords const f = map.get_fcoords(c);122 FCoords const f = map->get_fcoords(c);
122123
123 // this is to help to debug failing assertion below (see bug 1542238)124 // this is to help to debug failing assertion below (see bug 1542238)
124 if (f.field->immovable != this) {125 if (f.field->immovable != this) {
@@ -130,10 +131,11 @@
130 assert(f.field->immovable == this);131 assert(f.field->immovable == this);
131132
132 f.field->immovable = nullptr;133 f.field->immovable = nullptr;
133 egbase.inform_players_about_immovable(f.field - &map[0], nullptr);134 egbase.inform_players_about_immovable(f.field - &(*map)[0], nullptr);
134135
135 if (get_size() >= SMALL)136 if (get_size() >= SMALL) {
136 map.recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2));137 map->recalc_for_field_area(egbase.world(), Area<FCoords>(f, 2));
138 }
137}139}
138140
139/*141/*
140142
=== modified file 'src/logic/map_objects/tribes/building.cc'
--- src/logic/map_objects/tribes/building.cc 2017-08-16 04:31:56 +0000
+++ src/logic/map_objects/tribes/building.cc 2017-08-20 12:33:35 +0000
@@ -329,7 +329,7 @@
329 PlayerImmovable::init(egbase);329 PlayerImmovable::init(egbase);
330330
331 // Set the building onto the map331 // Set the building onto the map
332 Map& map = egbase.map();332 const Map& map = egbase.map();
333 Coords neighb;333 Coords neighb;
334334
335 set_position(egbase, position_);335 set_position(egbase, position_);
@@ -385,7 +385,7 @@
385 unset_position(egbase, position_);385 unset_position(egbase, position_);
386386
387 if (get_size() == BIG) {387 if (get_size() == BIG) {
388 Map& map = egbase.map();388 const Map& map = egbase.map();
389 Coords neighb;389 Coords neighb;
390390
391 map.get_ln(position_, &neighb);391 map.get_ln(position_, &neighb);
@@ -421,7 +421,7 @@
421421
422 rv.push_back(position_);422 rv.push_back(position_);
423 if (get_size() == BIG) {423 if (get_size() == BIG) {
424 Map& map = egbase.map();424 const Map& map = egbase.map();
425 Coords neighb;425 Coords neighb;
426426
427 map.get_ln(position_, &neighb);427 map.get_ln(position_, &neighb);
@@ -727,7 +727,7 @@
727 return;727 return;
728728
729 Player& player = owner();729 Player& player = owner();
730 Map& map = player.egbase().map();730 const Map& map = player.egbase().map();
731731
732 if (see)732 if (see)
733 player.see_area(Area<FCoords>(map.get_fcoords(get_position()), descr().vision_range()));733 player.see_area(Area<FCoords>(map.get_fcoords(get_position()), descr().vision_range()));
734734
=== modified file 'src/logic/map_objects/tribes/carrier.cc'
--- src/logic/map_objects/tribes/carrier.cc 2017-04-22 06:45:52 +0000
+++ src/logic/map_objects/tribes/carrier.cc 2017-08-20 12:33:35 +0000
@@ -432,7 +432,7 @@
432 * Find the flag we are closest to (in walking time).432 * Find the flag we are closest to (in walking time).
433 */433 */
434int32_t Carrier::find_closest_flag(Game& game) {434int32_t Carrier::find_closest_flag(Game& game) {
435 Map& map = game.map();435 const Map& map = game.map();
436 CoordPath startpath(map, dynamic_cast<Road&>(*get_location(game)).get_path());436 CoordPath startpath(map, dynamic_cast<Road&>(*get_location(game)).get_path());
437437
438 CoordPath endpath;438 CoordPath endpath;
439439
=== modified file 'src/logic/map_objects/tribes/militarysite.cc'
--- src/logic/map_objects/tribes/militarysite.cc 2017-08-16 13:23:15 +0000
+++ src/logic/map_objects/tribes/militarysite.cc 2017-08-20 12:33:35 +0000
@@ -156,7 +156,7 @@
156void MilitarySite::AttackTarget::enemy_soldier_approaches(const Soldier& enemy) const {156void MilitarySite::AttackTarget::enemy_soldier_approaches(const Soldier& enemy) const {
157 auto& owner = military_site_->owner();157 auto& owner = military_site_->owner();
158 Game& game = dynamic_cast<Game&>(owner.egbase());158 Game& game = dynamic_cast<Game&>(owner.egbase());
159 Map& map = game.map();159 const Map& map = game.map();
160 if (enemy.get_owner() == &owner || enemy.get_battle() ||160 if (enemy.get_owner() == &owner || enemy.get_battle() ||
161 military_site_->descr().get_conquers() <=161 military_site_->descr().get_conquers() <=
162 map.calc_distance(enemy.get_position(), military_site_->get_position()))162 map.calc_distance(enemy.get_position(), military_site_->get_position()))
163163
=== modified file 'src/logic/map_objects/tribes/production_program.cc'
--- src/logic/map_objects/tribes/production_program.cc 2017-08-16 04:31:56 +0000
+++ src/logic/map_objects/tribes/production_program.cc 2017-08-20 12:33:35 +0000
@@ -1138,7 +1138,7 @@
1138}1138}
11391139
1140void ProductionProgram::ActMine::execute(Game& game, ProductionSite& ps) const {1140void ProductionProgram::ActMine::execute(Game& game, ProductionSite& ps) const {
1141 Map& map = game.map();1141 Map* map = game.mutable_map();
11421142
1143 // select one of the nodes randomly1143 // select one of the nodes randomly
1144 uint32_t totalres = 0;1144 uint32_t totalres = 0;
@@ -1147,7 +1147,7 @@
11471147
1148 {1148 {
1149 MapRegion<Area<FCoords>> mr(1149 MapRegion<Area<FCoords>> mr(
1150 map, Area<FCoords>(map.get_fcoords(ps.get_position()), distance_));1150 *map, Area<FCoords>(map->get_fcoords(ps.get_position()), distance_));
1151 do {1151 do {
1152 DescriptionIndex fres = mr.location().field->get_resources();1152 DescriptionIndex fres = mr.location().field->get_resources();
1153 ResourceAmount amount = mr.location().field->get_resources_amount();1153 ResourceAmount amount = mr.location().field->get_resources_amount();
@@ -1172,7 +1172,7 @@
1172 totalchance += 4;1172 totalchance += 4;
1173 else if (amount <= 6)1173 else if (amount <= 6)
1174 totalchance += 2;1174 totalchance += 2;
1175 } while (mr.advance(map));1175 } while (mr.advance(*map));
1176 }1176 }
11771177
1178 // how much is digged1178 // how much is digged
@@ -1193,7 +1193,7 @@
11931193
1194 {1194 {
1195 MapRegion<Area<FCoords>> mr(1195 MapRegion<Area<FCoords>> mr(
1196 map, Area<FCoords>(map.get_fcoords(ps.get_position()), distance_));1196 *map, Area<FCoords>(map->get_fcoords(ps.get_position()), distance_));
1197 do {1197 do {
1198 DescriptionIndex fres = mr.location().field->get_resources();1198 DescriptionIndex fres = mr.location().field->get_resources();
1199 ResourceAmount amount = mr.location().field->get_resources_amount();1199 ResourceAmount amount = mr.location().field->get_resources_amount();
@@ -1206,10 +1206,10 @@
1206 assert(amount > 0);1206 assert(amount > 0);
12071207
1208 --amount;1208 --amount;
1209 map.set_resources(mr.location(), amount);1209 map->set_resources(mr.location(), amount);
1210 break;1210 break;
1211 }1211 }
1212 } while (mr.advance(map));1212 } while (mr.advance(*map));
1213 }1213 }
12141214
1215 if (pick >= 0) {1215 if (pick >= 0) {
@@ -1489,10 +1489,11 @@
1489 }1489 }
14901490
1491 // Look for an appropriate object in the given radius1491 // Look for an appropriate object in the given radius
1492 const Map& map = game.map();
1492 std::vector<ImmovableFound> immovables;1493 std::vector<ImmovableFound> immovables;
1493 CheckStepWalkOn cstep(MOVECAPS_WALK, true);1494 CheckStepWalkOn cstep(MOVECAPS_WALK, true);
1494 Area<FCoords> area(game.map().get_fcoords(psite.base_flag().get_position()), radius);1495 Area<FCoords> area(map.get_fcoords(psite.base_flag().get_position()), radius);
1495 if (game.map().find_reachable_immovables(1496 if (map.find_reachable_immovables(
1496 area, &immovables, cstep, FindImmovableByDescr(descr))) {1497 area, &immovables, cstep, FindImmovableByDescr(descr))) {
1497 state.objvar = immovables[0].object;1498 state.objvar = immovables[0].object;
14981499
@@ -1502,7 +1503,6 @@
15021503
1503 // No object found, look for a field where we can build1504 // No object found, look for a field where we can build
1504 std::vector<Coords> fields;1505 std::vector<Coords> fields;
1505 Map& map = game.map();
1506 FindNodeAnd fna;1506 FindNodeAnd fna;
1507 // 10 is custom value to make sure the "water" is at least 10 nodes big1507 // 10 is custom value to make sure the "water" is at least 10 nodes big
1508 fna.add(FindNodeShore(10));1508 fna.add(FindNodeShore(10));
15091509
=== modified file 'src/logic/map_objects/tribes/ship.cc'
--- src/logic/map_objects/tribes/ship.cc 2017-08-16 14:30:17 +0000
+++ src/logic/map_objects/tribes/ship.cc 2017-08-20 12:33:35 +0000
@@ -288,7 +288,7 @@
288288
289/// updates a ships tasks in transport mode \returns false if failed to update tasks289/// updates a ships tasks in transport mode \returns false if failed to update tasks
290bool Ship::ship_update_transport(Game& game, Bob::State& state) {290bool Ship::ship_update_transport(Game& game, Bob::State& state) {
291 Map& map = game.map();291 const Map& map = game.map();
292292
293 PortDock* dst = get_destination(game);293 PortDock* dst = get_destination(game);
294 if (!dst) {294 if (!dst) {
@@ -366,7 +366,7 @@
366366
367/// updates a ships tasks in expedition mode367/// updates a ships tasks in expedition mode
368void Ship::ship_update_expedition(Game& game, Bob::State&) {368void Ship::ship_update_expedition(Game& game, Bob::State&) {
369 Map& map = game.map();369 Map* map = game.mutable_map();
370370
371 assert(expedition_);371 assert(expedition_);
372372
@@ -374,29 +374,29 @@
374 FCoords position = get_position();374 FCoords position = get_position();
375 for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {375 for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
376 expedition_->swimmable[dir - 1] =376 expedition_->swimmable[dir - 1] =
377 map.get_neighbour(position, dir).field->nodecaps() & MOVECAPS_SWIM;377 map->get_neighbour(position, dir).field->nodecaps() & MOVECAPS_SWIM;
378 }378 }
379379
380 if (ship_state_ == ShipStates::kExpeditionScouting) {380 if (ship_state_ == ShipStates::kExpeditionScouting) {
381 // Check surrounding fields for port buildspaces381 // Check surrounding fields for port buildspaces
382 std::vector<Coords> temp_port_buildspaces;382 std::vector<Coords> temp_port_buildspaces;
383 MapRegion<Area<Coords>> mr(map, Area<Coords>(position, descr().vision_range()));383 MapRegion<Area<Coords>> mr(*map, Area<Coords>(position, descr().vision_range()));
384 bool new_port_space = false;384 bool new_port_space = false;
385 do {385 do {
386 if (!map.is_port_space(mr.location())) {386 if (!map->is_port_space(mr.location())) {
387 continue;387 continue;
388 }388 }
389389
390 const FCoords fc = map.get_fcoords(mr.location());390 const FCoords fc = map->get_fcoords(mr.location());
391391
392 // Check whether the maximum theoretical possible NodeCap of the field392 // Check whether the maximum theoretical possible NodeCap of the field
393 // is of the size big and whether it can theoretically be a port space393 // is of the size big and whether it can theoretically be a port space
394 if ((map.get_max_nodecaps(game.world(), fc) & BUILDCAPS_SIZEMASK) != BUILDCAPS_BIG ||394 if ((map->get_max_nodecaps(game.world(), fc) & BUILDCAPS_SIZEMASK) != BUILDCAPS_BIG ||
395 map.find_portdock(fc).empty()) {395 map->find_portdock(fc).empty()) {
396 continue;396 continue;
397 }397 }
398398
399 if (!can_build_port_here(get_owner()->player_number(), map, fc)) {399 if (!can_build_port_here(get_owner()->player_number(), *map, fc)) {
400 continue;400 continue;
401 }401 }
402402
@@ -409,7 +409,7 @@
409 new_port_space = true;409 new_port_space = true;
410 temp_port_buildspaces.insert(temp_port_buildspaces.begin(), mr.location());410 temp_port_buildspaces.insert(temp_port_buildspaces.begin(), mr.location());
411 }411 }
412 } while (mr.advance(map));412 } while (mr.advance(*map));
413413
414 if (new_port_space) {414 if (new_port_space) {
415 ship_state_ = ShipStates::kExpeditionPortspaceFound;415 ship_state_ = ShipStates::kExpeditionPortspaceFound;
@@ -438,10 +438,10 @@
438438
439 // If we are waiting for the next transport job, check if we should move away from ships and439 // If we are waiting for the next transport job, check if we should move away from ships and
440 // shores440 // shores
441 const Map& map = game.map();
441 switch (ship_state_) {442 switch (ship_state_) {
442 case ShipStates::kTransport: {443 case ShipStates::kTransport: {
443 FCoords position = get_position();444 FCoords position = get_position();
444 Map& map = game.map();
445 unsigned int dirs[LAST_DIRECTION + 1];445 unsigned int dirs[LAST_DIRECTION + 1];
446 unsigned int dirmax = 0;446 unsigned int dirmax = 0;
447447
@@ -569,7 +569,6 @@
569 // Most likely the command was send as the ship was on an exploration and just leaving569 // Most likely the command was send as the ship was on an exploration and just leaving
570 // the island - therefore we try to find the island again.570 // the island - therefore we try to find the island again.
571 FCoords position = get_position();571 FCoords position = get_position();
572 Map& map = game.map();
573 for (uint8_t dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {572 for (uint8_t dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
574 FCoords neighbour = map.get_neighbour(position, dir);573 FCoords neighbour = map.get_neighbour(position, dir);
575 for (uint8_t sur = FIRST_DIRECTION; sur <= LAST_DIRECTION; ++sur)574 for (uint8_t sur = FIRST_DIRECTION; sur <= LAST_DIRECTION; ++sur)
@@ -612,7 +611,7 @@
612 }611 }
613 case ShipStates::kExpeditionColonizing: {612 case ShipStates::kExpeditionColonizing: {
614 assert(!expedition_->seen_port_buildspaces.empty());613 assert(!expedition_->seen_port_buildspaces.empty());
615 BaseImmovable* baim = game.map()[expedition_->seen_port_buildspaces.front()].get_immovable();614 BaseImmovable* baim = map[expedition_->seen_port_buildspaces.front()].get_immovable();
616 if (baim) {615 if (baim) {
617 upcast(ConstructionSite, cs, baim);616 upcast(ConstructionSite, cs, baim);
618617
@@ -742,13 +741,13 @@
742 * Find a path to the dock @p pd, returns its length, and the path optionally.741 * Find a path to the dock @p pd, returns its length, and the path optionally.
743 */742 */
744uint32_t Ship::calculate_sea_route(Game& game, PortDock& pd, Path* finalpath) const {743uint32_t Ship::calculate_sea_route(Game& game, PortDock& pd, Path* finalpath) const {
745 Map& map = game.map();744 Map* map = game.mutable_map();
746 StepEvalAStar se(pd.get_warehouse()->get_position());745 StepEvalAStar se(pd.get_warehouse()->get_position());
747 se.swim_ = true;746 se.swim_ = true;
748 se.conservative_ = false;747 se.conservative_ = false;
749 se.estimator_bias_ = -5 * map.calc_cost(0);748 se.estimator_bias_ = -5 * map->calc_cost(0);
750749
751 MapAStar<StepEvalAStar> astar(map, se);750 MapAStar<StepEvalAStar> astar(*map, se);
752751
753 astar.push(get_position());752 astar.push(get_position());
754753
755754
=== modified file 'src/logic/map_objects/tribes/soldier.cc'
--- src/logic/map_objects/tribes/soldier.cc 2017-07-05 19:21:57 +0000
+++ src/logic/map_objects/tribes/soldier.cc 2017-08-20 12:33:35 +0000
@@ -735,6 +735,7 @@
735 upcast(Building, enemy, state.objvar1.get(game));735 upcast(Building, enemy, state.objvar1.get(game));
736736
737 // Handle returns737 // Handle returns
738 const Map& map = game.map();
738 if (state.ivar2 > 0) {739 if (state.ivar2 > 0) {
739 if (state.ivar2 == 1) {740 if (state.ivar2 == 1) {
740 // Return home741 // Return home
@@ -774,7 +775,7 @@
774 }775 }
775 if (state.ivar2 == 2) {776 if (state.ivar2 == 2) {
776 // No more home, so return to homeland777 // No more home, so return to homeland
777 upcast(Flag, flag, game.map().get_immovable(get_position()));778 upcast(Flag, flag, map.get_immovable(get_position()));
778 if (flag && flag->get_owner() == get_owner()) {779 if (flag && flag->get_owner() == get_owner()) {
779 // At a flag780 // At a flag
780 molog("[attack] Returned to own flag\n");781 molog("[attack] Returned to own flag\n");
@@ -793,11 +794,10 @@
793 return pop_task(game);794 return pop_task(game);
794 }795 }
795 // Try to find our land796 // Try to find our land
796 Map* map = game.get_map();
797 std::vector<Coords> coords;797 std::vector<Coords> coords;
798 uint32_t maxdist = descr().vision_range() * 2;798 uint32_t maxdist = descr().vision_range() * 2;
799 Area<FCoords> area(map->get_fcoords(get_position()), maxdist);799 Area<FCoords> area(map.get_fcoords(get_position()), maxdist);
800 if (map->find_reachable_fields(area, &coords, CheckStepDefault(descr().movecaps()),800 if (map.find_reachable_fields(area, &coords, CheckStepDefault(descr().movecaps()),
801 FindNodeOwned(get_owner()->player_number()))) {801 FindNodeOwned(get_owner()->player_number()))) {
802 // Found home land802 // Found home land
803 target = coords.front();803 target = coords.front();
@@ -842,8 +842,8 @@
842 }842 }
843 // Any enemy soldier at baseflag count as defender.843 // Any enemy soldier at baseflag count as defender.
844 std::vector<Bob*> soldiers;844 std::vector<Bob*> soldiers;
845 game.map().find_bobs(845 map.find_bobs(
846 Area<FCoords>(game.map().get_fcoords(enemy->base_flag().get_position()), 0), &soldiers,846 Area<FCoords>(map.get_fcoords(enemy->base_flag().get_position()), 0), &soldiers,
847 FindBobEnemySoldier(get_owner()));847 FindBobEnemySoldier(get_owner()));
848 defenders += soldiers.size();848 defenders += soldiers.size();
849 }849 }
@@ -862,7 +862,7 @@
862 // valid anymore, we either "conquered" the new building, or it was862 // valid anymore, we either "conquered" the new building, or it was
863 // destroyed.863 // destroyed.
864 if (state.coords) {864 if (state.coords) {
865 BaseImmovable* const newimm = game.map()[state.coords].get_immovable();865 BaseImmovable* const newimm = map[state.coords].get_immovable();
866 upcast(MilitarySite, newsite, newimm);866 upcast(MilitarySite, newsite, newimm);
867 if (newsite && (&newsite->owner() == &owner())) {867 if (newsite && (&newsite->owner() == &owner())) {
868 const SoldierControl* soldier_control = newsite->soldier_control();868 const SoldierControl* soldier_control = newsite->soldier_control();
@@ -1182,7 +1182,7 @@
1182 throw GameDataError("bad direction '%d'", dir);1182 throw GameDataError("bad direction '%d'", dir);
1183 }1183 }
11841184
1185 Map& map = game.map();1185 const Map& map = game.map();
1186 int32_t const tdelta = (map.calc_cost(get_position(), mapdir)) / 2;1186 int32_t const tdelta = (map.calc_cost(get_position(), mapdir)) / 2;
1187 molog("[move_in_battle] dir: (%d) tdelta: (%d)\n", dir, tdelta);1187 molog("[move_in_battle] dir: (%d) tdelta: (%d)\n", dir, tdelta);
1188 combat_walking_ = dir;1188 combat_walking_ = dir;
@@ -1275,7 +1275,7 @@
1275 return pop_task(game);1275 return pop_task(game);
1276 }1276 }
12771277
1278 Map& map = game.map();1278 const Map& map = game.map();
1279 Soldier& opponent = *battle_->opponent(*this);1279 Soldier& opponent = *battle_->opponent(*this);
1280 if (opponent.get_position() != get_position()) {1280 if (opponent.get_position() != get_position()) {
1281 if (is_a(Building, map[get_position()].get_immovable())) {1281 if (is_a(Building, map[get_position()].get_immovable())) {
12821282
=== modified file 'src/logic/map_objects/tribes/warehouse.cc'
--- src/logic/map_objects/tribes/warehouse.cc 2017-07-01 15:36:36 +0000
+++ src/logic/map_objects/tribes/warehouse.cc 2017-08-20 12:33:35 +0000
@@ -80,13 +80,13 @@
8080
81 Player& owner = warehouse_->owner();81 Player& owner = warehouse_->owner();
82 Game& game = dynamic_cast<Game&>(owner.egbase());82 Game& game = dynamic_cast<Game&>(owner.egbase());
83 Map& map = game.map();83 const Map& map = game.map();
84 if (enemy.get_owner() == &owner || enemy.get_battle() ||84 if (enemy.get_owner() == &owner || enemy.get_battle() ||
85 warehouse_->descr().get_conquers() <=85 warehouse_->descr().get_conquers() <=
86 map.calc_distance(enemy.get_position(), warehouse_->get_position()))86 map.calc_distance(enemy.get_position(), warehouse_->get_position()))
87 return;87 return;
8888
89 if (game.map().find_bobs(89 if (map.find_bobs(
90 Area<FCoords>(map.get_fcoords(warehouse_->base_flag().get_position()), 2), nullptr,90 Area<FCoords>(map.get_fcoords(warehouse_->base_flag().get_position()), 2), nullptr,
91 FindBobEnemySoldier(&owner)))91 FindBobEnemySoldier(&owner)))
92 return;92 return;
@@ -581,8 +581,7 @@
581void Warehouse::init_portdock(EditorGameBase& egbase) {581void Warehouse::init_portdock(EditorGameBase& egbase) {
582 molog("Setting up port dock fields\n");582 molog("Setting up port dock fields\n");
583583
584 Map& map = egbase.map();584 std::vector<Coords> dock = egbase.map().find_portdock(get_position());
585 std::vector<Coords> dock = map.find_portdock(get_position());
586 if (dock.empty()) {585 if (dock.empty()) {
587 log("Attempting to setup port without neighboring water (coords: %3dx%3d).\n",586 log("Attempting to setup port without neighboring water (coords: %3dx%3d).\n",
588 get_position().x, get_position().y);587 get_position().x, get_position().y);
@@ -670,7 +669,7 @@
670 planned_workers_.pop_back();669 planned_workers_.pop_back();
671 }670 }
672671
673 Map& map = egbase.map();672 const Map& map = egbase.map();
674 if (const uint32_t conquer_radius = descr().get_conquers())673 if (const uint32_t conquer_radius = descr().get_conquers())
675 egbase.unconquer_area(674 egbase.unconquer_area(
676 PlayerArea<Area<FCoords>>(owner().player_number(),675 PlayerArea<Area<FCoords>>(owner().player_number(),
677676
=== modified file 'src/logic/map_objects/tribes/worker.cc'
--- src/logic/map_objects/tribes/worker.cc 2017-07-07 11:19:07 +0000
+++ src/logic/map_objects/tribes/worker.cc 2017-08-20 12:33:35 +0000
@@ -106,7 +106,7 @@
106 */106 */
107// TODO(unknown): Lots of magic numbers in here107// TODO(unknown): Lots of magic numbers in here
108bool Worker::run_mine(Game& game, State& state, const Action& action) {108bool Worker::run_mine(Game& game, State& state, const Action& action) {
109 Map& map = game.map();109 Map* map = game.mutable_map();
110110
111 // Make sure that the specified resource is available in this world111 // Make sure that the specified resource is available in this world
112 DescriptionIndex const res = game.world().get_resource(action.sparam1.c_str());112 DescriptionIndex const res = game.world().get_resource(action.sparam1.c_str());
@@ -119,7 +119,7 @@
119 uint32_t totalres = 0;119 uint32_t totalres = 0;
120 uint32_t totalchance = 0;120 uint32_t totalchance = 0;
121 int32_t pick;121 int32_t pick;
122 MapRegion<Area<FCoords>> mr(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));122 MapRegion<Area<FCoords>> mr(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1));
123 do {123 do {
124 DescriptionIndex fres = mr.location().field->get_resources();124 DescriptionIndex fres = mr.location().field->get_resources();
125 ResourceAmount amount = mr.location().field->get_resources_amount();125 ResourceAmount amount = mr.location().field->get_resources_amount();
@@ -143,7 +143,7 @@
143 totalchance += 4;143 totalchance += 4;
144 else if (amount <= 6)144 else if (amount <= 6)
145 totalchance += 2;145 totalchance += 2;
146 } while (mr.advance(map));146 } while (mr.advance(*map));
147147
148 if (totalres == 0) {148 if (totalres == 0) {
149 molog(" Run out of resources\n");149 molog(" Run out of resources\n");
@@ -155,7 +155,7 @@
155 // Second pass through fields - reset mr155 // Second pass through fields - reset mr
156 pick = game.logic_rand() % totalchance;156 pick = game.logic_rand() % totalchance;
157 mr =157 mr =
158 MapRegion<Area<FCoords>>(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));158 MapRegion<Area<FCoords>>(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1));
159 do {159 do {
160 DescriptionIndex fres = mr.location().field->get_resources();160 DescriptionIndex fres = mr.location().field->get_resources();
161 if (fres != res) {161 if (fres != res) {
@@ -169,10 +169,10 @@
169 assert(amount > 0);169 assert(amount > 0);
170170
171 --amount;171 --amount;
172 map.set_resources(mr.location(), amount);172 map->set_resources(mr.location(), amount);
173 break;173 break;
174 }174 }
175 } while (mr.advance(map));175 } while (mr.advance(*map));
176176
177 if (pick >= 0) {177 if (pick >= 0) {
178 molog(" Not successful this time\n");178 molog(" Not successful this time\n");
@@ -206,7 +206,7 @@
206bool Worker::run_breed(Game& game, State& state, const Action& action) {206bool Worker::run_breed(Game& game, State& state, const Action& action) {
207 molog(" Breed(%s, %i)\n", action.sparam1.c_str(), action.iparam1);207 molog(" Breed(%s, %i)\n", action.sparam1.c_str(), action.iparam1);
208208
209 Map& map = game.map();209 Map* map = game.mutable_map();
210210
211 // Make sure that the specified resource is available in this world211 // Make sure that the specified resource is available in this world
212 DescriptionIndex const res = game.world().get_resource(action.sparam1.c_str());212 DescriptionIndex const res = game.world().get_resource(action.sparam1.c_str());
@@ -219,7 +219,7 @@
219 uint32_t totalres = 0;219 uint32_t totalres = 0;
220 uint32_t totalchance = 0;220 uint32_t totalchance = 0;
221 int32_t pick;221 int32_t pick;
222 MapRegion<Area<FCoords>> mr(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));222 MapRegion<Area<FCoords>> mr(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1));
223 do {223 do {
224 DescriptionIndex fres = mr.location().field->get_resources();224 DescriptionIndex fres = mr.location().field->get_resources();
225 ResourceAmount amount = mr.location().field->get_initial_res_amount() -225 ResourceAmount amount = mr.location().field->get_initial_res_amount() -
@@ -244,7 +244,7 @@
244 totalchance += 4;244 totalchance += 4;
245 else if (amount <= 6)245 else if (amount <= 6)
246 totalchance += 2;246 totalchance += 2;
247 } while (mr.advance(map));247 } while (mr.advance(*map));
248248
249 if (totalres == 0) {249 if (totalres == 0) {
250 molog(" All resources full\n");250 molog(" All resources full\n");
@@ -257,7 +257,7 @@
257 assert(totalchance);257 assert(totalchance);
258 pick = game.logic_rand() % totalchance;258 pick = game.logic_rand() % totalchance;
259 mr =259 mr =
260 MapRegion<Area<FCoords>>(map, Area<FCoords>(map.get_fcoords(get_position()), action.iparam1));260 MapRegion<Area<FCoords>>(*map, Area<FCoords>(map->get_fcoords(get_position()), action.iparam1));
261261
262 do {262 do {
263 DescriptionIndex fres = mr.location().field->get_resources();263 DescriptionIndex fres = mr.location().field->get_resources();
@@ -272,10 +272,10 @@
272 assert(amount > 0);272 assert(amount > 0);
273273
274 --amount;274 --amount;
275 map.set_resources(mr.location(), mr.location().field->get_initial_res_amount() - amount);275 map->set_resources(mr.location(), mr.location().field->get_initial_res_amount() - amount);
276 break;276 break;
277 }277 }
278 } while (mr.advance(map));278 } while (mr.advance(*map));
279279
280 if (pick >= 0) {280 if (pick >= 0) {
281 molog(" Not successful this time\n");281 molog(" Not successful this time\n");
@@ -341,7 +341,7 @@
341bool Worker::run_findobject(Game& game, State& state, const Action& action) {341bool Worker::run_findobject(Game& game, State& state, const Action& action) {
342 CheckStepWalkOn cstep(descr().movecaps(), false);342 CheckStepWalkOn cstep(descr().movecaps(), false);
343343
344 Map& map = game.map();344 const Map& map = game.map();
345 Area<FCoords> area(map.get_fcoords(get_position()), 0);345 Area<FCoords> area(map.get_fcoords(get_position()), 0);
346 bool found_reserved = false;346 bool found_reserved = false;
347347
@@ -486,7 +486,7 @@
486486
487bool Worker::run_findspace(Game& game, State& state, const Action& action) {487bool Worker::run_findspace(Game& game, State& state, const Action& action) {
488 std::vector<Coords> list;488 std::vector<Coords> list;
489 Map& map = game.map();489 const Map& map = game.map();
490 const World& world = game.world();490 const World& world = game.world();
491491
492 CheckStepDefault cstep(descr().movecaps());492 CheckStepDefault cstep(descr().movecaps());
@@ -706,7 +706,7 @@
706 }706 }
707 }707 }
708708
709 Map& map = game.map();709 const Map& map = game.map();
710 Coords pos = get_position();710 Coords pos = get_position();
711 FCoords fpos = map.get_fcoords(pos);711 FCoords fpos = map.get_fcoords(pos);
712712
@@ -863,8 +863,7 @@
863 * possible.863 * possible.
864 */864 */
865bool Worker::run_geologist_find(Game& game, State& state, const Action&) {865bool Worker::run_geologist_find(Game& game, State& state, const Action&) {
866 const Map& map = game.map();866 const FCoords position = game.map().get_fcoords(get_position());
867 const FCoords position = map.get_fcoords(get_position());
868 BaseImmovable const* const imm = position.field->get_immovable();867 BaseImmovable const* const imm = position.field->get_immovable();
869 const World& world = game.world();868 const World& world = game.world();
870869
@@ -1285,7 +1284,7 @@
1285}1284}
12861285
1287void Worker::transfer_update(Game& game, State& /* state */) {1286void Worker::transfer_update(Game& game, State& /* state */) {
1288 Map& map = game.map();1287 const Map& map = game.map();
1289 PlayerImmovable* location = get_location(game);1288 PlayerImmovable* location = get_location(game);
12901289
1291 // We expect to always have a location at this point,1290 // We expect to always have a location at this point,
@@ -2235,7 +2234,7 @@
2235 return pop_task(game);2234 return pop_task(game);
2236 }2235 }
22372236
2238 Map& map = game.map();2237 const Map& map = game.map();
2239 PlayerImmovable const* location = get_location(game);2238 PlayerImmovable const* location = get_location(game);
22402239
2241 if (location && &location->owner() == &owner()) {2240 if (location && &location->owner() == &owner()) {
@@ -2354,7 +2353,7 @@
2354 }2353 }
23552354
2356 //2355 //
2357 Map& map = game.map();2356 const Map& map = game.map();
2358 const World& world = game.world();2357 const World& world = game.world();
2359 Area<FCoords> owner_area(2358 Area<FCoords> owner_area(
2360 map.get_fcoords(dynamic_cast<Flag&>(*get_location(game)).get_position()), state.ivar2);2359 map.get_fcoords(dynamic_cast<Flag&>(*get_location(game)).get_position()), state.ivar2);
@@ -2482,7 +2481,7 @@
2482 return pop_task(game);2481 return pop_task(game);
2483 }2482 }
24842483
2485 Map& map = game.map();2484 const Map& map = game.map();
24862485
2487 // If not yet time to go home2486 // If not yet time to go home
2488 if (static_cast<int32_t>(state.ivar2 - game.get_gametime()) > 0) {2487 if (static_cast<int32_t>(state.ivar2 - game.get_gametime()) > 0) {
24892488
=== modified file 'src/logic/player.cc'
--- src/logic/player.cc 2017-08-16 04:31:56 +0000
+++ src/logic/player.cc 2017-08-20 12:33:35 +0000
@@ -60,7 +60,7 @@
60 const Widelands::PlayerNumber player_number,60 const Widelands::PlayerNumber player_number,
61 const Widelands::Coords& location,61 const Widelands::Coords& location,
62 const Widelands::BuildingDescr* descr) {62 const Widelands::BuildingDescr* descr) {
63 Widelands::Map& map = egbase.map();63 const Widelands::Map& map = egbase.map();
64 Widelands::FCoords c[4]; // Big buildings occupy 4 locations.64 Widelands::FCoords c[4]; // Big buildings occupy 4 locations.
65 c[0] = map.get_fcoords(location);65 c[0] = map.get_fcoords(location);
66 map.get_brn(c[0], &c[1]);66 map.get_brn(c[0], &c[1]);
@@ -412,7 +412,7 @@
412===============412===============
413*/413*/
414Road* Player::build_road(const Path& path) {414Road* Player::build_road(const Path& path) {
415 Map& map = egbase().map();415 const Map& map = egbase().map();
416 FCoords fc = map.get_fcoords(path.get_start());416 FCoords fc = map.get_fcoords(path.get_start());
417 if (upcast(Flag, start, fc.field->get_immovable())) {417 if (upcast(Flag, start, fc.field->get_immovable())) {
418 if (upcast(Flag, end, map.get_immovable(path.get_end()))) {418 if (upcast(Flag, end, map.get_immovable(path.get_end()))) {
@@ -441,7 +441,7 @@
441}441}
442442
443Road& Player::force_road(const Path& path) {443Road& Player::force_road(const Path& path) {
444 Map& map = egbase().map();444 const Map& map = egbase().map();
445 FCoords c = map.get_fcoords(path.get_start());445 FCoords c = map.get_fcoords(path.get_start());
446 Flag& start = force_flag(c);446 Flag& start = force_flag(c);
447 Flag& end = force_flag(map.get_fcoords(path.get_end()));447 Flag& end = force_flag(map.get_fcoords(path.get_end()));
@@ -466,7 +466,7 @@
466466
467Building& Player::force_building(Coords const location,467Building& Player::force_building(Coords const location,
468 const BuildingDescr::FormerBuildings& former_buildings) {468 const BuildingDescr::FormerBuildings& former_buildings) {
469 Map& map = egbase().map();469 const Map& map = egbase().map();
470 DescriptionIndex idx = former_buildings.back();470 DescriptionIndex idx = former_buildings.back();
471 const BuildingDescr* descr = egbase().tribes().get_building_descr(idx);471 const BuildingDescr* descr = egbase().tribes().get_building_descr(idx);
472 terraform_for_building(egbase(), player_number(), location, descr);472 terraform_for_building(egbase(), player_number(), location, descr);
@@ -481,7 +481,7 @@
481 DescriptionIndex b_idx,481 DescriptionIndex b_idx,
482 const BuildingDescr::FormerBuildings& former_buildings) {482 const BuildingDescr::FormerBuildings& former_buildings) {
483 EditorGameBase& eg = egbase();483 EditorGameBase& eg = egbase();
484 Map& map = eg.map();484 const Map& map = eg.map();
485 const Tribes& tribes = eg.tribes();485 const Tribes& tribes = eg.tribes();
486 const PlayerNumber pn = player_number();486 const PlayerNumber pn = player_number();
487487
@@ -833,7 +833,7 @@
833 if (soldiers)833 if (soldiers)
834 soldiers->clear();834 soldiers->clear();
835835
836 Map& map = egbase().map();836 const Map& map = egbase().map();
837 std::vector<BaseImmovable*> flags;837 std::vector<BaseImmovable*> flags;
838838
839 map.find_reachable_immovables_unique(Area<FCoords>(map.get_fcoords(flag.get_position()), 25),839 map.find_reachable_immovables_unique(Area<FCoords>(map.get_fcoords(flag.get_position()), 25),
840840
=== modified file 'src/logic/replay_game_controller.cc'
--- src/logic/replay_game_controller.cc 2017-06-24 10:38:19 +0000
+++ src/logic/replay_game_controller.cc 2017-08-20 12:33:35 +0000
@@ -31,9 +31,6 @@
31 speed_(1000),31 speed_(1000),
32 paused_(false) {32 paused_(false) {
33 game_.set_game_controller(this);33 game_.set_game_controller(this);
34
35 // We have to create an empty map, otherwise nothing will load properly
36 game.set_map(new Widelands::Map);
37 replayreader_.reset(new Widelands::ReplayReader(game_, filename));34 replayreader_.reset(new Widelands::ReplayReader(game_, filename));
38}35}
3936
4037
=== modified file 'src/map_io/map_bob_packet.cc'
--- src/map_io/map_bob_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_bob_packet.cc 2017-08-20 12:33:35 +0000
@@ -75,13 +75,13 @@
75 FileRead fr;75 FileRead fr;
76 fr.open(fs, "binary/bob");76 fr.open(fs, "binary/bob");
7777
78 Map& map = egbase.map();78 Map* map = egbase.mutable_map();
79 map.recalc_whole_map(egbase.world()); // for movecaps checks in ReadBob79 map->recalc_whole_map(egbase.world()); // for movecaps checks in ReadBob
80 try {80 try {
81 uint16_t const packet_version = fr.unsigned_16();81 uint16_t const packet_version = fr.unsigned_16();
82 if (packet_version == kCurrentPacketVersion)82 if (packet_version == kCurrentPacketVersion)
83 for (uint16_t y = 0; y < map.get_height(); ++y) {83 for (uint16_t y = 0; y < map->get_height(); ++y) {
84 for (uint16_t x = 0; x < map.get_width(); ++x) {84 for (uint16_t x = 0; x < map->get_width(); ++x) {
85 uint32_t const nr_bobs = fr.unsigned_32();85 uint32_t const nr_bobs = fr.unsigned_32();
86 for (uint32_t i = 0; i < nr_bobs; ++i)86 for (uint32_t i = 0; i < nr_bobs; ++i)
87 read_bob(fr, egbase, mol, Coords(x, y), lookup_table);87 read_bob(fr, egbase, mol, Coords(x, y), lookup_table);
8888
=== modified file 'src/map_io/map_building_packet.cc'
--- src/map_io/map_building_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_building_packet.cc 2017-08-20 12:33:35 +0000
@@ -60,7 +60,7 @@
60 try {60 try {
61 uint16_t const packet_version = fr.unsigned_16();61 uint16_t const packet_version = fr.unsigned_16();
62 if (packet_version == kCurrentPacketVersion) {62 if (packet_version == kCurrentPacketVersion) {
63 Map& map = egbase.map();63 const Map& map = egbase.map();
64 uint16_t const width = map.get_width();64 uint16_t const width = map.get_width();
65 uint16_t const height = map.get_height();65 uint16_t const height = map.get_height();
66 FCoords c;66 FCoords c;
6767
=== modified file 'src/map_io/map_buildingdata_packet.cc'
--- src/map_io/map_buildingdata_packet.cc 2017-08-16 13:23:15 +0000
+++ src/map_io/map_buildingdata_packet.cc 2017-08-20 12:33:35 +0000
@@ -434,9 +434,10 @@
434 }434 }
435 }435 }
436436
437 const Map& map = game.map();
438
437 if (uint32_t const conquer_radius = warehouse.descr().get_conquers()) {439 if (uint32_t const conquer_radius = warehouse.descr().get_conquers()) {
438 // Add to map of military influence.440 // Add to map of military influence.
439 const Map& map = game.map();
440 Area<FCoords> a(map.get_fcoords(warehouse.get_position()), conquer_radius);441 Area<FCoords> a(map.get_fcoords(warehouse.get_position()), conquer_radius);
441 const Field& first_map_field = map[0];442 const Field& first_map_field = map[0];
442 Player::Field* const player_fields = player.fields_;443 Player::Field* const player_fields = player.fields_;
@@ -447,7 +448,7 @@
447 while (mr.advance(map));448 while (mr.advance(map));
448 }449 }
449 player.see_area(Area<FCoords>(450 player.see_area(Area<FCoords>(
450 game.map().get_fcoords(warehouse.get_position()), warehouse.descr().vision_range()));451 map.get_fcoords(warehouse.get_position()), warehouse.descr().vision_range()));
451 warehouse.next_military_act_ = game.get_gametime();452 warehouse.next_military_act_ = game.get_gametime();
452 } else {453 } else {
453 throw UnhandledVersionError(454 throw UnhandledVersionError(
@@ -830,7 +831,7 @@
830 fw.unsigned_16(kCurrentPacketVersion);831 fw.unsigned_16(kCurrentPacketVersion);
831832
832 // Walk the map again833 // Walk the map again
833 Map& map = egbase.map();834 const Map& map = egbase.map();
834 const uint32_t mapwidth = map.get_width();835 const uint32_t mapwidth = map.get_width();
835 MapIndex const max_index = map.max_index();836 MapIndex const max_index = map.max_index();
836 for (MapIndex i = 0; i < max_index; ++i) {837 for (MapIndex i = 0; i < max_index; ++i) {
837838
=== modified file 'src/map_io/map_elemental_packet.cc'
--- src/map_io/map_elemental_packet.cc 2017-08-16 13:23:15 +0000
+++ src/map_io/map_elemental_packet.cc 2017-08-20 12:33:35 +0000
@@ -114,7 +114,7 @@
114}114}
115115
116void MapElementalPacket::read(FileSystem& fs, EditorGameBase& egbase, bool, MapObjectLoader&) {116void MapElementalPacket::read(FileSystem& fs, EditorGameBase& egbase, bool, MapObjectLoader&) {
117 pre_read(fs, &egbase.map());117 pre_read(fs, egbase.mutable_map());
118}118}
119119
120void MapElementalPacket::write(FileSystem& fs, EditorGameBase& egbase, MapObjectSaver&) {120void MapElementalPacket::write(FileSystem& fs, EditorGameBase& egbase, MapObjectSaver&) {
121121
=== modified file 'src/map_io/map_exploration_packet.cc'
--- src/map_io/map_exploration_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_exploration_packet.cc 2017-08-20 12:33:35 +0000
@@ -50,7 +50,7 @@
50 }50 }
5151
52 static_assert(kMaxPlayers < 32, "assert(MAX_PLAYERS < 32) failed.");52 static_assert(kMaxPlayers < 32, "assert(MAX_PLAYERS < 32) failed.");
53 Map& map = egbase.map();53 const Map& map = egbase.map();
54 PlayerNumber const nr_players = map.get_nrplayers();54 PlayerNumber const nr_players = map.get_nrplayers();
55 MapIndex const max_index = map.max_index();55 MapIndex const max_index = map.max_index();
56 try {56 try {
@@ -82,7 +82,7 @@
82 fw.unsigned_16(kCurrentPacketVersion);82 fw.unsigned_16(kCurrentPacketVersion);
8383
84 static_assert(kMaxPlayers < 32, "assert(MAX_PLAYERS < 32) failed.");84 static_assert(kMaxPlayers < 32, "assert(MAX_PLAYERS < 32) failed.");
85 Map& map = egbase.map();85 const Map& map = egbase.map();
86 PlayerNumber const nr_players = map.get_nrplayers();86 PlayerNumber const nr_players = map.get_nrplayers();
87 MapIndex const max_index = map.max_index();87 MapIndex const max_index = map.max_index();
88 for (MapIndex i = 0; i < max_index; ++i) {88 for (MapIndex i = 0; i < max_index; ++i) {
8989
=== modified file 'src/map_io/map_heights_packet.cc'
--- src/map_io/map_heights_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_heights_packet.cc 2017-08-20 12:33:35 +0000
@@ -38,7 +38,7 @@
38 try {38 try {
39 uint16_t const packet_version = fr.unsigned_16();39 uint16_t const packet_version = fr.unsigned_16();
40 if (packet_version == kCurrentPacketVersion) {40 if (packet_version == kCurrentPacketVersion) {
41 Map& map = egbase.map();41 const Map& map = egbase.map();
42 MapIndex const max_index = map.max_index();42 MapIndex const max_index = map.max_index();
43 for (MapIndex i = 0; i < max_index; ++i)43 for (MapIndex i = 0; i < max_index; ++i)
44 map[i].set_height(fr.unsigned_8());44 map[i].set_height(fr.unsigned_8());
@@ -60,7 +60,7 @@
6060
61 fw.unsigned_16(kCurrentPacketVersion);61 fw.unsigned_16(kCurrentPacketVersion);
6262
63 Map& map = egbase.map();63 const Map& map = egbase.map();
64 MapIndex const max_index = map.max_index();64 MapIndex const max_index = map.max_index();
65 for (MapIndex i = 0; i < max_index; ++i)65 for (MapIndex i = 0; i < max_index; ++i)
66 fw.unsigned_8(map[i].get_height());66 fw.unsigned_8(map[i].get_height());
6767
=== modified file 'src/map_io/map_node_ownership_packet.cc'
--- src/map_io/map_node_ownership_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_node_ownership_packet.cc 2017-08-20 12:33:35 +0000
@@ -51,7 +51,7 @@
51 try {51 try {
52 uint16_t const packet_version = fr.unsigned_16();52 uint16_t const packet_version = fr.unsigned_16();
53 if (packet_version == kCurrentPacketVersion) {53 if (packet_version == kCurrentPacketVersion) {
54 Map& map = egbase.map();54 const Map& map = egbase.map();
55 MapIndex const max_index = map.max_index();55 MapIndex const max_index = map.max_index();
56 for (MapIndex i = 0; i < max_index; ++i)56 for (MapIndex i = 0; i < max_index; ++i)
57 map[i].set_owned_by(fr.unsigned_8());57 map[i].set_owned_by(fr.unsigned_8());
@@ -69,7 +69,7 @@
6969
70 fw.unsigned_16(kCurrentPacketVersion);70 fw.unsigned_16(kCurrentPacketVersion);
7171
72 Map& map = egbase.map();72 const Map& map = egbase.map();
73 MapIndex const max_index = map.max_index();73 MapIndex const max_index = map.max_index();
74 for (MapIndex i = 0; i < max_index; ++i)74 for (MapIndex i = 0; i < max_index; ++i)
75 fw.unsigned_8(map[i].get_owned_by());75 fw.unsigned_8(map[i].get_owned_by());
7676
=== modified file 'src/map_io/map_objective_packet.cc'
--- src/map_io/map_objective_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_objective_packet.cc 2017-08-20 12:33:35 +0000
@@ -45,7 +45,7 @@
45 char const* const name = s->get_name();45 char const* const name = s->get_name();
46 try {46 try {
47 std::unique_ptr<Objective> objective(new Objective(name));47 std::unique_ptr<Objective> objective(new Objective(name));
48 Map::Objectives* objectives = egbase.map().mutable_objectives();48 Map::Objectives* objectives = egbase.mutable_map()->mutable_objectives();
49 if (objectives->count(name)) {49 if (objectives->count(name)) {
50 throw GameDataError("duplicated");50 throw GameDataError("duplicated");
51 }51 }
5252
=== modified file 'src/map_io/map_player_names_and_tribes_packet.cc'
--- src/map_io/map_player_names_and_tribes_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_player_names_and_tribes_packet.cc 2017-08-20 12:33:35 +0000
@@ -44,7 +44,7 @@
44 EditorGameBase& egbase,44 EditorGameBase& egbase,
45 bool const skip,45 bool const skip,
46 MapObjectLoader&) {46 MapObjectLoader&) {
47 pre_read(fs, egbase.get_map(), skip);47 pre_read(fs, egbase.mutable_map(), skip);
48}48}
4949
50void MapPlayerNamesAndTribesPacket::pre_read(FileSystem& fs, Map* const map, bool const skip) {50void MapPlayerNamesAndTribesPacket::pre_read(FileSystem& fs, Map* const map, bool const skip) {
5151
=== modified file 'src/map_io/map_player_position_packet.cc'
--- src/map_io/map_player_position_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_player_position_packet.cc 2017-08-20 12:33:35 +0000
@@ -42,12 +42,12 @@
42 // Read all the positions42 // Read all the positions
43 // This could bring trouble if one player position/ is not set (this43 // This could bring trouble if one player position/ is not set (this
44 // is possible in the editor), is also -1, -1.44 // is possible in the editor), is also -1, -1.
45 Map& map = egbase.map();45 Map* map = egbase.mutable_map();
46 Extent const extent = map.extent();46 Extent const extent = map->extent();
47 PlayerNumber const nr_players = map.get_nrplayers();47 PlayerNumber const nr_players = map->get_nrplayers();
48 iterate_player_numbers(p, nr_players) {48 iterate_player_numbers(p, nr_players) {
49 try {49 try {
50 map.set_starting_pos(50 map->set_starting_pos(
51 p,51 p,
52 get_safe_coords((boost::format("player_%u") % static_cast<unsigned int>(p)).str(),52 get_safe_coords((boost::format("player_%u") % static_cast<unsigned int>(p)).str(),
53 extent, &s));53 extent, &s));
5454
=== modified file 'src/map_io/map_port_spaces_packet.cc'
--- src/map_io/map_port_spaces_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_port_spaces_packet.cc 2017-08-20 12:33:35 +0000
@@ -39,8 +39,8 @@
39 prof.read("port_spaces", nullptr, fs);39 prof.read("port_spaces", nullptr, fs);
40 Section& s1 = prof.get_safe_section("global");40 Section& s1 = prof.get_safe_section("global");
4141
42 Map& map = egbase.map();42 Map* map = egbase.mutable_map();
43 Extent ext(map.extent());43 Extent ext(map->extent());
4444
45 try {45 try {
46 int32_t const packet_version = s1.get_int("packet_version");46 int32_t const packet_version = s1.get_int("packet_version");
@@ -51,7 +51,7 @@
5151
52 Section& s2 = prof.get_safe_section("port_spaces");52 Section& s2 = prof.get_safe_section("port_spaces");
53 for (uint16_t i = 0; i < num; ++i) {53 for (uint16_t i = 0; i < num; ++i) {
54 map.set_port_space(54 map->set_port_space(
55 get_safe_coords(std::to_string(static_cast<unsigned int>(i)), ext, &s2), true);55 get_safe_coords(std::to_string(static_cast<unsigned int>(i)), ext, &s2), true);
56 }56 }
57 } else {57 } else {
@@ -69,7 +69,7 @@
69 Section& s1 = prof.create_section("global");69 Section& s1 = prof.create_section("global");
70 s1.set_int("packet_version", kCurrentPacketVersion);70 s1.set_int("packet_version", kCurrentPacketVersion);
7171
72 Map& map = egbase.map();72 const Map& map = egbase.map();
73 const uint16_t num = map.get_port_spaces().size();73 const uint16_t num = map.get_port_spaces().size();
74 s1.set_int("number_of_port_spaces", num);74 s1.set_int("number_of_port_spaces", num);
7575
7676
=== modified file 'src/map_io/map_resources_packet.cc'
--- src/map_io/map_resources_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_resources_packet.cc 2017-08-20 12:33:35 +0000
@@ -39,7 +39,7 @@
39 FileRead fr;39 FileRead fr;
40 fr.open(fs, "binary/resource");40 fr.open(fs, "binary/resource");
4141
42 Map& map = egbase.map();42 Map* map = egbase.mutable_map();
43 const World& world = egbase.world();43 const World& world = egbase.world();
4444
45 try {45 try {
@@ -63,8 +63,8 @@
63 smap[id] = res;63 smap[id] = res;
64 }64 }
6565
66 for (uint16_t y = 0; y < map.get_height(); ++y) {66 for (uint16_t y = 0; y < map->get_height(); ++y) {
67 for (uint16_t x = 0; x < map.get_width(); ++x) {67 for (uint16_t x = 0; x < map->get_width(); ++x) {
68 DescriptionIndex const id = fr.unsigned_8();68 DescriptionIndex const id = fr.unsigned_8();
69 ResourceAmount const found_amount = fr.unsigned_8();69 ResourceAmount const found_amount = fr.unsigned_8();
70 ResourceAmount const amount = found_amount;70 ResourceAmount const amount = found_amount;
@@ -85,9 +85,9 @@
8585
86 if (0xa < set_id)86 if (0xa < set_id)
87 throw "Unknown resource in map file. It is not in world!\n";87 throw "Unknown resource in map file. It is not in world!\n";
88 const auto fcoords = map.get_fcoords(Coords(x, y));88 const auto fcoords = map->get_fcoords(Coords(x, y));
89 map.initialize_resources(fcoords, set_id, set_start_amount);89 map->initialize_resources(fcoords, set_id, set_start_amount);
90 map.set_resources(fcoords, set_amount);90 map->set_resources(fcoords, set_amount);
91 }91 }
92 }92 }
93 } else {93 } else {
9494
=== modified file 'src/map_io/map_roaddata_packet.cc'
--- src/map_io/map_roaddata_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_roaddata_packet.cc 2017-08-20 12:33:35 +0000
@@ -104,7 +104,7 @@
104 Path p(road.flags_[0]->get_position());104 Path p(road.flags_[0]->get_position());
105 for (Path::StepVector::size_type i = nr_steps; i; --i)105 for (Path::StepVector::size_type i = nr_steps; i; --i)
106 try {106 try {
107 p.append(egbase.map(), read_direction_8(&fr));107 p.append(map, read_direction_8(&fr));
108 } catch (const WException& e) {108 } catch (const WException& e) {
109 throw GameDataError(109 throw GameDataError(
110 "step #%lu: %s", static_cast<long unsigned int>(nr_steps - i), e.what());110 "step #%lu: %s", static_cast<long unsigned int>(nr_steps - i), e.what());
111111
=== modified file 'src/map_io/map_saver.cc'
--- src/map_io/map_saver.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_saver.cc 2017-08-20 12:33:35 +0000
@@ -70,8 +70,9 @@
70}70}
7171
72void MapSaver::save() {72void MapSaver::save() {
73 const Map& map = egbase_.map();
73 std::string timer_message = "MapSaver::save() for '";74 std::string timer_message = "MapSaver::save() for '";
74 timer_message += egbase_.map().get_name();75 timer_message += map.get_name();
75 timer_message += "' took %ums";76 timer_message += "' took %ums";
76 ScopedTimer timer(timer_message);77 ScopedTimer timer(timer_message);
7778
@@ -160,9 +161,6 @@
160161
161 // We don't save these when saving a map in the editor.162 // We don't save these when saving a map in the editor.
162 if (is_game) {163 if (is_game) {
163
164 const Map& map = egbase_.map();
165
166 PlayerNumber const nr_players = map.get_nrplayers();164 PlayerNumber const nr_players = map.get_nrplayers();
167165
168 // allowed worker types166 // allowed worker types
@@ -285,7 +283,7 @@
285 log("took %ums\n ", timer.ms_since_last_query());283 log("took %ums\n ", timer.ms_since_last_query());
286284
287 log("Writing map images ... ");285 log("Writing map images ... ");
288 save_map_images(&fs_, egbase_.map().filesystem());286 save_map_images(&fs_, map.filesystem());
289 log("took %ums\n ", timer.ms_since_last_query());287 log("took %ums\n ", timer.ms_since_last_query());
290288
291 if (is_game) {289 if (is_game) {
292290
=== modified file 'src/map_io/map_terrain_packet.cc'
--- src/map_io/map_terrain_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_terrain_packet.cc 2017-08-20 12:33:35 +0000
@@ -41,7 +41,7 @@
41 FileRead fr;41 FileRead fr;
42 fr.open(fs, "binary/terrain");42 fr.open(fs, "binary/terrain");
4343
44 Map& map = egbase.map();44 const Map& map = egbase.map();
45 const World& world = egbase.world();45 const World& world = egbase.world();
4646
47 try {47 try {
4848
=== modified file 'src/map_io/map_version_packet.cc'
--- src/map_io/map_version_packet.cc 2017-01-25 18:55:59 +0000
+++ src/map_io/map_version_packet.cc 2017-08-20 12:33:35 +0000
@@ -42,9 +42,9 @@
42 try {42 try {
43 prof.read("version", nullptr, fs);43 prof.read("version", nullptr, fs);
44 } catch (...) {44 } catch (...) {
45 Map& map = egbase.map();45 Map* map = egbase.mutable_map();
46 map.map_version_.map_version_timestamp = 0;46 map->map_version_.map_version_timestamp = 0;
47 map.map_version_.map_creator_version = "unknown";47 map->map_version_.map_creator_version = "unknown";
48 return;48 return;
49 }49 }
5050
@@ -55,14 +55,14 @@
55 if ((packet_version == kCurrentPacketVersion) ||55 if ((packet_version == kCurrentPacketVersion) ||
56 (packet_version > kCurrentPacketVersion &&56 (packet_version > kCurrentPacketVersion &&
57 forward_compatibility <= kCurrentPacketVersion)) {57 forward_compatibility <= kCurrentPacketVersion)) {
58 Map& map = egbase.map();58 Map* map = egbase.mutable_map();
59 map.map_version_.map_source_url = globv.get_safe_string("map_source_url");59 map->map_version_.map_source_url = globv.get_safe_string("map_source_url");
60 map.map_version_.map_source_release = globv.get_safe_string("map_release");60 map->map_version_.map_source_release = globv.get_safe_string("map_release");
61 map.map_version_.map_creator_version = globv.get_safe_string("map_creator_version");61 map->map_version_.map_creator_version = globv.get_safe_string("map_creator_version");
62 map.map_version_.map_version_major = globv.get_safe_int("map_version_major");62 map->map_version_.map_version_major = globv.get_safe_int("map_version_major");
63 map.map_version_.map_version_minor = globv.get_safe_int("map_version_minor");63 map->map_version_.map_version_minor = globv.get_safe_int("map_version_minor");
64 uint32_t ts = static_cast<uint32_t>(globv.get_safe_int("map_version_timestamp"));64 uint32_t ts = static_cast<uint32_t>(globv.get_safe_int("map_version_timestamp"));
65 map.map_version_.map_version_timestamp = ts;65 map->map_version_.map_version_timestamp = ts;
66 } else {66 } else {
67 throw UnhandledVersionError("MapVersionPacket", packet_version, kCurrentPacketVersion);67 throw UnhandledVersionError("MapVersionPacket", packet_version, kCurrentPacketVersion);
68 }68 }
@@ -108,7 +108,7 @@
108 // TODO(unknown): -- we could store the unix time in uint32, as a partial fix to 2038 problem.108 // TODO(unknown): -- we could store the unix time in uint32, as a partial fix to 2038 problem.
109 // There seems to be a get_safe_natural method, but not corresponding setter.109 // There seems to be a get_safe_natural method, but not corresponding setter.
110110
111 Map& map = egbase.map();111 const Map& map = egbase.map();
112 globs.set_string("map_source_url", map.map_version_.map_source_url);112 globs.set_string("map_source_url", map.map_version_.map_source_url);
113 globs.set_string("map_release", map.map_version_.map_source_release);113 globs.set_string("map_release", map.map_version_.map_source_release);
114 globs.set_string("map_creator_version", map.map_version_.map_creator_version);114 globs.set_string("map_creator_version", map.map_version_.map_creator_version);
115115
=== modified file 'src/scripting/lua_bases.cc'
--- src/scripting/lua_bases.cc 2017-01-30 14:40:12 +0000
+++ src/scripting/lua_bases.cc 2017-08-20 12:33:35 +0000
@@ -458,7 +458,7 @@
458*/458*/
459int LuaPlayerBase::place_road(lua_State* L) {459int LuaPlayerBase::place_road(lua_State* L) {
460 EditorGameBase& egbase = get_egbase(L);460 EditorGameBase& egbase = get_egbase(L);
461 Map& map = egbase.map();461 const Map& map = egbase.map();
462462
463 Flag* starting_flag = (*get_user_class<LuaMaps::LuaFlag>(L, 2))->get(L, egbase);463 Flag* starting_flag = (*get_user_class<LuaMaps::LuaFlag>(L, 2))->get(L, egbase);
464 Coords current = starting_flag->get_position();464 Coords current = starting_flag->get_position();
465465
=== modified file 'src/scripting/lua_game.cc'
--- src/scripting/lua_game.cc 2017-08-17 15:34:45 +0000
+++ src/scripting/lua_game.cc 2017-08-20 12:33:35 +0000
@@ -565,8 +565,7 @@
565int LuaPlayer::add_objective(lua_State* L) {565int LuaPlayer::add_objective(lua_State* L) {
566 Game& game = get_game(L);566 Game& game = get_game(L);
567567
568 Map* map = game.get_map();568 Map::Objectives* objectives = game.mutable_map()->mutable_objectives();
569 Map::Objectives* objectives = map->mutable_objectives();
570569
571 const std::string name = luaL_checkstring(L, 2);570 const std::string name = luaL_checkstring(L, 2);
572 if (objectives->count(name))571 if (objectives->count(name))
@@ -596,13 +595,13 @@
596int LuaPlayer::reveal_fields(lua_State* L) {595int LuaPlayer::reveal_fields(lua_State* L) {
597 EditorGameBase& egbase = get_egbase(L);596 EditorGameBase& egbase = get_egbase(L);
598 Player& p = get(L, egbase);597 Player& p = get(L, egbase);
599 Map& m = egbase.map();598 const Map& map = egbase.map();
600599
601 luaL_checktype(L, 2, LUA_TTABLE);600 luaL_checktype(L, 2, LUA_TTABLE);
602601
603 lua_pushnil(L); /* first key */602 lua_pushnil(L); /* first key */
604 while (lua_next(L, 2) != 0) {603 while (lua_next(L, 2) != 0) {
605 p.see_node(m, m[0], (*get_user_class<LuaField>(L, -1))->fcoords(L), egbase.get_gametime());604 p.see_node(map, map[0], (*get_user_class<LuaField>(L, -1))->fcoords(L), egbase.get_gametime());
606 lua_pop(L, 1);605 lua_pop(L, 1);
607 }606 }
608607
@@ -626,14 +625,13 @@
626int LuaPlayer::hide_fields(lua_State* L) {625int LuaPlayer::hide_fields(lua_State* L) {
627 EditorGameBase& egbase = get_egbase(L);626 EditorGameBase& egbase = get_egbase(L);
628 Player& p = get(L, egbase);627 Player& p = get(L, egbase);
629 Map& m = egbase.map();
630628
631 luaL_checktype(L, 2, LUA_TTABLE);629 luaL_checktype(L, 2, LUA_TTABLE);
632 const bool mode = !lua_isnone(L, 3) && luaL_checkboolean(L, 3);630 const bool mode = !lua_isnone(L, 3) && luaL_checkboolean(L, 3);
633631
634 lua_pushnil(L); /* first key */632 lua_pushnil(L); /* first key */
635 while (lua_next(L, 2) != 0) {633 while (lua_next(L, 2) != 0) {
636 p.unsee_node((*get_user_class<LuaField>(L, -1))->fcoords(L).field - &m[0],634 p.unsee_node((*get_user_class<LuaField>(L, -1))->fcoords(L).field - &egbase.map()[0],
637 egbase.get_gametime(),635 egbase.get_gametime(),
638 mode ? Player::UnseeNodeMode::kUnexplore : Player::UnseeNodeMode::kUnsee);636 mode ? Player::UnseeNodeMode::kUnexplore : Player::UnseeNodeMode::kUnsee);
639 lua_pop(L, 1);637 lua_pop(L, 1);
@@ -691,15 +689,15 @@
691*/689*/
692int LuaPlayer::get_ships(lua_State* L) {690int LuaPlayer::get_ships(lua_State* L) {
693 EditorGameBase& egbase = get_egbase(L);691 EditorGameBase& egbase = get_egbase(L);
694 Map* map = egbase.get_map();692 const Map& map = egbase.map();
695 PlayerNumber p = (get(L, egbase)).player_number();693 PlayerNumber p = (get(L, egbase)).player_number();
696 lua_newtable(L);694 lua_newtable(L);
697 uint32_t cidx = 1;695 uint32_t cidx = 1;
698696
699 std::set<OPtr<Ship>> found_ships;697 std::set<OPtr<Ship>> found_ships;
700 for (int16_t y = 0; y < map->get_height(); ++y) {698 for (int16_t y = 0; y < map.get_height(); ++y) {
701 for (int16_t x = 0; x < map->get_width(); ++x) {699 for (int16_t x = 0; x < map.get_width(); ++x) {
702 FCoords f = map->get_fcoords(Coords(x, y));700 FCoords f = map.get_fcoords(Coords(x, y));
703 // there are too many bobs on the map so we investigate701 // there are too many bobs on the map so we investigate
704 // only bobs on water702 // only bobs on water
705 if (f.field->nodecaps() & MOVECAPS_SWIM) {703 if (f.field->nodecaps() & MOVECAPS_SWIM) {
@@ -734,7 +732,6 @@
734*/732*/
735int LuaPlayer::get_buildings(lua_State* L) {733int LuaPlayer::get_buildings(lua_State* L) {
736 EditorGameBase& egbase = get_egbase(L);734 EditorGameBase& egbase = get_egbase(L);
737 Map* map = egbase.get_map();
738 Player& p = get(L, egbase);735 Player& p = get(L, egbase);
739736
740 // if only one string, convert to array so that we can use737 // if only one string, convert to array so that we can use
@@ -770,7 +767,7 @@
770 continue;767 continue;
771768
772 lua_pushuint32(L, cidx++);769 lua_pushuint32(L, cidx++);
773 upcasted_map_object_to_lua(L, (*map)[vec[l].pos].get_immovable());770 upcasted_map_object_to_lua(L, egbase.map()[vec[l].pos].get_immovable());
774 lua_rawset(L, -3);771 lua_rawset(L, -3);
775 }772 }
776773
@@ -1087,7 +1084,7 @@
1087 std::string filename = _("%1% (%2%)");1084 std::string filename = _("%1% (%2%)");
1088 i18n::Textdomain td("maps");1085 i18n::Textdomain td("maps");
1089 filename =1086 filename =
1090 (boost::format(filename) % _(get_egbase(L).get_map()->get_name()) % o.descname().c_str())1087 (boost::format(filename) % _(get_egbase(L).map().get_name()) % o.descname().c_str())
1091 .str();1088 .str();
1092 get_game(L).save_handler().request_save(filename);1089 get_game(L).save_handler().request_save(filename);
1093 }1090 }
@@ -1103,7 +1100,7 @@
1103 Game& g = get_game(L);1100 Game& g = get_game(L);
1104 // The next call checks if the Objective still exists1101 // The next call checks if the Objective still exists
1105 get(L, g);1102 get(L, g);
1106 g.map().mutable_objectives()->erase(name_);1103 g.mutable_map()->mutable_objectives()->erase(name_);
1107 return 0;1104 return 0;
1108}1105}
11091106
@@ -1125,7 +1122,7 @@
1125 ==========================================================1122 ==========================================================
1126 */1123 */
1127Objective& LuaObjective::get(lua_State* L, Widelands::Game& g) {1124Objective& LuaObjective::get(lua_State* L, Widelands::Game& g) {
1128 Map::Objectives* objectives = g.map().mutable_objectives();1125 Map::Objectives* objectives = g.mutable_map()->mutable_objectives();
1129 Map::Objectives::iterator i = objectives->find(name_);1126 Map::Objectives::iterator i = objectives->find(name_);
1130 if (i == objectives->end()) {1127 if (i == objectives->end()) {
1131 report_error(L, "Objective with name '%s' doesn't exist!", name_.c_str());1128 report_error(L, "Objective with name '%s' doesn't exist!", name_.c_str());
11321129
=== modified file 'src/scripting/lua_map.cc'
--- src/scripting/lua_map.cc 2017-08-16 04:31:56 +0000
+++ src/scripting/lua_map.cc 2017-08-20 12:33:35 +0000
@@ -1171,10 +1171,10 @@
1171 for each player defined in the map.1171 for each player defined in the map.
1172*/1172*/
1173int LuaMap::get_player_slots(lua_State* L) {1173int LuaMap::get_player_slots(lua_State* L) {
1174 Map& m = get_egbase(L).map();1174 const Map& map = get_egbase(L).map();
11751175
1176 lua_createtable(L, m.get_nrplayers(), 0);1176 lua_createtable(L, map.get_nrplayers(), 0);
1177 for (Widelands::PlayerNumber i = 0; i < m.get_nrplayers(); i++) {1177 for (Widelands::PlayerNumber i = 0; i < map.get_nrplayers(); i++) {
1178 lua_pushuint32(L, i + 1);1178 lua_pushuint32(L, i + 1);
1179 to_lua<LuaMaps::LuaPlayerSlot>(L, new LuaMaps::LuaPlayerSlot(i + 1));1179 to_lua<LuaMaps::LuaPlayerSlot>(L, new LuaMaps::LuaPlayerSlot(i + 1));
1180 lua_settable(L, -3);1180 lua_settable(L, -3);
@@ -1252,11 +1252,11 @@
1252 uint32_t x = luaL_checkuint32(L, 2);1252 uint32_t x = luaL_checkuint32(L, 2);
1253 uint32_t y = luaL_checkuint32(L, 3);1253 uint32_t y = luaL_checkuint32(L, 3);
12541254
1255 Map& m = get_egbase(L).map();1255 const Map& map = get_egbase(L).map();
12561256
1257 if (x >= static_cast<uint32_t>(m.get_width()))1257 if (x >= static_cast<uint32_t>(map.get_width()))
1258 report_error(L, "x coordinate out of range!");1258 report_error(L, "x coordinate out of range!");
1259 if (y >= static_cast<uint32_t>(m.get_height()))1259 if (y >= static_cast<uint32_t>(map.get_height()))
1260 report_error(L, "y coordinate out of range!");1260 report_error(L, "y coordinate out of range!");
12611261
1262 return to_lua<LuaMaps::LuaField>(L, new LuaMaps::LuaField(x, y));1262 return to_lua<LuaMaps::LuaField>(L, new LuaMaps::LuaField(x, y));
@@ -1272,7 +1272,7 @@
1272// TODO(unknown): do we really want this function?1272// TODO(unknown): do we really want this function?
1273int LuaMap::recalculate(lua_State* L) {1273int LuaMap::recalculate(lua_State* L) {
1274 EditorGameBase& egbase = get_egbase(L);1274 EditorGameBase& egbase = get_egbase(L);
1275 egbase.map().recalc_whole_map(egbase.world());1275 egbase.mutable_map()->recalc_whole_map(egbase.world());
1276 return 0;1276 return 0;
1277}1277}
12781278
@@ -5787,7 +5787,7 @@
5787 report_error(L, "height must be <= %i", MAX_FIELD_HEIGHT);5787 report_error(L, "height must be <= %i", MAX_FIELD_HEIGHT);
57885788
5789 EditorGameBase& egbase = get_egbase(L);5789 EditorGameBase& egbase = get_egbase(L);
5790 egbase.map().set_height(egbase.world(), f, height);5790 egbase.mutable_map()->set_height(egbase.world(), f, height);
57915791
5792 return 0;5792 return 0;
5793}5793}
@@ -5865,9 +5865,9 @@
58655865
5866 auto c = fcoords(L);5866 auto c = fcoords(L);
5867 const auto current_amount = c.field->get_resources_amount();5867 const auto current_amount = c.field->get_resources_amount();
5868 auto& map = egbase.map();5868 auto* map = egbase.mutable_map();
5869 map.initialize_resources(c, res, c.field->get_initial_res_amount());5869 map->initialize_resources(c, res, c.field->get_initial_res_amount());
5870 map.set_resources(c, current_amount);5870 map->set_resources(c, current_amount);
5871 return 0;5871 return 0;
5872}5872}
58735873
@@ -5894,12 +5894,12 @@
5894 report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount,5894 report_error(L, "Illegal amount: %i, must be >= 0 and <= %i", amount,
5895 static_cast<unsigned int>(max_amount));5895 static_cast<unsigned int>(max_amount));
58965896
5897 auto& map = egbase.map();5897 auto* map = egbase.mutable_map();
5898 if (is_a(Game, &egbase)) {5898 if (is_a(Game, &egbase)) {
5899 map.set_resources(c, amount);5899 map->set_resources(c, amount);
5900 } else {5900 } else {
5901 // in editor, reset also initial amount5901 // in editor, reset also initial amount
5902 map.initialize_resources(c, res, amount);5902 map->initialize_resources(c, res, amount);
5903 }5903 }
5904 return 0;5904 return 0;
5905}5905}
@@ -5972,7 +5972,7 @@
5972 if (td == static_cast<DescriptionIndex>(-1))5972 if (td == static_cast<DescriptionIndex>(-1))
5973 report_error(L, "Unknown terrain '%s'", name);5973 report_error(L, "Unknown terrain '%s'", name);
59745974
5975 egbase.map().change_terrain(world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::R), td);5975 egbase.mutable_map()->change_terrain(world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::R), td);
59765976
5977 lua_pushstring(L, name);5977 lua_pushstring(L, name);
5978 return 1;5978 return 1;
@@ -5991,7 +5991,8 @@
5991 if (td == static_cast<DescriptionIndex>(INVALID_INDEX))5991 if (td == static_cast<DescriptionIndex>(INVALID_INDEX))
5992 report_error(L, "Unknown terrain '%s'", name);5992 report_error(L, "Unknown terrain '%s'", name);
59935993
5994 egbase.map().change_terrain(world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::D), td);5994 egbase.mutable_map()->change_terrain(
5995 world, TCoords<FCoords>(fcoords(L), TCoords<FCoords>::D), td);
59955996
5996 lua_pushstring(L, name);5997 lua_pushstring(L, name);
5997 return 1;5998 return 1;
@@ -6058,7 +6059,7 @@
6058*/6059*/
6059int LuaField::get_claimers(lua_State* L) {6060int LuaField::get_claimers(lua_State* L) {
6060 EditorGameBase& egbase = get_egbase(L);6061 EditorGameBase& egbase = get_egbase(L);
6061 Map& map = egbase.map();6062 const Map& map = egbase.map();
60626063
6063 std::vector<PlrInfluence> claimers;6064 std::vector<PlrInfluence> claimers;
60646065
@@ -6187,7 +6188,7 @@
6187 ==========================================================6188 ==========================================================
6188 */6189 */
6189int LuaField::region(lua_State* L, uint32_t radius) {6190int LuaField::region(lua_State* L, uint32_t radius) {
6190 Map& map = get_egbase(L).map();6191 const Map& map = get_egbase(L).map();
6191 MapRegion<Area<FCoords>> mr(map, Area<FCoords>(fcoords(L), radius));6192 MapRegion<Area<FCoords>> mr(map, Area<FCoords>(fcoords(L), radius));
61926193
6193 lua_newtable(L);6194 lua_newtable(L);
@@ -6203,7 +6204,7 @@
6203}6204}
62046205
6205int LuaField::hollow_region(lua_State* L, uint32_t radius, uint32_t inner_radius) {6206int LuaField::hollow_region(lua_State* L, uint32_t radius, uint32_t inner_radius) {
6206 Map& map = get_egbase(L).map();6207 const Map& map = get_egbase(L).map();
6207 HollowArea<Area<>> har(Area<>(coords_, radius), inner_radius);6208 HollowArea<Area<>> har(Area<>(coords_, radius), inner_radius);
62086209
6209 MapHollowRegion<Area<>> mr(map, har);6210 MapHollowRegion<Area<>> mr(map, har);
@@ -6265,7 +6266,7 @@
6265 (RO) The name of the tribe suggested for this player in this map6266 (RO) The name of the tribe suggested for this player in this map
6266*/6267*/
6267int LuaPlayerSlot::get_tribe_name(lua_State* L) {6268int LuaPlayerSlot::get_tribe_name(lua_State* L) {
6268 lua_pushstring(L, get_egbase(L).get_map()->get_scenario_player_tribe(player_number_));6269 lua_pushstring(L, get_egbase(L).map().get_scenario_player_tribe(player_number_));
6269 return 1;6270 return 1;
6270}6271}
62716272
@@ -6275,7 +6276,7 @@
6275 (RO) The name for this player as suggested in this map6276 (RO) The name for this player as suggested in this map
6276*/6277*/
6277int LuaPlayerSlot::get_name(lua_State* L) {6278int LuaPlayerSlot::get_name(lua_State* L) {
6278 lua_pushstring(L, get_egbase(L).get_map()->get_scenario_player_name(player_number_));6279 lua_pushstring(L, get_egbase(L).map().get_scenario_player_name(player_number_));
6279 return 1;6280 return 1;
6280}6281}
62816282
62826283
=== modified file 'src/website/map_info.cc'
--- src/website/map_info.cc 2017-01-25 18:55:59 +0000
+++ src/website/map_info.cc 2017-08-20 12:33:35 +0000
@@ -75,9 +75,8 @@
75 FileSystem* in_out_filesystem = &FileSystem::create(map_dir);75 FileSystem* in_out_filesystem = &FileSystem::create(map_dir);
76 g_fs->add_file_system(in_out_filesystem);76 g_fs->add_file_system(in_out_filesystem);
7777
78 Map* map = new Map();
79 EditorGameBase egbase(nullptr);78 EditorGameBase egbase(nullptr);
80 egbase.set_map(map);79 auto* map = egbase.mutable_map();
81 std::unique_ptr<Widelands::MapLoader> ml(map->get_correct_loader(map_file));80 std::unique_ptr<Widelands::MapLoader> ml(map->get_correct_loader(map_file));
8281
83 if (!ml) {82 if (!ml) {
8483
=== modified file 'src/wui/attack_box.cc'
--- src/wui/attack_box.cc 2017-02-25 13:27:40 +0000
+++ src/wui/attack_box.cc 2017-08-20 12:33:35 +0000
@@ -40,17 +40,16 @@
40 uint32_t const y)40 uint32_t const y)
41 : UI::Box(parent, x, y, UI::Box::Vertical),41 : UI::Box(parent, x, y, UI::Box::Vertical),
42 player_(player),42 player_(player),
43 map_(&player_->egbase().map()),43 map_(player_->egbase().map()),
44 node_coordinates_(target),44 node_coordinates_(target),
45 lastupdate_(0) {45 lastupdate_(0) {
46 init();46 init();
47}47}
4848
49uint32_t AttackBox::get_max_attackers() {49uint32_t AttackBox::get_max_attackers() {
50 assert(map_);
51 assert(player_);50 assert(player_);
5251
53 if (upcast(Building, building, map_->get_immovable(*node_coordinates_)))52 if (upcast(Building, building, map_.get_immovable(*node_coordinates_)))
54 return player_->find_attack_soldiers(building->base_flag());53 return player_->find_attack_soldiers(building->base_flag());
55 return 0;54 return 0;
56}55}
5756
=== modified file 'src/wui/attack_box.h'
--- src/wui/attack_box.h 2017-05-20 22:42:49 +0000
+++ src/wui/attack_box.h 2017-08-20 12:33:35 +0000
@@ -80,7 +80,7 @@
8080
81private:81private:
82 Widelands::Player* player_;82 Widelands::Player* player_;
83 Widelands::Map* map_;83 const Widelands::Map& map_;
84 Widelands::FCoords* node_coordinates_;84 Widelands::FCoords* node_coordinates_;
8585
86 std::unique_ptr<UI::Slider> soldiers_slider_;86 std::unique_ptr<UI::Slider> soldiers_slider_;
8787
=== modified file 'src/wui/building_statistics_menu.cc'
--- src/wui/building_statistics_menu.cc 2017-08-17 15:34:45 +0000
+++ src/wui/building_statistics_menu.cc 2017-08-20 12:33:35 +0000
@@ -540,7 +540,6 @@
540void BuildingStatisticsMenu::update() {540void BuildingStatisticsMenu::update() {
541 const Player& player = iplayer().player();541 const Player& player = iplayer().player();
542 const TribeDescr& tribe = player.tribe();542 const TribeDescr& tribe = player.tribe();
543 const Map& map = iplayer().game().map();
544 const DescriptionIndex nr_buildings = iplayer().egbase().tribes().nrbuildings();543 const DescriptionIndex nr_buildings = iplayer().egbase().tribes().nrbuildings();
545544
546 owned_label_.set_visible(false);545 owned_label_.set_visible(false);
@@ -581,7 +580,7 @@
581 ++nr_build;580 ++nr_build;
582 else {581 else {
583 ++nr_owned;582 ++nr_owned;
584 BaseImmovable& immovable = *map[stats_vector[l].pos].get_immovable();583 BaseImmovable& immovable = *iplayer().game().map()[stats_vector[l].pos].get_immovable();
585 if (building.type() == MapObjectType::PRODUCTIONSITE ||584 if (building.type() == MapObjectType::PRODUCTIONSITE ||
586 building.type() == MapObjectType::TRAININGSITE) {585 building.type() == MapObjectType::TRAININGSITE) {
587 ProductionSite& productionsite = dynamic_cast<ProductionSite&>(immovable);586 ProductionSite& productionsite = dynamic_cast<ProductionSite&>(immovable);
588587
=== modified file 'src/wui/fieldaction.cc'
--- src/wui/fieldaction.cc 2017-08-17 15:34:45 +0000
+++ src/wui/fieldaction.cc 2017-08-20 12:33:35 +0000
@@ -195,7 +195,7 @@
195 void reset_mouse_and_die();195 void reset_mouse_and_die();
196196
197 Widelands::Player* player_;197 Widelands::Player* player_;
198 Widelands::Map* map_;198 const Widelands::Map& map_;
199 FieldOverlayManager& field_overlay_manager_;199 FieldOverlayManager& field_overlay_manager_;
200200
201 Widelands::FCoords node_;201 Widelands::FCoords node_;
@@ -246,9 +246,9 @@
246 UI::UniqueWindow::Registry* const registry)246 UI::UniqueWindow::Registry* const registry)
247 : UI::UniqueWindow(ib, "field_action", registry, 68, 34, _("Action")),247 : UI::UniqueWindow(ib, "field_action", registry, 68, 34, _("Action")),
248 player_(plr),248 player_(plr),
249 map_(&ib->egbase().map()),249 map_(ib->egbase().map()),
250 field_overlay_manager_(*ib->mutable_field_overlay_manager()),250 field_overlay_manager_(*ib->mutable_field_overlay_manager()),
251 node_(ib->get_sel_pos().node, &(*map_)[ib->get_sel_pos().node]),251 node_(ib->get_sel_pos().node, &map_[ib->get_sel_pos().node]),
252 tabpanel_(this, g_gr->images().get("images/ui_basic/but1.png")),252 tabpanel_(this, g_gr->images().get("images/ui_basic/but1.png")),
253 fastclick_(true),253 fastclick_(true),
254 best_tab_(0),254 best_tab_(0),
@@ -305,7 +305,7 @@
305 const Widelands::PlayerNumber owner = node_.field->get_owned_by();305 const Widelands::PlayerNumber owner = node_.field->get_owned_by();
306306
307 if (!igbase || igbase->can_see(owner)) {307 if (!igbase || igbase->can_see(owner)) {
308 Widelands::BaseImmovable* const imm = map_->get_immovable(node_);308 Widelands::BaseImmovable* const imm = map_.get_immovable(node_);
309 const bool can_act = igbase ? igbase->can_act(owner) : true;309 const bool can_act = igbase ? igbase->can_act(owner) : true;
310310
311 // The box with road-building buttons311 // The box with road-building buttons
@@ -380,7 +380,7 @@
380void FieldActionWindow::add_buttons_attack() {380void FieldActionWindow::add_buttons_attack() {
381 UI::Box& a_box = *new UI::Box(&tabpanel_, 0, 0, UI::Box::Horizontal);381 UI::Box& a_box = *new UI::Box(&tabpanel_, 0, 0, UI::Box::Horizontal);
382382
383 if (upcast(Widelands::Building, building, map_->get_immovable(node_))) {383 if (upcast(Widelands::Building, building, map_.get_immovable(node_))) {
384 if (const Widelands::AttackTarget* attack_target = building->attack_target()) {384 if (const Widelands::AttackTarget* attack_target = building->attack_target()) {
385 if (player_ && player_->is_hostile(building->owner()) &&385 if (player_ && player_->is_hostile(building->owner()) &&
386 attack_target->can_be_attacked()) {386 attack_target->can_be_attacked()) {
387387
=== modified file 'src/wui/game_debug_ui.cc'
--- src/wui/game_debug_ui.cc 2017-06-28 07:17:12 +0000
+++ src/wui/game_debug_ui.cc 2017-08-20 12:33:35 +0000
@@ -198,7 +198,7 @@
198 void open_bob(uint32_t);198 void open_bob(uint32_t);
199199
200private:200private:
201 Widelands::Map& map_;201 const Widelands::Map& map_;
202 Widelands::FCoords const coords_;202 Widelands::FCoords const coords_;
203203
204 UI::MultilineTextarea ui_field_;204 UI::MultilineTextarea ui_field_;
205205
=== modified file 'src/wui/game_main_menu_save_game.cc'
--- src/wui/game_main_menu_save_game.cc 2017-06-24 11:18:12 +0000
+++ src/wui/game_main_menu_save_game.cc 2017-08-20 12:33:35 +0000
@@ -113,7 +113,7 @@
113 {113 {
114 // Try to translate the map name.114 // Try to translate the map name.
115 i18n::Textdomain td("maps");115 i18n::Textdomain td("maps");
116 mapname_.set_text(_(parent.game().get_map()->get_name()));116 mapname_.set_text(_(parent.game().map().get_name()));
117 }117 }
118 uint32_t gametime = parent.game().get_gametime();118 uint32_t gametime = parent.game().get_gametime();
119 gametime_.set_text(gametimestring(gametime));119 gametime_.set_text(gametimestring(gametime));
120120
=== modified file 'src/wui/interactive_base.cc'
--- src/wui/interactive_base.cc 2017-08-18 02:28:27 +0000
+++ src/wui/interactive_base.cc 2017-08-20 12:33:35 +0000
@@ -144,7 +144,7 @@
144}144}
145145
146void InteractiveBase::set_sel_pos(Widelands::NodeAndTriangle<> const center) {146void InteractiveBase::set_sel_pos(Widelands::NodeAndTriangle<> const center) {
147 Map& map = egbase().map();147 const Map& map = egbase().map();
148148
149 // Remove old sel pointer149 // Remove old sel pointer
150 if (sel_.jobid)150 if (sel_.jobid)
@@ -278,7 +278,7 @@
278 default:278 default:
279 throw wexception("Encountered unexpected WorkareaInfo size %i", workareas_nrs);279 throw wexception("Encountered unexpected WorkareaInfo size %i", workareas_nrs);
280 }280 }
281 Widelands::Map& map = egbase_.map();281 const Widelands::Map& map = egbase_.map();
282 FieldOverlayManager::OverlayId overlay_id = field_overlay_manager_->next_overlay_id();282 FieldOverlayManager::OverlayId overlay_id = field_overlay_manager_->next_overlay_id();
283283
284 Widelands::HollowArea<> hollow_area(Widelands::Area<>(coords, 0), 0);284 Widelands::HollowArea<> hollow_area(Widelands::Area<>(coords, 0), 0);
@@ -606,7 +606,7 @@
606bool InteractiveBase::append_build_road(Coords const field) {606bool InteractiveBase::append_build_road(Coords const field) {
607 assert(buildroad_);607 assert(buildroad_);
608608
609 Map& map = egbase().map();609 const Map& map = egbase().map();
610 const Widelands::Player& player = egbase().player(road_build_player_);610 const Widelands::Player& player = egbase().player(road_build_player_);
611611
612 { // find a path to the clicked-on node612 { // find a path to the clicked-on node
@@ -708,7 +708,7 @@
708 assert(buildroad_);708 assert(buildroad_);
709 assert(road_building_preview_.empty());709 assert(road_building_preview_.empty());
710710
711 Map& map = egbase().map();711 const Map& map = egbase().map();
712712
713 // preview of the road713 // preview of the road
714 const CoordPath::StepVector::size_type nr_steps = buildroad_->get_nsteps();714 const CoordPath::StepVector::size_type nr_steps = buildroad_->get_nsteps();
715715
=== modified file 'src/wui/interactive_gamebase.cc'
--- src/wui/interactive_gamebase.cc 2017-08-17 15:34:45 +0000
+++ src/wui/interactive_gamebase.cc 2017-08-20 12:33:35 +0000
@@ -137,7 +137,6 @@
137 * during single/multiplayer/scenario).137 * during single/multiplayer/scenario).
138 */138 */
139void InteractiveGameBase::postload() {139void InteractiveGameBase::postload() {
140 Widelands::Map& map = egbase().map();
141 auto* overlay_manager = mutable_field_overlay_manager();140 auto* overlay_manager = mutable_field_overlay_manager();
142 show_buildhelp(false);141 show_buildhelp(false);
143 on_buildhelp_changed(buildhelp());142 on_buildhelp_changed(buildhelp());
@@ -146,7 +145,7 @@
146 boost::bind(&InteractiveGameBase::calculate_buildcaps, this, _1));145 boost::bind(&InteractiveGameBase::calculate_buildcaps, this, _1));
147146
148 // Recalc whole map for changed owner stuff147 // Recalc whole map for changed owner stuff
149 map.recalc_whole_map(egbase().world());148 egbase().mutable_map()->recalc_whole_map(egbase().world());
150149
151 // Close game-relevant UI windows (but keep main menu open)150 // Close game-relevant UI windows (but keep main menu open)
152 fieldaction_.destroy();151 fieldaction_.destroy();
@@ -224,7 +223,7 @@
224 * If so, do it and return true; otherwise, return false.223 * If so, do it and return true; otherwise, return false.
225 */224 */
226bool InteractiveGameBase::try_show_ship_window() {225bool InteractiveGameBase::try_show_ship_window() {
227 Widelands::Map& map(game().map());226 const Widelands::Map& map= game().map();
228 Widelands::Area<Widelands::FCoords> area(map.get_fcoords(get_sel_pos().node), 1);227 Widelands::Area<Widelands::FCoords> area(map.get_fcoords(get_sel_pos().node), 1);
229228
230 if (!(area.field->nodecaps() & Widelands::MOVECAPS_SWIM))229 if (!(area.field->nodecaps() & Widelands::MOVECAPS_SWIM))
231230
=== modified file 'src/wui/watchwindow.cc'
--- src/wui/watchwindow.cc 2017-08-17 15:34:45 +0000
+++ src/wui/watchwindow.cc 2017-08-20 12:33:35 +0000
@@ -210,11 +210,11 @@
210 }210 }
211211
212 if (upcast(Widelands::Bob, bob, views_[cur_index_].tracking.get(game()))) {212 if (upcast(Widelands::Bob, bob, views_[cur_index_].tracking.get(game()))) {
213 const Widelands::Map& map = game().map();
213 const Vector2f field_position =214 const Vector2f field_position =
214 MapviewPixelFunctions::to_map_pixel(game().map(), bob->get_position());215 MapviewPixelFunctions::to_map_pixel(map, bob->get_position());
215 const Vector2f pos = bob->calc_drawpos(game(), field_position, 1.f);216 const Vector2f pos = bob->calc_drawpos(game(), field_position, 1.f);
216217
217 Widelands::Map& map = game().map();
218 // Drop the tracking if it leaves our vision range218 // Drop the tracking if it leaves our vision range
219 InteractivePlayer* ipl = game().get_ipl();219 InteractivePlayer* ipl = game().get_ipl();
220 if (ipl && 1 >= ipl->player().vision(map.get_index(bob->get_position(), map.get_width()))) {220 if (ipl && 1 >= ipl->player().vision(map.get_index(bob->get_position(), map.get_width()))) {
@@ -253,7 +253,7 @@
253 // Find the nearest bob. Other object types can not move and are253 // Find the nearest bob. Other object types can not move and are
254 // therefore not of interest.254 // therefore not of interest.
255 Vector2f center_map_pixel = mapview_.view_area().rect().center();255 Vector2f center_map_pixel = mapview_.view_area().rect().center();
256 Widelands::Map& map = g.map();256 const Widelands::Map& map = g.map();
257 MapviewPixelFunctions::normalize_pix(map, &center_map_pixel);257 MapviewPixelFunctions::normalize_pix(map, &center_map_pixel);
258 std::vector<Widelands::Bob*> bobs;258 std::vector<Widelands::Bob*> bobs;
259 // Scan progressively larger circles around the given position for259 // Scan progressively larger circles around the given position for

Subscribers

People subscribed via source and target branches

to status/vote changes: