1 // Copyright (C) 2004 John Farrell
2 // Copyright (C) 2004 Ulf Lorenz
3 // Copyright (C) 2004, 2005, 2006 Andrea Paternesi
4 // Copyright (C) 2007, 2008, 2009 Ben Asselstine
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.
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.
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
35 /** Class which describes a threat to a player.
37 * The smart AI player tries to assess all enemy stacks and cities and all
38 * ruins and store the results in threats. A threat has three characteristic
41 * - a strength which determines how strong the stack (or the stacks defending
43 * - a danger which determines how close the enemy object is (if an enemy stack
44 * endangers two cities at once, the danger value doubles). The danger depends
45 * on the distance to the AI's cities as well as the strength of the stack.
46 * - a value, which gives an assessment of how valuable it is to destroy the
47 * threat. As an example, taking over a dangerous enemy city is more valuable
48 * than destroying a stack because the AI gets an additional city. The value
49 * is the sum of the danger of the threat and some additional bonus.
51 * Furthermore, the threat class has some additional functions. They are e.g.
52 * neccessary because the AI bundles several stacks which are close together
53 * or a stack which is in an enemy city to one single threat.
55 * For more information about the smart AI, see ai_smart.h
58 class Threat: public Ownable
63 //! Constructor. Our threat is an enemy city.
66 //! Constructor. The threat is an enemy stack.
69 //! Constructor. The "threat" is a ruin (the danger value is 0)
75 // Methods that operate on class data and modify the class.
77 //! Add a stack to this threat.
78 void addStack(Stack *stack);
80 //! Removes the stack s from the threat.
81 void deleteStack(Stack* s);
83 //! Removes the stack with the given id from the threat.
84 void deleteStack(guint32 id);
86 //! Increase the danger of this threat
87 void addDanger(float danger);
89 // Methods that operate on class data and do not modify the class.
91 /** Checks if a threat is close to a certain position and "belongs"
92 * (i.e. is caused by) a certain player.
94 * The background is that threats close to each other are merged into
97 * @param pos the position the threat has to be close to
98 * @param p the player who has to cause the threat
99 * @return true if both the position and the player satisfy the
100 * conditions, else return false
102 bool Near(Vector<int> pos, Player *p) const;
104 //! How strong is this threat?
105 float getStrength() const {return d_strength;}
107 /** Returns the closest point of a threat to a certain location
108 * (remember that a threat can consist of several single threats
109 * or a city which covers more than one tile)
111 * If there are no dangers left, it returns the point (-1, -1).
113 Vector<int> getClosestPoint(Vector<int> location) const;
116 //! return the danger posed by this threat to the current player
117 float getDanger() const { return d_danger; }
119 float getValue() const {return d_value;}
121 //! Does this threat contain a city?
122 bool isCity() const { return d_city != 0; }
124 //! Is this threat a ruin?
125 bool isRuin() const { return d_ruin != 0; }
127 //! Can be used for some general debug output
128 std::string toString() const;
132 void calculateValue();
133 void calculateStrength();
136 //! The city associated with this threat.
139 //! The ruin associated with this threat.
142 //! The list of stacks associated with this threat.
143 StackReflist *d_stacks;
145 //! The amount of danger this threat represents.
148 //! Danger augmented by some other factors.