1 // Copyright (C) 2004 John Farrell 2 // Copyright (C) 2004, 2005 Ulf Lorenz 3 // Copyright (C) 2004, 2006 Andrea Paternesi 4 // Copyright (C) 2007, 2009, 2014 Ben Asselstine 5 // 6 // This program is free software; you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation; either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Library General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program; if not, write to the Free Software 18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 // 02110-1301, USA. 20 21 #pragma once 22 #ifndef THREATLIST_H 23 #define THREATLIST_H 24 25 #include <list> 26 #include "Threat.h" 27 28 class Stack; 29 class Ruin; 30 class AICityInfo; 31 32 //! Artificial intelligence for representing a list of threats to a Player. 33 /** List of threats. 34 */ 35 class Threatlist : public std::list<Threat*> 36 { 37 public: 38 39 //! Default Constructor. 40 Threatlist(); 41 42 //! Destructor. 43 ~Threatlist(); 44 45 // Methods that operate on class data and modify the class. 46 47 //! Add a ruin as a threat 48 void addRuin(Ruin *ruin); 49 50 //! Adds a stack as a threat. 51 /** 52 * If other threats posed by the owner of the stack are close by, they 53 * are merged to a single threat. 54 */ 55 void addStack(Stack *stack); 56 57 //! Searches through the threat list and deletes the stack 58 void deleteStack(Stack* s); 59 60 //! deletes the stack in the threat list that has the given id. 61 void deleteStack(guint32 id); 62 63 // how much danger does this set of threats pose to the given city? 64 void findThreats(AICityInfo *info) const; 65 66 //! sort into a list of most dangerous first 67 void sortByValue(); 68 69 //! sort into list by closest first 70 void sortByDistance(Vector<int> pos); 71 72 //! sort into a list with value divded by distance. 73 void sortByDistanceAndValue(Vector<int> pos); 74 75 //! Behaves like std::list::erase(), but frees pointers as well 76 iterator flErase(iterator object); 77 78 //! Behaves like std::list::remove(), but frees pointers as well 79 bool flRemove(Threat* object); 80 81 // Methods that operate on class data but do not modify the class 82 83 //! return some debugging information 84 Glib::ustring toString() const; 85 86 void changeOwnership(Player *old_owner, Player *new_owner); 87 88 private: 89 90 //! Behaves like std::list::clear(), but frees pointers as well 91 void flClear(); 92 93 static bool compareValue(const Threat *lhs, const Threat *rhs); 94 }; 95 96 #endif // THREATLIST_H 97 98 // End of file 99