1 /***************************************************************************
2                         battle.h  -  Battle turn class
3                              -------------------
4     begin                : Sat May 3 2003
5     copyright            : (C) 2003 by Gabor Torok
6     email                : cctorok@yahoo.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef BATTLE_H
19 #define BATTLE_H
20 #pragma once
21 
22 #include <iostream>
23 #include <string>
24 #include <vector>
25 #include "session.h"
26 #include "spellcaster.h"
27 
28 /**
29   *@author Gabor Torok
30   */
31 
32 class Session;
33 class Creature;
34 class Item;
35 class Projectile;
36 class Spell;
37 
38 /// This class represents a single battle turn.
39 
40 class Battle {
41 	enum {
42 		MESSAGE_SIZE = 200
43 	};
44 private:
45 	Session *session;
46 	Creature *creature;
47 	Item* item;
48 	char message[MESSAGE_SIZE];
49 	int creatureInitiative;
50 	bool initiativeCheck;
51 	int speed;
52 	float dist;
53 	bool empty;
54 	bool projectileHit;
55 	Spell *spell;
56 	int weaponWait;
57 	float range;
58 
59 	int ap, startingAp;
60 	bool paused;
61 	int steps;
62 	bool needsReset;
63 	int nextTurn;
64 
65 	// sounds
66 	static int handheldSwishSoundStart, handheldSwishSoundCount;
67 	static int bowSwishSoundStart, bowSwishSoundCount;
68 	static int potionSoundStart, potionSoundCount;
69 	static char *sound[];
70 
71 public:
72 
73 	static bool debugBattle;
74 
getAP()75 	inline int getAP() {
76 		return ap;
77 	}
decrAP()78 	inline int decrAP() {
79 		return --ap;
80 	}
getStartingAP()81 	inline int getStartingAP() {
82 		return startingAp;
83 	}
84 
85 	void endTurn();
86 
87 	static void setupBattles( Session *session, Battle *battle[], int count, std::vector<Battle *> *turns );
88 
89 	static void projectileHitTurn( Session *session, Projectile *proj, Creature *target );
90 	static void projectileHitTurn( Session *session, Projectile *proj, int x, int y );
91 
92 	Battle();
93 
94 	Battle( Session *session, Creature *creature );
95 	~Battle();
96 
97 	void reset( bool keepPaused = false, bool keepAP = false );
98 	Creature *getAvailableTarget();
99 	Creature *getAvailablePartyTarget();
100 
isEmpty()101 	inline bool isEmpty() {
102 		return empty;
103 	}
104 	bool fightTurn();
105 
106 	void dealDamage( float damage, int effect = Constants::EFFECT_GLOW, bool magical = false, GLuint delay = 0 );
107 
getCreature()108 	inline Creature *getCreature() {
109 		return creature;
110 	}
getSession()111 	inline Session *getSession() {
112 		return session;
113 	}
114 
115 	void invalidate();
116 
getSoundCount()117 	static inline int getSoundCount() {
118 		return handheldSwishSoundCount + bowSwishSoundCount + potionSoundCount;
119 	}
getSound(int index)120 	static inline char *getSound( int index ) {
121 		return sound[index];
122 	}
123 
124 	void castSpell( bool alwaysSucceeds = false );
125 
126 	void useSkill();
127 
128 	int calculateRange( Item *item = NULL );
129 
130 	bool describeAttack( Creature *target, char *buff, size_t buffSize, Color *color, bool includeActions );
131 
getRange()132 	inline float getRange() {
133 		return range;
134 	}
135 
136 	bool isInRangeOfTarget();
137 
138 protected:
139 	bool waitingOnAnimation( Creature *creature );
140 	void launchProjectile();
141 	//void initTurn();
142 	void hitWithItem();
143 	float applyMagicItemSpellDamage();
144 	void applyMagicItemDamage( float *damage );
145 	void applyHighAttackRoll( float *damage, float attack, float min, float max );
146 	bool handleLowAttackRoll( float attack, float min, float max );
147 	void prepareToHitMessage();
148 	void initItem( Item *item );
149 
150 	void executeEatDrinkAction();
151 	// return true if game paused
152 	bool pauseBeforePlayerTurn();
153 	void initTurnStep( bool callScript = false );
154 	int getAdjustedWait( int originalWait );
155 	void executeAction();
156 	void stepCloserToTarget();
157 	bool selectNewTarget();
158 	bool moveCreature();
159 
160 	static char *getRandomSound( int start, int count );
161 };
162 
163 #endif
164