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 __CREATURE_H 22 #define __CREATURE_H 23 24 #include <math.h> 25 #include "xlist.h" 26 #include "std_ai.h" 27 #include "bodypart.h" 28 #include "magic.h" 29 #include "skills.h" 30 #include "wskills.h" 31 #include "xpotion.h" 32 #include "xcorpse.h" 33 #include "incl_i.h" 34 #include "cr_defs.h" 35 #include "deity.h" 36 37 enum AI_TYPE {AI_HERO = 0, AI_SIMPLE = 1}; 38 39 enum ACTION { 40 A_UNKNOWN = 0, 41 A_MOVE = 1, 42 // A_MOVETOSTAIRWAY = 2, 43 A_ATTACK = 3, 44 A_CAST = 4, 45 A_EAT = 5, 46 A_READ = 6, 47 A_USETOOL = 7, 48 }; 49 50 51 enum TACTICS_STATE 52 { 53 TS_COWARD, 54 TS_DEFENSIVE, 55 TS_NORMAL, 56 TS_AGRESSIVE, 57 TS_BERSERKER, 58 }; 59 60 enum CR_NAME_TYPE 61 { 62 CRN_T1, //you, the kobold, someone 63 CRN_T2, //you, he/she, it 64 CRN_T3, //your, him/her, it 65 CRN_T4, //yours, his/hers, its 66 }; 67 68 69 70 /////// attack structures /////////// 71 // 1) Creatures can make one attack with several consiquences: 72 // a) just a simple damage 73 // b) stun, paralyze, poison 74 // c) fire, cold or other damage (same with 'b') 75 // 2) Creature extend it damage by some fetures 76 // a) spawn when attack was successful 77 // b) 'eat' armour or weapon 78 79 enum EXTENDED_ATTACK 80 { 81 EA_NONE, 82 EA_SPAWN, 83 }; 84 85 struct MELEE_ATTACK 86 { 87 EXTENDED_ATTACK e_attack; 88 RESISTANCE r_attack; 89 int prob; //0..100 90 }; 91 92 93 94 95 class XAI; 96 class XStandardAI; 97 class XModifer; 98 class XMagic; 99 class XPotion; 100 class XBook; 101 class XScroll; 102 enum MAGIC_SCHOOL; 103 104 struct ACTION_DATA 105 { ACTION_DATAACTION_DATA106 ACTION_DATA() : item(NULL), action(A_MOVE) {} 107 ACTION action; 108 XPtr<XItem> item; 109 void Store(XFile * f); 110 void Restore(XFile * f); 111 }; 112 113 114 typedef int (ITEM_FILTR)(XItem *); 115 116 struct XTREQUEST 117 { 118 int max_rng; 119 ITEM_FILTR * item_filtr; 120 }; 121 122 struct XTRESPONSE 123 { 124 XPoint pt; 125 XObject * o; 126 }; 127 128 enum MISSILE_FL_TYPE 129 { 130 MFT_ARROW, 131 MFT_BALL, 132 }; 133 134 enum MF_RESULT 135 { 136 MF_HIT, 137 MF_AVOID, 138 MF_BLOCK, 139 }; 140 141 struct MF_DATA //struct for missile flight 142 { 143 int sx; //start position; 144 int sy; 145 int ex; //target position 146 int ey; 147 MISSILE_FL_TYPE arrow_type; 148 int arrow_color; 149 int max_range; //if creature avoid missile - it flight away. 150 int missile_speed; //greater speed, harder to avoid. 151 int to_hit; //hit bonus of missile; 152 XPoint pt; //position where arrow stopped 153 XLocation * l; //where it is... 154 }; 155 156 struct DAMAGE_DATA //struct for inflict damage to creature 157 { 158 XCreature * target; 159 XCreature * attacker; 160 const char * attacker_name; //if specified this name, than write it instead attacker name 161 int damage; 162 }; 163 164 struct _CREATURE; 165 166 class XCreature : public XBaseObject 167 { 168 public: 169 XItemList contain; 170 XList<XBodyPart *> components; 171 CR_PERSON_TYPE creature_person_type; 172 const char * creature_description; 173 CREATURE_NAME creature_name; //allow to store less info into save file 174 const _CREATURE * super_info; //full information about Creature Creation struct... 175 public: 176 DECLARE_CREATOR(XCreature, XBaseObject); 177 XCreature(); 178 virtual void Invalidate(); 179 Compare(XObject * o)180 virtual int Compare(XObject * o) {return 1;} 181 182 int TestMove(); 183 virtual void NewMove(); 184 virtual void Move(); 185 virtual void HideOldView(); 186 virtual void ShowNewView(); 187 virtual void PutStatus(); 188 virtual void DoMove(); 189 int Run(); 190 191 XStandardAI * xai; 192 193 unsigned long _EXP; 194 int level; 195 int base_exp; 196 unsigned long ExpOfLevel(int lev); 197 void AddExp(unsigned long exp); 198 199 int GetSpeed(); 200 201 CR_GENDER GetGender(); 202 char * GetGenderStr(); 203 204 int lttm; //long doing time to move 205 int isDisturb; //is creature disturbed duaring lttm 206 207 ACTION_DATA action_data; 208 virtual int stopAction(); 209 210 void Regenerate(); 211 int onHeal(int _hp); 212 int onRestorePP(int _pp); 213 214 virtual void IncLevel(); 215 216 virtual int Read(XItem * item); 217 int continueRead(); 218 219 virtual int Eat(XAnyFood * food); 220 int continueEat(); 221 222 virtual int UseItem(XItem * item); 223 int continueUseItem(); 224 225 226 227 int base_nutrio; //stomach size for normal satiation 228 int nutrio; //stomach satioation; 229 int nutrio_speed; //speed with which nutrients decrease; 230 int DecNutrio(); 231 FOOD_FEELING food_feeling; 232 233 void MoveStairWay(); 234 235 virtual void Attack(); 236 virtual void Die(XCreature * killer); 237 238 XBodyPart * GetRNDBodyPart(ITEM_MASK xim, RBP_FLAG rbpf); 239 XBodyPart * GetRNDBodyPart(); 240 int GetHITFHBonus(XItem * weapon); 241 int GetShieldDVBonus(); 242 int GetDMGFHBonus(XItem * weapon); 243 int GetHIT(); 244 int GetDV(XCreature * attacker = NULL); 245 int GetDMG(); 246 int GetPV(); 247 int GetResistance(RESISTANCE tr); 248 int GetVisibleRadius(); 249 int GetTacticsDVBonus(); 250 int GetTacticsHITBonus(); 251 int GetTacticsDMGBonus(); 252 253 virtual int GetTarget(TARGET_REASON tr, XPoint * pt = NULL, int max_range = 0, XObject ** back = NULL);//Get target for a spell onIdentifyItem()254 virtual XItem * onIdentifyItem() {return NULL;} 255 virtual int TargetOp(TARGET_REASON tr, XTREQUEST * rq, XTRESPONSE * rp); SelectItem(ITEM_FILTR * filtr)256 virtual XItem * SelectItem(ITEM_FILTR * filtr) {return NULL;} 257 258 int Shoot(int tx, int ty); 259 XItem * GetItem(BODYPART bp, int count = 0); 260 XBodyPart * GetBodyPart(BODYPART bp, int count = 0); 261 int CanWear(XItem * item); 262 int Wear(XItem * item); //if can Wear, Wear it. 263 264 XModifer * md; 265 XMagic * m; 266 XSkills * sk; 267 XWarSkills * wsk; 268 269 XResistance added_resists; 270 XStats added_stats; 271 XStats max_stats; 272 int added_DV; 273 int added_PV; 274 int added_HIT; 275 int added_DMG; 276 int added_RNG; 277 int added_HP; 278 int added_PP; 279 int added_speed; 280 /* unsigned int added_xproperty;*/ 281 282 283 bool ContainItem(XItem * item); //Adds item to creature inventory, increase cqrried weight. 284 int DropItem(XItem * i); 285 int PickUpItem(XItem * i); 286 CARRY_STATE GetCarryState(); 287 int CarryValue(CARRY_STATE cs); 288 bool CarryItem(XItem * item); 289 void UnCarryItem(XItem * item); 290 int carried_weight; 291 292 int MoneyOp(int money_count); // if money_count >= 0 then add money, else sub. 293 294 int GetStats(STATS st); 295 int GainAttr(STATS st, int val); 296 int GainResist(RESISTANCE rs, int val); 297 int GetMaxHP(); 298 int GetMaxPP(); 299 int GetExp(); 300 int GetCreatureStrength(); 301 // static int AttackCreature(ATTACK_DATA * pData); 302 static int InflictDamage(DAMAGE_DATA * pData); 303 int AttackCreature(XCreature * target, int dmg); //hit tgt for dmg damage! 304 int AttackCreature(XCreature * target, int dmg, RESISTANCE tr, const char * magic_name); //hit tgt for dmg damage! 305 int onMagicDamage(int dmg, RESISTANCE tr); 306 int CauseEffect(XCreature * attacker, int dmg, RESISTANCE tr); 307 int CauseEffect(int dmg, BRAND_TYPE brt); 308 int onAttacked(XCreature * attacker, int dmg); 309 int onAttackedByMagic(XCreature * attacker, int dmg, RESISTANCE tr, const char * magic_name); 310 GetMeleeAttackMsg()311 virtual char * GetMeleeAttackMsg() {return "attack";} 312 313 virtual void FirstStep(int _x, int _y, XLocation * _l); 314 virtual void LastStep(); 315 316 static MF_RESULT MissileFlight(MF_DATA * mfd); 317 318 virtual void Store(XFile * f); 319 virtual void Restore(XFile * f); 320 321 CREATURE_CLASS creature_class; 322 GROUP_ID group_id; //orcs warparty has id 1, bandits - id 2, etc 323 StdAnswer()324 virtual char * StdAnswer() {return "You receive no answer.";} 325 virtual int Chat(XCreature * chatter, char * msg); 326 327 virtual int onGiveItem(XCreature * giver, XItem * item); 328 329 TACTICS_STATE tactics; ChangeTactics(TACTICS_STATE tact)330 void ChangeTactics(TACTICS_STATE tact) {tactics = tact;} 331 char * GetWoundMsg(int flag = 0); 332 333 void GetRangeAttackInfo(int * range, int * hit, XDice * dmg); 334 335 CREATURE_SIZE creature_size; 336 int attack_energy; 337 int move_energy; 338 int base_speed; 339 int MeleeAttack(XCreature * target, XItem * weapon); 340 XQList<MELEE_ATTACK> * melee_attack; 341 342 void Sacrifice(XItem * item); 343 XReligion religion; 344 345 346 int isCreatureVisible(XCreature * cr); //check if creature visible or invisible 347 bool isVisible(); //check if creature visible to add acction message to msgwin 348 static XCreature * main_creature; //at this time is used to determine visibility of msg 349 isHero()350 bool isHero() { return (im & IM_HERO) > 0;} 351 352 char * GetNameEx(CR_NAME_TYPE crn); 353 char * GetVerb(char * verb); 354 355 }; 356 357 //Fake creature is need 358 class XFakeCreature : public XCreature 359 { 360 public: XFakeCreature(char * fake_name)361 XFakeCreature(char * fake_name) { strcpy(name, fake_name); } 362 }; 363 #endif 364