Benedikt Straub has proposed merging lp:~widelands-dev/widelands/no-hardcoded-resources into lp:widelands.
Commit message: Removed hardcoding for resources Requested reviews: Widelands Developers (widelands-dev) Related bugs: Bug #1713706 in widelands: "Remove hard-coding for resource types from the engine" https://bugs.launchpad.net/widelands/+bug/1713706 For more details, see: https://code.launchpad.net/~widelands-dev/widelands/no-hardcoded-resources/+merge/350750 No resources are hardcoded anymore. Geologists can discover any resource set as discoverable in Lua. Messages have been adjusted to handle the timeout in a different way. As a side effect, resource timeout radius and duration can now be set via Lua. -- Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/no-hardcoded-resources into lp:widelands.
=== modified file 'data/world/resources/init.lua' --- data/world/resources/init.lua 2017-08-30 17:07:20 +0000 +++ data/world/resources/init.lua 2018-07-24 19:34:27 +0000 @@ -50,6 +50,18 @@ -- -- detectable = true, -- +-- **timeout_millis** +-- *Mandatory*. Defines the time for which geologists messages for this +-- resource will be muted within this area after a find, e.g.:: +-- +-- timeout_millis = 30000, +-- +-- **timeout_radius** +-- *Mandatory*. Defines the radius within which geologists messages for this +-- resource will be muted after a find, e.g.:: +-- +-- timeout_radius = 8, +-- -- **representative_image** -- *Mandatory*. Path to an image file that will represent the resource in menus -- etc., e.g.:: @@ -72,6 +84,8 @@ descname = _ "Coal", max_amount = 20, detectable = true, + timeout_millis = 30000, + timeout_radius = 8, representative_image = pics_dir .. "coal4.png", editor_pictures = { [5] = pics_dir .. "coal1.png", @@ -86,6 +100,8 @@ descname = _ "Gold", max_amount = 20, detectable = true, + timeout_millis = 30000, + timeout_radius = 8, representative_image = pics_dir .. "gold4.png", editor_pictures = { [5] = pics_dir .. "gold1.png", @@ -100,6 +116,8 @@ descname = _ "Iron", max_amount = 20, detectable = true, + timeout_millis = 30000, + timeout_radius = 8, representative_image = pics_dir .. "iron4.png", editor_pictures = { [5] = pics_dir .. "iron1.png", @@ -114,6 +132,8 @@ descname = _ "Stones", max_amount = 20, detectable = true, + timeout_millis = 30000, + timeout_radius = 8, representative_image = pics_dir .. "stones4.png", editor_pictures = { [5] = pics_dir .. "stones1.png", @@ -128,6 +148,8 @@ descname = _ "Water", max_amount = 50, detectable = true, + timeout_millis = 30000, + timeout_radius = 8, representative_image = pics_dir .. "water4.png", editor_pictures = { [10] = pics_dir .."water1.png", @@ -142,6 +164,8 @@ descname = _ "Fish", max_amount = 20, detectable = false, + timeout_millis = 0, + timeout_radius = 0, representative_image = pics_dir .. "fish.png", editor_pictures = { [5] = pics_dir .. "fish1.png", === modified file 'src/logic/map_objects/tribes/worker.cc' --- src/logic/map_objects/tribes/worker.cc 2018-07-13 10:35:16 +0000 +++ src/logic/map_objects/tribes/worker.cc 2018-07-24 19:34:27 +0000 @@ -975,16 +975,6 @@ .str(); Message::Type message_type = Message::Type::kGeologists; - if (rdescr->name() == "coal") - message_type = Message::Type::kGeologistsCoal; - else if (rdescr->name() == "gold") - message_type = Message::Type::kGeologistsGold; - else if (rdescr->name() == "stones") - message_type = Message::Type::kGeologistsStones; - else if (rdescr->name() == "iron") - message_type = Message::Type::kGeologistsIron; - else if (rdescr->name() == "water") - message_type = Message::Type::kGeologistsWater; // We should add a message to the player's message queue - but only, // if there is not already a similar one in list. @@ -992,8 +982,8 @@ game, std::unique_ptr<Message>( new Message(message_type, game.get_gametime(), rdescr->descname(), ri.descr().representative_image_filename(), rdescr->descname(), - message, position, serial_)), - 300000, 8); + message, position, serial_, rdescr->name().c_str())), + rdescr->timeout_millis(), rdescr->timeout_radius()); } } === modified file 'src/logic/map_objects/world/resource_description.cc' --- src/logic/map_objects/world/resource_description.cc 2018-04-07 16:59:00 +0000 +++ src/logic/map_objects/world/resource_description.cc 2018-07-24 19:34:27 +0000 @@ -31,6 +31,8 @@ : name_(table.get_string("name")), descname_(table.get_string("descname")), detectable_(table.get_bool("detectable")), + timeout_millis_(table.get_int("timeout_millis")), + timeout_radius_(table.get_int("timeout_radius")), max_amount_(table.get_int("max_amount")), representative_image_(table.get_string("representative_image")) { @@ -76,6 +78,14 @@ return detectable_; } +uint32_t ResourceDescription::timeout_millis() const { + return timeout_millis_; +} + +uint32_t ResourceDescription::timeout_radius() const { + return timeout_radius_; +} + ResourceAmount ResourceDescription::max_amount() const { return max_amount_; } === modified file 'src/logic/map_objects/world/resource_description.h' --- src/logic/map_objects/world/resource_description.h 2018-04-07 16:59:00 +0000 +++ src/logic/map_objects/world/resource_description.h 2018-07-24 19:34:27 +0000 @@ -48,6 +48,12 @@ /// Returns if this resource is detectable by a geologist. bool detectable() const; + /// Returns the time for which nearby geologist messages for this resource are muted + uint32_t timeout_millis() const; + + /// Returns the radius within which geologist messages for this resource are tenporarily muted + uint32_t timeout_radius() const; + /// Returns the maximum amount that can be in a field for this resource. ResourceAmount max_amount() const; @@ -64,6 +70,8 @@ const std::string name_; const std::string descname_; const bool detectable_; + const uint32_t timeout_millis_; + const uint32_t timeout_radius_; const ResourceAmount max_amount_; const std::string representative_image_; std::vector<EditorPicture> editor_pictures_; === modified file 'src/logic/message.h' --- src/logic/message.h 2018-04-07 16:59:00 +0000 +++ src/logic/message.h 2018-07-24 19:34:27 +0000 @@ -36,11 +36,6 @@ kAllMessages, kGameLogic, kGeologists, - kGeologistsCoal, - kGeologistsGold, - kGeologistsStones, - kGeologistsIron, - kGeologistsWater, kScenario, kSeafaring, kEconomy, // economy @@ -63,6 +58,8 @@ * \param ser A MapObject serial. If non null, the message will be deleted once * the object is removed from the game. Defaults to 0 * \param s The message status. Defaults to Status::New + * \param detail The extended message type, used for comparisons in + * Player::add_message_with_timeout(). Defaults to nullptr */ Message(Message::Type msgtype, uint32_t sent_time, @@ -72,8 +69,10 @@ const std::string& init_body, const Widelands::Coords& c = Coords::null(), Widelands::Serial ser = 0, + const char* detail = nullptr, Status s = Status::kNew) : type_(msgtype), + type_detail_(detail), title_(init_title), icon_filename_(init_icon_filename), icon_(g_gr->images().get(init_icon_filename)), @@ -88,6 +87,9 @@ Message::Type type() const { return type_; } + const char* type_detail() const { + return type_detail_; + } uint32_t sent() const { return sent_; } @@ -129,15 +131,13 @@ } else if (type_ >= Widelands::Message::Type::kEconomy && type_ <= Widelands::Message::Type::kEconomySiteOccupied) { return Widelands::Message::Type::kEconomy; - } else if (type_ >= Widelands::Message::Type::kGeologists && - type_ <= Widelands::Message::Type::kGeologistsWater) { - return Widelands::Message::Type::kGeologists; } return type_; } private: Message::Type type_; + const char* type_detail_; const std::string title_; const std::string icon_filename_; const Image* icon_; // Pointer to icon into picture stack === modified file 'src/logic/player.cc' --- src/logic/player.cc 2018-07-20 07:49:32 +0000 +++ src/logic/player.cc 2018-07-24 19:34:27 +0000 @@ -357,6 +357,7 @@ Coords const position = message->position(); for (const auto& tmp_message : messages()) { if (tmp_message.second->type() == message->type() && + tmp_message.second->type_detail() == message->type_detail() && gametime < tmp_message.second->sent() + timeout && map.calc_distance(tmp_message.second->position(), position) <= radius) { return MessageId::null(); === modified file 'src/map_io/map_players_messages_packet.cc' --- src/map_io/map_players_messages_packet.cc 2018-04-07 16:59:00 +0000 +++ src/map_io/map_players_messages_packet.cc 2018-07-24 19:34:27 +0000 @@ -123,14 +123,14 @@ messages->add_message(std::unique_ptr<Message>(new Message( static_cast<Message::Type>(s->get_natural("type")), sent, name, "images/wui/fieldaction/menu_build_flag.png", name, s->get_safe_string("body"), - get_coords("position", extent, Coords::null(), s), serial, status))); + get_coords("position", extent, Coords::null(), s), serial, nullptr, status))); } else { messages->add_message(std::unique_ptr<Message>(new Message( static_cast<Message::Type>(s->get_natural("type")), sent, s->get_name(), s->get_safe_string("icon"), s->get_safe_string("heading"), s->get_safe_string("body"), get_coords("position", extent, Coords::null(), s), - serial, status))); + serial, s->get_string("detail"), status))); } previous_message_sent = sent; } catch (const WException& e) { @@ -183,6 +183,9 @@ uint32_t fileindex = mos.get_object_file_index_or_zero(mo); s.set_int("serial", fileindex); } + if (message.type_detail()) { + s.set_string("detail", message.type_detail()); + } } fs.ensure_directory_exists( (boost::format(kPlayerDirnameTemplate) % static_cast<unsigned int>(p)).str()); === modified file 'src/scripting/lua_game.cc' --- src/scripting/lua_game.cc 2018-07-12 04:41:20 +0000 +++ src/scripting/lua_game.cc 2018-07-24 19:34:27 +0000 @@ -377,7 +377,7 @@ MessageId const message = plr.add_message( game, std::unique_ptr<Message>(new Message(Message::Type::kScenario, game.get_gametime(), - title, icon, heading, body, c, 0, st)), + title, icon, heading, body, c, 0, nullptr, st)), popup); return to_lua<LuaMessage>(L, new LuaMessage(player_number(), message)); === modified file 'src/wui/game_message_menu.cc' --- src/wui/game_message_menu.cc 2018-05-14 08:24:46 +0000 +++ src/wui/game_message_menu.cc 2018-07-24 19:34:27 +0000 @@ -498,11 +498,6 @@ case Widelands::Message::Type::kNoMessages: case Widelands::Message::Type::kAllMessages: case Widelands::Message::Type::kGameLogic: - case Widelands::Message::Type::kGeologistsCoal: - case Widelands::Message::Type::kGeologistsGold: - case Widelands::Message::Type::kGeologistsStones: - case Widelands::Message::Type::kGeologistsIron: - case Widelands::Message::Type::kGeologistsWater: case Widelands::Message::Type::kEconomySiteOccupied: case Widelands::Message::Type::kWarfareSiteDefeated: case Widelands::Message::Type::kWarfareSiteLost: @@ -592,11 +587,6 @@ return "images/ui_basic/menu_help.png"; case Widelands::Message::Type::kNoMessages: case Widelands::Message::Type::kAllMessages: - case Widelands::Message::Type::kGeologistsCoal: - case Widelands::Message::Type::kGeologistsGold: - case Widelands::Message::Type::kGeologistsStones: - case Widelands::Message::Type::kGeologistsIron: - case Widelands::Message::Type::kGeologistsWater: case Widelands::Message::Type::kEconomySiteOccupied: case Widelands::Message::Type::kWarfareSiteDefeated: case Widelands::Message::Type::kWarfareSiteLost:
_______________________________________________ Mailing list: https://launchpad.net/~widelands-dev Post to : widelands-dev@lists.launchpad.net Unsubscribe : https://launchpad.net/~widelands-dev More help : https://help.launchpad.net/ListHelp