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, 2010, 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 THREAT_H 23 #define THREAT_H 24 25 #include <gtkmm.h> 26 #include "vector.h" 27 #include "Ownable.h" 28 29 class City; 30 class StackReflist; 31 class Stack; 32 class Player; 33 class Ruin; 34 35 //! Artificial intelligence for representing a threat to a Player. 36 /** 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 39 * figures: 40 * 41 * - a strength which determines how strong the stack (or the stacks defending 42 * the city) are 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. 50 * 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. 54 * 55 * For more information about the smart AI, see ai_smart.h 56 */ 57 58 class Threat: public Ownable 59 { 60 public: 61 // CREATORS 62 63 //! Constructor. Our threat is an enemy city. 64 Threat(City *c); 65 66 //! Constructor. The threat is an enemy stack. 67 Threat(Stack *s); 68 69 //! Constructor. The "threat" is a ruin (the danger value is 0) 70 Threat(Ruin *r); 71 72 //! Destructor. 73 ~Threat(); 74 75 // Methods that operate on class data and modify the class. 76 77 //! Add a stack to this threat. 78 void addStack(Stack *stack); 79 80 //! Removes the stack s from the threat. 81 void deleteStack(Stack* s); 82 83 //! Removes the stack with the given id from the threat. 84 void deleteStack(guint32 id); 85 86 //! Increase the danger of this threat 87 void addDanger(float danger); 88 89 // Methods that operate on class data and do not modify the class. 90 91 /** Checks if a threat is close to a certain position and "belongs" 92 * (i.e. is caused by) a certain player. 93 * 94 * The background is that threats close to each other are merged into 95 * a single threat. 96 * 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 101 */ 102 bool Near(Vector<int> pos, Player *p) const; 103 104 //! How strong is this threat? getStrength()105 float getStrength() const {return d_strength;} 106 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) 110 * 111 * If there are no dangers left, it returns the point (-1, -1). 112 */ 113 Vector<int> getClosestPoint(Vector<int> location) const; 114 115 116 //! return the danger posed by this threat to the current player getDanger()117 float getDanger() const { return d_danger; } 118 getValue()119 float getValue() const {return d_value;} 120 121 //! Does this threat contain a city? isCity()122 bool isCity() const { return d_city != 0; } 123 124 //! Is this threat a ruin? isRuin()125 bool isRuin() const { return d_ruin != 0; } 126 127 //! Can be used for some general debug output 128 Glib::ustring toString() const; 129 130 void changeOwnership(Player *old_owner, Player *new_owner); 131 private: 132 133 void calculateValue(); 134 void calculateStrength(); 135 // DATA 136 137 //! The city associated with this threat. 138 City *d_city; 139 140 //! The ruin associated with this threat. 141 Ruin *d_ruin; 142 143 //! The list of stacks associated with this threat. 144 StackReflist *d_stacks; 145 146 //! The amount of danger this threat represents. 147 float d_danger; 148 149 //! Danger augmented by some other factors. 150 float d_value; 151 152 float d_strength; 153 }; 154 155 #endif // THREAT_H 156 157 // End of file 158