diff --git a/src/supertux/player_status.cpp b/src/supertux/player_status.cpp index de21effb5cf..f42e17f05ef 100644 --- a/src/supertux/player_status.cpp +++ b/src/supertux/player_status.cpp @@ -213,30 +213,7 @@ PlayerStatus::read(const ReaderMapping& mapping) } auto map = iter.as_mapping(); - - std::string bonusname; - if (map.get("bonus", bonusname)) { - if (bonusname == "none") { - bonus[id] = NO_BONUS; - } else if (bonusname == "growup") { - bonus[id] = GROWUP_BONUS; - } else if (bonusname == "fireflower") { - bonus[id] = FIRE_BONUS; - } else if (bonusname == "iceflower") { - bonus[id] = ICE_BONUS; - } else if (bonusname == "airflower") { - bonus[id] = AIR_BONUS; - } else if (bonusname == "earthflower") { - bonus[id] = EARTH_BONUS; - } else { - log_warning << "Unknown bonus '" << bonusname << "' in savefile for player " << (id + 1) << std::endl; - bonus[id] = NO_BONUS; - } - } - map.get("fireflowers", max_fire_bullets[id]); - map.get("iceflowers", max_ice_bullets[id]); - map.get("airflowers", max_air_time[id]); - map.get("earthflowers", max_earth_time[id]); + parse_bonus_mapping(map, id); } } catch (const std::exception& e) @@ -245,34 +222,40 @@ PlayerStatus::read(const ReaderMapping& mapping) } } + parse_bonus_mapping(mapping, 0); + + mapping.get("coins", coins); + + mapping.get("worldmap-sprite", worldmap_sprite); + mapping.get("last-worldmap", last_worldmap); +} + +void +PlayerStatus::parse_bonus_mapping(const ReaderMapping& map, int id) +{ std::string bonusname; - if (mapping.get("bonus", bonusname)) { + if (map.get("bonus", bonusname)) { if (bonusname == "none") { - bonus[0] = NO_BONUS; + bonus[id] = NO_BONUS; } else if (bonusname == "growup") { - bonus[0] = GROWUP_BONUS; + bonus[id] = GROWUP_BONUS; } else if (bonusname == "fireflower") { - bonus[0] = FIRE_BONUS; + bonus[id] = FIRE_BONUS; } else if (bonusname == "iceflower") { - bonus[0] = ICE_BONUS; + bonus[id] = ICE_BONUS; } else if (bonusname == "airflower") { - bonus[0] = AIR_BONUS; + bonus[id] = AIR_BONUS; } else if (bonusname == "earthflower") { - bonus[0] = EARTH_BONUS; + bonus[id] = EARTH_BONUS; } else { - log_warning << "Unknown bonus '" << bonusname << "' in savefile" << std::endl; - bonus[0] = NO_BONUS; + log_warning << "Unknown bonus '" << bonusname << "' in savefile for player " << (id + 1) << std::endl; + bonus[id] = NO_BONUS; } } - mapping.get("fireflowers", max_fire_bullets[0]); - mapping.get("iceflowers", max_ice_bullets[0]); - mapping.get("airflowers", max_air_time[0]); - mapping.get("earthflowers", max_earth_time[0]); - - mapping.get("coins", coins); - - mapping.get("worldmap-sprite", worldmap_sprite); - mapping.get("last-worldmap", last_worldmap); + map.get("fireflowers", max_fire_bullets[id]); + map.get("iceflowers", max_ice_bullets[id]); + map.get("airflowers", max_air_time[id]); + map.get("earthflowers", max_earth_time[id]); } std::string diff --git a/src/supertux/player_status.hpp b/src/supertux/player_status.hpp index b705e3c2a5d..4be8f1bd832 100644 --- a/src/supertux/player_status.hpp +++ b/src/supertux/player_status.hpp @@ -56,6 +56,9 @@ class PlayerStatus final void add_player(); void remove_player(int player_id); +private: + void parse_bonus_mapping(const ReaderMapping& map, int id); + public: int m_num_players;