1 /*************************************************************************** 2 * Mechanized Assault and Exploration Reloaded Projectfile * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 18 ***************************************************************************/ 19 20 #ifndef game_logic_casualtiestrackerH 21 #define game_logic_casualtiestrackerH 22 23 #include "main.h" 24 #include "utility/signal/signal.h" 25 #include <vector> 26 27 class cNetMessage; 28 namespace tinyxml2 29 { 30 class XMLElement; 31 } 32 33 //------------------------------------------------------------------------------- 34 class cCasualtiesTracker 35 { 36 public: cCasualtiesTracker()37 cCasualtiesTracker() {} 38 39 void initFromXML (tinyxml2::XMLElement* casualtiesNode); 40 void storeToXML (tinyxml2::XMLElement* casualtiesNode) const; 41 42 void logCasualty (sID unitType, int playerNr); 43 int getCasualtiesOfUnitType (sID unitType, int playerNr) const; 44 45 void updateCasualtiesFromNetMessage (cNetMessage* message); 46 std::vector<std::unique_ptr<cNetMessage>> prepareNetMessagesForClient (int msgType); 47 48 std::vector<sID> getUnitTypesWithLosses() const; 49 50 mutable cSignal<void (const sID&, int)> casualtyChanged; 51 mutable cSignal<void ()> casualtiesChanged; 52 //------------------------------------------------------------------------------- 53 private: 54 struct Casualty 55 { 56 sID unitID; 57 int numberOfLosses; 58 }; 59 struct CasualtiesOfPlayer 60 { 61 std::vector<Casualty> casualties; 62 int playerNr; 63 }; 64 mutable std::vector<CasualtiesOfPlayer> casualtiesPerPlayer; 65 66 std::vector<Casualty>& getCasualtiesOfPlayer (int playerNr) const; 67 void setCasualty (sID unitType, int numberOfLosses, int playerNr); 68 69 void debugPrint(); 70 }; 71 72 73 #endif // game_logic_casualtiestrackerH 74