1 /******************************************************************************
2  *  Warmux is a convivial mass murder game.
3  *  Copyright (C) 2001-2011 Warmux Team.
4  *
5  *  This program is free software; you can redistribute it and/or modify
6  *  it under the terms of the GNU General Public License as published by
7  *  the Free Software Foundation; either version 2 of the License, or
8  *  (at your option) any later version.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18  ******************************************************************************
19  * A factory for AI strategies. It contains no turn specfic data.
20  *****************************************************************************/
21 
22 #ifndef AI_IDEA_H
23 #define AI_IDEA_H
24 
25 #include "ai/ai_strategy.h"
26 #include "ai/ai_weapons_weighting.h"
27 #include "weapon/weapon.h"
28 #include "weapon/weapon_launcher.h"
29 
30 class AIIdea
31 {
32 protected:
33   static bool CanUseWeapon(const Weapon * weapon);
34   static bool CanUseCharacter(const Character & character);
XDeltaToDirection(int delta)35   static LRDirection XDeltaToDirection(int delta) { return (delta < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT; }
XDeltaToDirection(float delta)36   static LRDirection XDeltaToDirection(float delta) { return (delta < 0) ? DIRECTION_LEFT : DIRECTION_RIGHT; }
37   static float GetDirectionRelativeAngle(LRDirection direction, float angle);
38   static float RateDamageDoneToEnemy(int damage, const Character & enemy);
39   static float RateDamageDoneToEnemy(int min_damage, int max_damage, const Character & enemy);
40   static float RateExplosion(const Character & shooter, const Point2i& position,
41                              const ExplosiveWeaponConfig & cfg,
42                              const float& expected_additional_distance);
43 public:
44   virtual AIStrategy * CreateStrategy() const = 0;
~AIIdea()45   virtual ~AIIdea() {}
NoLongerPossible()46   virtual bool NoLongerPossible() const { return false; }
GetMaxRating(bool)47   virtual float GetMaxRating(bool) const { return 0.0f; }
48 };
49 
50 class SkipTurnIdea : public AIIdea
51 {
52 public:
53   virtual AIStrategy * CreateStrategy() const;
54 };
55 
56 class WasteAmmoUnitsIdea : public AIIdea
57 {
58 public:
59   virtual AIStrategy * CreateStrategy() const;
60 };
61 
62 class AIShootIdea : public AIIdea
63 {
64 protected:
65   const WeaponsWeighting & weapons_weighting;
66   const Character & shooter;
67   const Character & enemy;
68   Weapon::Weapon_type weapon_type;
69 
AIShootIdea(const WeaponsWeighting & w,const Character & s,const Character & e,Weapon::Weapon_type t)70   AIShootIdea(const WeaponsWeighting & w,
71               const Character & s, const Character & e,
72               Weapon::Weapon_type t)
73     : weapons_weighting(w), shooter(s), enemy(e), weapon_type(t) { }
74 public:
75   virtual bool NoLongerPossible() const;
76   virtual float GetMaxRating(bool one_shot) const;
77 };
78 
79 class ShootDirectlyAtEnemyIdea : public AIShootIdea
80 {
81   int max_sq_distance;
82 public:
83   ShootDirectlyAtEnemyIdea(const WeaponsWeighting & weapons_weighting,
84                            const Character & shooter, const Character & enemy,
85                            Weapon::Weapon_type weapon_type, int max_distance);
86   virtual AIStrategy * CreateStrategy() const;
87 };
88 
89 class FireMissileWithFixedDurationIdea : public AIShootIdea
90 {
91   float duration;
92   int timeout; // if positive the character will set it to the specified value.
93 public:
94   FireMissileWithFixedDurationIdea(const WeaponsWeighting & weapons_weighting,
95                                    const Character & shooter, const Character & enemy,
96                                    Weapon::Weapon_type weapon_type,
97                                    float duration, int timeout = -1);
98   virtual AIStrategy * CreateStrategy() const;
99 };
100 
101 #endif
102