widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #07580
[Merge] lp:~widelands-dev/widelands/mapgen-ui-updates into lp:widelands
Miroslav Remák has proposed merging lp:~widelands-dev/widelands/mapgen-ui-updates into lp:widelands.
Commit message:
- Restore map generation ID validity checking
- Fix map generation UI not updating properly when user changes map ID
- Fix map generation UI not updating properly when user changes player count
- Fix documentation in map_generator.cc
Requested reviews:
Widelands Developers (widelands-dev)
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/mapgen-ui-updates/+merge/294520
For some reason the code that checks whether the world in the map ID string is valid got lost during one_world changes and the set_from_id_string function now always returns false.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/mapgen-ui-updates into lp:widelands.
=== modified file 'src/editor/map_generator.cc'
--- src/editor/map_generator.cc 2016-04-11 06:45:29 +0000
+++ src/editor/map_generator.cc 2016-05-12 14:31:50 +0000
@@ -193,8 +193,8 @@
/// \param elevation Random value.
/// \param map_gen_info_ Map generator information used to translate random values
/// to height information (world specific info).
-/// \param c position within map
-/// \param mapInfo Information about the random map currently begin created
+/// \param c Position within map.
+/// \param mapInfo Information about the random map currently being created
/// (map specific info).
///
/// \returns A map height value corresponding to elevation.
@@ -240,31 +240,28 @@
}
/**
-===============
-Generate a "continuous" array of "reasonable" random values.
-The array generated is in fact organized in a two-dimensional
-way. "Reasonable" means that the values are not purely random.
-Neighboring values (in a two-dimensional way) are fitting
-together so that such an array can be used to directly generate
-height information for mountains, wasteland, resources etc.
-"Continuous" means that also value of the left border fit to
-the right border values and values of the top border fit to the
-bottom border values. This means we have some kind of "endlessly"
-repeating set of random values.
-What is more, the different heights are weighed so that the
-random distribution of all random values in the array is linear.
-The minimum valu will be 0, the maximum value will be kMaxElevation,
-the average will be kAverageElevation.
-
-w, h: are width and height of the two-dimensional array
- produced. Thus, the array has w * h entries. To access a certain
- "coordinate" in the array, use array[x + w * y] to retrieve the entry.
-
-rng: is the random number generator to be used.
- This will mostly be the current rng of the random map currently being
- created.
-===============
-*/
+ * Generate a "continuous" array of "reasonable" random values.
+ * The array generated is in fact organized in a two-dimensional
+ * way. "Reasonable" means that the values are not purely random.
+ * Neighboring values (in a two-dimensional way) are fitting
+ * together so that such an array can be used to directly generate
+ * height information for mountains, wasteland, resources etc.
+ * "Continuous" means that also value of the left border fit to
+ * the right border values and values of the top border fit to the
+ * bottom border values. This means we have some kind of "endlessly"
+ * repeating set of random values.
+ * What is more, the different heights are weighed so that the
+ * random distribution of all random values in the array is linear.
+ * The minimum valu will be 0, the maximum value will be kMaxElevation,
+ * the average will be kAverageElevation.
+ *
+ * \param w, h Width and height of the two-dimensional array
+ * produced. Thus, the array has w * h entries. To access a certain
+ * "coordinate" in the array, use array[x + w * y] to retrieve the entry.
+ * \param rng The random number generator to be used.
+ * This will mostly be the current rng of the random map currently being
+ * created.
+ */
uint32_t * MapGenerator::generate_random_value_map
(uint32_t const w, uint32_t const h, RNG & rng)
{
@@ -416,29 +413,27 @@
/**
-===============
-Figures out terrain info for a field in a random map.
-
-map_gen_info_: Map generator information used to translate
- Random values to height information (world-
- specific info)
-x, y: first coordinate of the current triangle
-x1, y1: second coordinate of the current triangle
-x2, y2: third coordinate of the current triangle
-random2: Random array for generating different
- terrain types on land
-random3: Random array for generating different
- terrain types on land
-random4: Random array for wasteland generation
-h1, h2, h3: Map height information for the three triangle coords
-mapInfo: Information about the random map currently
- begin created (map specific info)
-rng: is the random number generator to be used.
- This will mostly be the current rng of the random map
- currently being created.
-terrType: Returns the terrain-Type fpor this triangle
-===============
-*/
+ * Figures out terrain info for a field in a random map.
+ *
+ * \param map_gen_info_ Map generator information used to translate
+ * random values to height information (world-
+ * specific info).
+ * \param x, y First coordinate of the current triangle.
+ * \param x1, y1 Second coordinate of the current triangle.
+ * \param x2, y2 Third coordinate of the current triangle.
+ * \param random2 Random array for generating different
+ * terrain types on land.
+ * \param random3 Random array for generating different
+ * terrain types on land.
+ * \param random4 Random array for wasteland generation.
+ * \param h1, h2, h3 Map height information for the three triangle coords.
+ * \param mapInfo Information about the random map currently
+ * being created (map specific info).
+ * \param rng The random number generator to be used.
+ * This will mostly be the current rng of the random map
+ * currently being created.
+ * \param terrType Returns the terrain type for this triangle.
+ */
DescriptionIndex MapGenerator::figure_out_terrain
(uint32_t * const random2,
uint32_t * const random3,
@@ -871,17 +866,15 @@
}
/**
-===============
-Converts a character out of a mapId-String into an integer value.
-Valid characters are 'a'-'z' (or 'A'-'Z') and '2'-'9'. 'i' and 'o'
-(or 'I' and 'O') are not valid.
-The character is treated case-insensitive.
-
-num: Number to convert
-Return value: The resulting number (0-31) or -1 if the character
- was no legal character.
-===============
-*/
+ * Converts a character out of a mapId-String into an integer value.
+ * Valid characters are 'a'-'z' (or 'A'-'Z') and '2'-'9'. 'i' and 'o'
+ * (or 'I' and 'O') are not valid.
+ * The character is treated case-insensitive.
+ *
+ * \param ch Character to convert.
+ * \return The resulting number (0-31) or -1 if the character
+ * was no legal character.
+ */
int UniqueRandomMapInfo::map_id_char_to_number(char ch)
{
@@ -921,14 +914,12 @@
}
/**
-===============
-Converts an integer number (0-31) to a characted usable in
-a map id string.
-
-num: Number to convert
-Return value: The converted value as a character
-===============
-*/
+ * Converts an integer number (0-31) to a characted usable in
+ * a map id string.
+ *
+ * \param num Number to convert.
+ * \return The converted value as a character.
+ */
char UniqueRandomMapInfo::map_id_number_to_char(int32_t const num)
{
if (num == 22)
@@ -953,17 +944,18 @@
}
/**
-===============
-Fills a UniqueRandomMapInfo structure from a given Map-id-string.
-
-mapIdString: Map-Id-String
-mapInfo_out: UniqueRandomMapInfo-Structure to be filled
-Return value: true if the map-id-string was valid, false otherwise
-===============
-*/
+ * Fills a UniqueRandomMapInfo structure from a given map ID string.
+ *
+ * \param mapIdString Map ID string.
+ * \param mapInfo_out UniqueRandomMapInfo structure to be filled.
+ * \param world_names List of valid world names to check against.
+ *
+ * \return True if the map ID string was valid, false otherwise.
+ */
bool UniqueRandomMapInfo::set_from_id_string
- (UniqueRandomMapInfo & mapInfo_out, const std::string & mapIdString)
+ (UniqueRandomMapInfo & mapInfo_out, const std::string & mapIdString,
+ const std::vector<std::string> & world_names)
{
// check string
@@ -1045,23 +1037,35 @@
// Island mode
mapInfo_out.islandMode = (nums[13] == 1) ? true : false;
+ // World name hash
+ uint16_t world_name_hash =
+ (nums[14]) |
+ (nums[15] << 5) |
+ (nums[16] << 10) |
+ (nums[17] << 15);
+
+ for (const std::string & world_name : world_names) {
+ if (generate_world_name_hash(world_name) == world_name_hash) {
+ mapInfo_out.world_name = world_name;
+ return true;
+ }
+ }
+
return false; // No valid world name found
}
/**
-===============
-Generates an ID-String for map generation.
-The ID-String is an encoded version of the
-information in a UniqueMapInfo structure.
-Thus, the ID_String will contain all info
-necessary to re-create a given random map.
+ * Generates an ID-String for map generation.
+ * The ID-String is an encoded version of the
+ * information in a UniqueMapInfo structure.
+ * Thus, the ID_String will contain all info
+ * necessary to re-create a given random map.
+ *
+ * \param mapIdsString_out Output buffer for the resulting map ID string.
+ * \param mapInfo Information about the random map currently being
+ * created (map specific info).
+ */
-mapIdsString_out: Output buffer for the resulting
- Map-ID-String
-mapInfo: Information about the random map currently
- begin created (map specific info)
-===============
-*/
void UniqueRandomMapInfo::generate_id_string
(std::string & mapIdsString_out, const UniqueRandomMapInfo & mapInfo)
{
=== modified file 'src/editor/map_generator.h'
--- src/editor/map_generator.h 2015-11-28 22:29:26 +0000
+++ src/editor/map_generator.h 2016-05-12 14:31:50 +0000
@@ -64,7 +64,8 @@
// other stuff
static bool set_from_id_string
- (UniqueRandomMapInfo & mapInfo_out, const std::string & mapIdString);
+ (UniqueRandomMapInfo & mapInfo_out, const std::string & mapIdString,
+ const std::vector<std::string> & world_names);
static void generate_id_string
(std::string & mapIdsString_out, const UniqueRandomMapInfo & mapInfo);
=== modified file 'src/editor/ui_menus/main_menu_random_map.cc'
--- src/editor/ui_menus/main_menu_random_map.cc 2016-05-11 19:04:04 +0000
+++ src/editor/ui_menus/main_menu_random_map.cc 2016-05-12 14:31:50 +0000
@@ -181,6 +181,10 @@
box_.add_space(margin_);
box_height += margin_;
+ players_.changed.connect(boost::bind(&MainMenuNewRandomMap::button_clicked,
+ this,
+ ButtonId::kPlayers));
+
// ---------- Worlds ----------
world_box_.add(&world_label_, UI::Align::kLeft);
@@ -328,6 +332,7 @@
*/
void MainMenuNewRandomMap::button_clicked(MainMenuNewRandomMap::ButtonId n) {
switch (n) {
+ case ButtonId::kPlayers: // intended fall-through
case ButtonId::kMapSize:
// Restrict maximum players according to map size, but allow at least 2 players.
max_players_ =
@@ -522,7 +527,13 @@
std::string str = map_id_edit_.text();
- if (!UniqueRandomMapInfo::set_from_id_string(map_info, str))
+ std::vector<std::string> world_names;
+ world_names.reserve(world_descriptions_.size());
+ for (const auto & descr : world_descriptions_) {
+ world_names.push_back(descr.name);
+ }
+
+ if (!UniqueRandomMapInfo::set_from_id_string(map_info, str, world_names))
ok_button_.set_enabled(false);
else {
std::stringstream sstrm;
@@ -532,12 +543,21 @@
width_.set_value(find_dimension_index(map_info.w));
height_.set_value(find_dimension_index(map_info.h));
+ players_.set_interval(1, map_info.numPlayers); // hack to make sure we can set the value
+ players_.set_value(map_info.numPlayers);
+
landval_ = map_info.landRatio * 100.0 + 0.49;
waterval_ = map_info.waterRatio * 100.0 + 0.49;
+ wastelandval_ = map_info.wastelandRatio * 100.0 + 0.49;
resource_amount_ = map_info.resource_amount;
-
- resources_.set_title(resource_amounts_[resource_amount_].c_str());
+ resources_.set_title(resource_amounts_[resource_amount_]);
+
+ current_world_ = std::find(world_names.cbegin(), world_names.cend(),
+ map_info.world_name) - world_names.cbegin();
+ world_.set_title(world_descriptions_[current_world_].descname);
+
+ island_mode_.set_state(map_info.islandMode);
// Update other values in UI as well
button_clicked(ButtonId::kNone);
=== modified file 'src/editor/ui_menus/main_menu_random_map.h'
--- src/editor/ui_menus/main_menu_random_map.h 2016-05-11 13:30:23 +0000
+++ src/editor/ui_menus/main_menu_random_map.h 2016-05-12 14:31:50 +0000
@@ -55,7 +55,8 @@
kWasteland,
kResources,
kWorld,
- kIslandMode
+ kIslandMode,
+ kPlayers
};
private:
Follow ups