1 /* 2 This file is part of "Avanor, the Land of Mystery" roguelike game 3 Home page: http://www.avanor.com/ 4 Copyright (C) 2000-2003 Vadim Gaidukevich 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 2 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 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., 675 Mass Ave, Cambridge, MA 02139, USA. 19 */ 20 21 #ifndef __STD_AI_H 22 #define __STD_AI_H 23 24 #include "creature.h" 25 #include "item.h" 26 #include "cr_defs.h" 27 #include "rect.h" 28 #include "msgwin.h" 29 30 enum AI_FLAG { 31 AIF_NONE = 0x00000000, 32 AIF_ALLOW_PICK_UP = 0x00000001, //can creature pick items 33 34 AIF_ALLOW_MOVE_WAY_UP = 0x00000002, //can creature move upstair 35 AIF_ALLOW_MOVE_WAY_DOWN = 0x00000004, //can creature move downstair 36 AIF_FREE_WAY = AIF_ALLOW_MOVE_WAY_UP | AIF_ALLOW_MOVE_WAY_DOWN, 37 AIF_ALLOW_MOVE_OUT = 0x00000008, //can creature move to main location 38 AIF_FREE_MOVE = AIF_FREE_WAY | AIF_ALLOW_MOVE_OUT, //can creature move were it want 39 40 AIF_FIND_WAY = 0x00000010, //creature pursuit enemy in other locations.. 41 AIF_PEACEFUL = 0x00000020, //creature never attack first 42 AIF_COWARD = 0x00000040, //creature coward strenghter creatures, Also run away when wounded to much 43 AIF_ALLOW_PACK = 0x00000100, //creature try make a pack 44 AIF_ALLOW_WEAR_ITEM = 0x00000200, //creature can wear items 45 AIF_GUARD_AREA = 0x00000400, //this creature guard a area 46 AIF_PROTECT_AREA = 0x00000800, //creature attack every who enter this area 47 AIF_RANDOM_MOVE = 0x00001000, //creature move randomly 48 AIF_EXPLORER_MOVE = 0x00002000, //creature explore dangeon 49 AIF_EXECUTE_SCRIPT = 0x00004000, //if nothing to do, execute script... 50 AIF_NO_SWAP = 0x00008000, //you can't swap place with this creature if it frendly 51 52 AIF_INSECT = AIF_FREE_WAY | AIF_RANDOM_MOVE, 53 AIF_LO_ANIMAL = AIF_FREE_WAY | AIF_RANDOM_MOVE | AIF_COWARD, 54 AIF_HI_ANIMAL = AIF_FREE_WAY | AIF_RANDOM_MOVE | AIF_FIND_WAY | AIF_COWARD, 55 AIF_CREATURE = AIF_ALLOW_PICK_UP | AIF_ALLOW_WEAR_ITEM | AIF_FREE_WAY | AIF_RANDOM_MOVE | AIF_FIND_WAY | AIF_COWARD, 56 AIF_HUMAN = AIF_ALLOW_PICK_UP | AIF_ALLOW_WEAR_ITEM | AIF_FREE_MOVE | AIF_RANDOM_MOVE | AIF_FIND_WAY | AIF_COWARD, 57 AIF_GHOST = AIF_FREE_WAY | AIF_RANDOM_MOVE | AIF_FIND_WAY | AIF_COWARD, 58 59 }; 60 61 62 enum COMPANION_COMMAND 63 { 64 CC_NONE, 65 CC_ATTACK, 66 CC_MOVE, 67 CC_WAIT, 68 CC_FOLLOW, 69 CC_GUARD, 70 }; 71 72 enum SCRIPT_COMMAND 73 { 74 SCC_NONE, 75 SCC_MOVE_POINT, 76 SCC_MOVE_LOCATION, 77 SCC_COLLECT_MUSHROOM, 78 SCC_DROP_ITEM, 79 }; 80 81 struct SCRIPT_CMD 82 { 83 SCRIPT_COMMAND cmd; 84 int pt_x; 85 int pt_y; 86 LOCATION ln; 87 ITEM_MASK im; 88 }; 89 90 #define ENEMY_LIST_SIZE 5 91 class XCreature; 92 class XStandardAI : public XObject 93 { 94 protected: XStandardAI()95 XStandardAI() {} 96 public: 97 DECLARE_CREATOR(XStandardAI, XObject); 98 XStandardAI(XCreature * _cr); 99 virtual void Invalidate(); 100 101 void SetArea(XRect * area, LOCATION ln); SetOwner(XCreature * cr)102 void SetOwner(XCreature * cr) {ai_owner = cr;} 103 104 virtual void AnalyzeGrid(int j, int i, int w); 105 virtual void AnalyzeView(int radius); 106 virtual void Move(); 107 virtual int isPersonalEnemy(XCreature * cr); 108 virtual int isEnemy(XCreature * cr); 109 virtual void onWasAttacked(XCreature * attacker); 110 virtual void onDie(XCreature * killer); 111 virtual void onSteal(XCreature * rogue); 112 113 virtual int Chat(XCreature * chatter = NULL, char * msg = NULL); 114 virtual int onGiveItem(XCreature * giver, XItem * item); 115 virtual int GetTargetPos(XPoint * pt); 116 /* virtual int Chat(XCreature * chatter = NULL, char * msg = NULL); 117 118 119 int Eat(int dl); 120 */ 121 122 int Wear(); 123 124 void GetDirection(XPoint * target, XPoint * direction); //calculate exact direction to target 125 void GetRandDirection(XPoint * target, XPoint * direction); //calculate aproximate direction target 126 void GetExactDirection(XPoint * target, XPoint * direction); //calucalte exact direction on target 127 128 void SetAIFlag(AI_FLAG aif); 129 void ResAIFlag(AI_FLAG aif); GetAIFlag()130 unsigned int GetAIFlag() { return ai_flag; } 131 void SetEnemyClass(CREATURE_CLASS cr_class); 132 133 void AddPersonalEnemy(XCreature * cr); 134 void RemovePersonalEnemy(XCreature * cr); 135 136 virtual void Store(XFile * f); 137 virtual void Restore(XFile * f); 138 void SetGroupEnemy(XCreature * enemy); 139 140 141 //companion 142 XPtr<XCreature> companion; 143 COMPANION_COMMAND companion_command; 144 XPtr<XCreature> ordered_enemy; 145 146 XQList<SCRIPT_CMD> script; 147 void ExecuteScript(XQList<SCRIPT_CMD> * scr); 148 void RunScript(); 149 150 //the create who know trap can't activate it 151 //used for random rooms guardians. 152 XList<XMapObject *> known_traps; 153 void LearnTraps(); 154 bool isKnowThisTrap(XMapObject * trap); 155 protected: 156 XPtr<XCreature> personal_enemy[ENEMY_LIST_SIZE]; 157 158 159 int FindPath(XPoint * target, XPoint * direction); 160 int AttackEnemy(int x, int y); 161 int CastSpell(); 162 int Shoot(); 163 int ReadScroll(); 164 int DrinkPotion(); 165 int PickUpItems(); 166 167 int MoveTo(int x, int y, XLocation * l = NULL); 168 169 170 171 int TryToRunAway(); //creature tryes to run away from attacker... if can 172 173 bool CanMoveHere(int px, int py); //can move here without risk of attaking friendly creature 174 175 AI_FLAG ai_flag; 176 XPtr<XCreature> ai_owner; 177 CREATURE_CLASS enemy_class; 178 179 XRect guard_area; 180 LOCATION guard_area_location; 181 182 183 XCreature * enemy; // current targeted creature 184 int enemy_dist; // distance to the closest enemy 185 186 XPtr<XCreature> last_enemy; 187 XMapObject * last_moved_way; //used to prevent up/down moving way repeating... 188 int invisible_x; 189 int invisible_y; 190 int invisible_hunting_mode; 191 192 int friend_avg_x; 193 int friend_avg_y; 194 int friends_count; //count of friends (which has same enemy) for coward attack 195 196 int item_dist; // distance to the closest item 197 int item_x; // item x coordinate 198 int item_y; // item y coordinate 199 200 int way_dist; 201 int way_x; 202 int way_y; 203 204 // int turns_on_level; // number of turns spent on this level 205 206 }; 207 208 #endif 209