Merge lp:~widelands-dev/widelands/bug-1736086-map-without-players into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 8715
Proposed branch: lp:~widelands-dev/widelands/bug-1736086-map-without-players
Merge into: lp:widelands
Diff against target: 118 lines (+12/-16)
7 files modified
src/editor/map_generator.cc (+2/-2)
src/editor/ui_menus/player_menu.cc (+4/-0)
src/logic/map.cc (+2/-10)
src/map_io/coords_profile.cc (+1/-1)
src/map_io/map_player_position_packet.cc (+1/-1)
src/sound/note_sound.h (+1/-1)
src/ui_fsmenu/mapselect.cc (+1/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1736086-map-without-players
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+345397@code.launchpad.net

Commit message

New maps now have 0 players

- Initialize new maps with 0 players. Consistent use of Coords::null()
- Disable selection of maps with 0 players
- Automatically add first player to editor player menu for convenience

Description of the change

Maps with 0 players will still show up in the game load screens, but be disabled. I decided to show them to avoid "Where the F is my new map" moments.

If the starting position isn't set, the game load screen won't notice that, but the error is caught and displayed to the user on game start. I chose to keep it that way for efficiency.

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

Continuous integration builds have changed state:

Travis build 3494. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/377593633.
Appveyor build 3299. State: failed. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1736086_map_without_players-3299.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Mhh, this will imply that it is impossible to set the startin g postion at 0,0.

I will try this to "verify" the fix.

Code LGTM, compiling this now and do some testing.

Revision history for this message
Klaus Halfmann (klaus-halfmann) wrote :

Works as expected.

@bunnybot merge

Revision history for this message
GunChleoc (gunchleoc) wrote :

Coords::null() is actually (-1, -1). Maybe it needs a better name.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/map_generator.cc'
2--- src/editor/map_generator.cc 2018-04-07 16:59:00 +0000
3+++ src/editor/map_generator.cc 2018-05-11 05:37:05 +0000
4@@ -663,7 +663,7 @@
5 const std::string ai = map_.get_scenario_player_ai(1);
6 map_.set_nrplayers(map_info_.numPlayers);
7 FindNodeSize functor(FindNodeSize::sizeBig);
8- Coords playerstart(-1, -1);
9+ Coords playerstart(Coords::null());
10
11 // Build a basic structure how player start positions are placed
12 uint8_t line[3];
13@@ -783,7 +783,7 @@
14
15 log("WARNING: Player %u has no starting position - illegal coordinates (%d, %d).\n", n,
16 coords2.x, coords2.y);
17- coords2 = Coords(-1, -1);
18+ coords2 = Coords::null();
19 }
20
21 // Finally set the found starting position
22
23=== modified file 'src/editor/ui_menus/player_menu.cc'
24--- src/editor/ui_menus/player_menu.cc 2018-04-07 16:59:00 +0000
25+++ src/editor/ui_menus/player_menu.cc 2018-05-11 05:37:05 +0000
26@@ -88,6 +88,10 @@
27 plr_set_pos_buts_[i] = nullptr;
28 plr_set_tribes_buts_[i] = nullptr;
29 }
30+
31+ if (parent.egbase().map().get_nrplayers() < 1) {
32+ clicked_add_player();
33+ }
34 update();
35
36 set_thinks(true);
37
38=== modified file 'src/logic/map.cc'
39--- src/logic/map.cc 2018-04-11 18:42:55 +0000
40+++ src/logic/map.cc 2018-05-11 05:37:05 +0000
41@@ -305,15 +305,7 @@
42 set_name(name);
43 set_author(author);
44 set_description(description);
45- set_nrplayers(1);
46- // Set first tribe found as the "basic" tribe
47- // <undefined> (as set before) is useless and will lead to a
48- // crash -> Widelands will search for tribe "<undefined>"
49- set_scenario_player_tribe(1, Widelands::get_all_tribenames()[0]);
50- set_scenario_player_name(1, (boost::format(_("Player %u")) % 1).str());
51- set_scenario_player_ai(1, "");
52- set_scenario_player_closeable(1, false);
53-
54+ set_nrplayers(0);
55 {
56 Field::Terrains default_terrains;
57 default_terrains.d = default_terrain;
58@@ -494,7 +486,7 @@
59 return;
60 }
61
62- starting_pos_.resize(nrplayers, Coords(-1, -1));
63+ starting_pos_.resize(nrplayers, Coords::null());
64 scenario_tribes_.resize(nrplayers);
65 scenario_ais_.resize(nrplayers);
66 scenario_closeables_.resize(nrplayers);
67
68=== modified file 'src/map_io/coords_profile.cc'
69--- src/map_io/coords_profile.cc 2018-04-07 16:59:00 +0000
70+++ src/map_io/coords_profile.cc 2018-05-11 05:37:05 +0000
71@@ -37,7 +37,7 @@
72 const long int x = strtol(endp, &endp, 0);
73 const long int y = strtol(endp, &endp, 0);
74
75- // Check of consistence should NOT be at x, y < 0 as (-1, -1) is used for
76+ // Check of consistence should NOT be at x, y < 0 as (-1, -1) == Coords::null() is used for
77 // not set starting positions in the editor. So check whether x, y < -1 so
78 // the editor can load incomplete maps. For games the starting positions
79 // will be checked in player initalisation anyway.
80
81=== modified file 'src/map_io/map_player_position_packet.cc'
82--- src/map_io/map_player_position_packet.cc 2018-04-07 16:59:00 +0000
83+++ src/map_io/map_player_position_packet.cc 2018-05-11 05:37:05 +0000
84@@ -41,7 +41,7 @@
85 if (packet_version == kCurrentPacketVersion) {
86 // Read all the positions
87 // This could bring trouble if one player position/ is not set (this
88- // is possible in the editor), is also -1, -1.
89+ // is possible in the editor), is also -1, -1 == Coords::null().
90 Map* map = egbase.mutable_map();
91 Extent const extent = map->extent();
92 PlayerNumber const nr_players = map->get_nrplayers();
93
94=== modified file 'src/sound/note_sound.h'
95--- src/sound/note_sound.h 2018-04-07 16:59:00 +0000
96+++ src/sound/note_sound.h 2018-05-11 05:37:05 +0000
97@@ -41,7 +41,7 @@
98 }
99 NoteSound(const std::string& init_fx, uint32_t init_stereo_position, uint8_t init_priority)
100 : fx(init_fx),
101- coords(Widelands::Coords(-1, -1)),
102+ coords(Widelands::Coords::null()),
103 priority(init_priority),
104 stereo_position(init_stereo_position) {
105 }
106
107=== modified file 'src/ui_fsmenu/mapselect.cc'
108--- src/ui_fsmenu/mapselect.cc 2018-04-07 16:59:00 +0000
109+++ src/ui_fsmenu/mapselect.cc 2018-05-11 05:37:05 +0000
110@@ -184,7 +184,7 @@
111
112 bool FullscreenMenuMapSelect::set_has_selection() {
113 bool has_selection = table_.has_selection();
114- ok_.set_enabled(has_selection);
115+ ok_.set_enabled(has_selection && maps_data_.at(table_.get_selected()).nrplayers > 0);
116
117 if (!has_selection) {
118 map_details_.clear();

Subscribers

People subscribed via source and target branches

to status/vote changes: