1 | /* |
2 | Copyright (C) 1998-2001 Andreas Zehender <az@azweb.de> |
3 | |
4 | it under the terms of the GNU General Public License as published by |
5 | the Free Software Foundation; either version 2 of the License, or |
6 | (at your option) any later version. |
7 | |
8 | This program is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | GNU General Public License for more details. |
12 | |
13 | You should have received a copy of the GNU General Public License |
14 | along with this program; if not, write to the Free Software |
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
16 | */ |
17 | |
18 | #ifndef __KSD_AI_H |
19 | #define __KSD_AI_H |
20 | |
21 | #include <krandomsequence.h> |
22 | |
23 | #include "dialogs.h" |
24 | #include "options.h" |
25 | #include "sprites.h" |
26 | |
27 | enum Rotation {RLEFT,RNONE,RRIGHT}; |
28 | |
29 | struct MineHit |
30 | { |
31 | int mineNumber,hitTime; |
32 | double distance; |
33 | }; |
34 | |
35 | enum HitObject {HSHIP,HMINE,HSHOT,HNOTHING}; |
36 | |
37 | struct Hit |
38 | { |
39 | HitObject object; |
40 | int playerNumber,objectNumber,hitTime; |
41 | double distance; //distance^2 |
42 | }; |
43 | |
44 | struct Shot |
45 | { |
46 | Hit hit; |
47 | Rotation rotation; |
48 | int rotationFrames; |
49 | double score; |
50 | }; |
51 | |
52 | |
53 | class Ai |
54 | { |
55 | public: |
56 | Ai(int pn,ShipSprite* s[2],QList<BulletSprite*> *b[2], |
57 | QList<MineSprite*> *m[2],SConfig *c); |
58 | ~Ai(); |
59 | void newRound(); |
60 | void think(); |
61 | bool rotateLeft(){return rotation==RLEFT;} |
62 | bool rotateRight(){return rotation==RRIGHT;} |
63 | bool accelerate(){return acc;} |
64 | bool shootBullet(){return bullet;} |
65 | bool layMine(){return mine;} |
66 | private: |
67 | AiSprite nextPosition(AiSprite sp,double mult); |
68 | void nextPositions(AiSprite sp,QVector<AiSprite> *a,int frames); |
69 | Hit firstObject(AiSprite shot,int shotframes,int frames); |
70 | void shotScores(); |
71 | void calculateNextPositions(); |
72 | void setSpriteFieldSize(); |
73 | void testForHits(); |
74 | void tryShots(); |
75 | void chooseAction(); |
76 | |
77 | SConfig *cfg; |
78 | |
79 | KRandomSequence random; |
80 | |
81 | //actions |
82 | Rotation rotation; |
83 | bool acc; |
84 | bool bullet,mine; |
85 | //what to do when |
86 | int rotateFramesNumber,accelerateFramesNumber; |
87 | bool shoot; |
88 | double score; |
89 | //sprites |
90 | int playerNumber,opponentNumber; |
91 | ShipSprite *ship[2]; |
92 | QList<BulletSprite*> *bullets[2]; |
93 | QList<MineSprite*> *mines[2]; |
94 | QVector<AiSprite> *shipsNextPositions[2]; |
95 | QVector<AiSprite> *aiMines[2]; |
96 | int mineNumber[2]; |
97 | //possible Hits |
98 | QList<Shot*> myShots; |
99 | QList<Hit*> objectsHitByShip; |
100 | QList<Hit*> minesHitByShot; |
101 | int borderTime; |
102 | int sunTime; |
103 | //SpriteField width and height |
104 | double sfwidth,sfheight,sfwidth_2,sfheight_2; |
105 | //Difficulty |
106 | static int calcFrameIncrement[Options::EnumAiDifficulty::COUNT]; |
107 | static int calcPositionNumber[Options::EnumAiDifficulty::COUNT]; |
108 | static int calcShotDirections[Options::EnumAiDifficulty::COUNT]; |
109 | static int calcCollisions[Options::EnumAiDifficulty::COUNT]; |
110 | static int calcNextShot[Options::EnumAiDifficulty::COUNT]; |
111 | static double calcShotRandom[Options::EnumAiDifficulty::COUNT]; |
112 | |
113 | int calculateCollisions; |
114 | int waitShot; |
115 | }; |
116 | |
117 | #endif |
118 | |