File indexing completed on 2023-09-24 04:19:09
0001 /* 0002 SPDX-FileCopyrightText: 1998-2001 Andreas Zehender <az@azweb.de> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KSD_AI_H 0008 #define __KSD_AI_H 0009 0010 #include <QRandomGenerator> 0011 0012 #include "dialogs.h" 0013 #include "options.h" 0014 #include "sprites.h" 0015 0016 enum Rotation {RLEFT,RNONE,RRIGHT}; 0017 0018 struct MineHit 0019 { 0020 int mineNumber,hitTime; 0021 double distance; 0022 }; 0023 0024 enum HitObject {HSHIP,HMINE,HSHOT,HNOTHING}; 0025 0026 struct Hit 0027 { 0028 HitObject object; 0029 int playerNumber,objectNumber,hitTime; 0030 double distance; //distance^2 0031 }; 0032 0033 struct Shot 0034 { 0035 Hit hit; 0036 Rotation rotation; 0037 int rotationFrames; 0038 double score; 0039 }; 0040 0041 0042 class Ai 0043 { 0044 public: 0045 Ai(int pn,ShipSprite* s[2],QList<BulletSprite*> *b[2], 0046 QList<MineSprite*> *m[2],SConfig *c); 0047 ~Ai(); 0048 void newRound(); 0049 void think(); 0050 bool rotateLeft(){return rotation==RLEFT;} 0051 bool rotateRight(){return rotation==RRIGHT;} 0052 bool accelerate(){return acc;} 0053 bool shootBullet(){return bullet;} 0054 bool layMine(){return mine;} 0055 private: 0056 AiSprite nextPosition(AiSprite sp,double mult); 0057 void nextPositions(const AiSprite &sp,QVector<AiSprite> *a,int frames); 0058 Hit firstObject(AiSprite shot,int shotframes,int frames); 0059 void shotScores(); 0060 void calculateNextPositions(); 0061 void setSpriteFieldSize(); 0062 void testForHits(); 0063 void tryShots(); 0064 void chooseAction(); 0065 0066 SConfig *cfg; 0067 0068 QRandomGenerator random; 0069 0070 //actions 0071 Rotation rotation; 0072 bool acc; 0073 bool bullet,mine; 0074 //what to do when 0075 int rotateFramesNumber,accelerateFramesNumber; 0076 bool shoot; 0077 double score; 0078 //sprites 0079 int playerNumber,opponentNumber; 0080 ShipSprite *ship[2]; 0081 QList<BulletSprite*> *bullets[2]; 0082 QList<MineSprite*> *mines[2]; 0083 QVector<AiSprite> *shipsNextPositions[2]; 0084 QVector<AiSprite> *aiMines[2]; 0085 int mineNumber[2]; 0086 //possible Hits 0087 QList<Shot*> myShots; 0088 QList<Hit*> objectsHitByShip; 0089 QList<Hit*> minesHitByShot; 0090 int borderTime; 0091 int sunTime; 0092 //SpriteField width and height 0093 double sfwidth,sfheight,sfwidth_2,sfheight_2; 0094 //Difficulty 0095 static int calcFrameIncrement[Options::EnumAiDifficulty::COUNT]; 0096 static int calcPositionNumber[Options::EnumAiDifficulty::COUNT]; 0097 static int calcShotDirections[Options::EnumAiDifficulty::COUNT]; 0098 static int calcCollisions[Options::EnumAiDifficulty::COUNT]; 0099 static int calcNextShot[Options::EnumAiDifficulty::COUNT]; 0100 static double calcShotRandom[Options::EnumAiDifficulty::COUNT]; 0101 0102 int calculateCollisions; 0103 int waitShot; 0104 }; 0105 0106 #endif