initial commit, lordsawar source, slightly modified
[lordsawar] / src / Threatlist.h
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 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 #ifndef THREATLIST_H
22 #define THREATLIST_H
23
24 #include <list>
25 #include "Threat.h"
26
27 class Stack;
28 class Ruin;
29 class AICityInfo;
30
31 using namespace std;
32
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
46         // Methods that operate on class data and modify the class.
47
48         //! Add a ruin as a threat
49         void addRuin(Ruin *ruin);
50         
51         //! Adds a stack as a threat. 
52         /**
53          * If other threats posed by the owner of the stack are close by, they 
54          * are merged to a single threat.
55          */
56         void addStack(Stack *stack);
57
58         //! Searches through the threat list and deletes the stack
59         void deleteStack(Stack* s);
60
61         //! deletes the stack in the threat list that has the given id.
62         void deleteStack(guint32 id);
63
64         // how much danger does this set of threats pose to the given city?
65         void findThreats(AICityInfo *info) const;
66
67         //! sort into a list of most dangerous first
68         void sortByValue();
69
70         //! sort into list by closest first
71         void sortByDistance(Vector<int> pos);
72
73         //! sort into a list with value divded by distance.
74         void sortByDistanceAndValue(Vector<int> pos);
75
76         //! Behaves like std::list::clear(), but frees pointers as well
77         void flClear();
78
79         //! Behaves like std::list::erase(), but frees pointers as well
80         iterator flErase(iterator object);
81
82         //! Behaves like std::list::remove(), but frees pointers as well
83         bool flRemove(Threat* object);
84
85         // Methods that operate on class data but do not modify the class
86
87         //! return some debugging information
88         string toString() const;
89         
90         void changeOwnership(Player *old_owner, Player *new_owner);
91
92     private:
93
94         static bool compareValue(const Threat *lhs, const Threat *rhs);
95 };
96
97 #endif // THREATLIST_H
98
99 // End of file