JNR
laFightingCreature.h
1 /*
2 
3 Jump'n'Run Engine
4 http://www.atanaslaskov.com/jnr/
5 
6 BSD LICENSE
7 Copyright (c) 2007-2013, Atanas Laskov
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
12 1. Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 2. Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL ATANAS LASKOV BE LIABLE FOR ANY
21 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 */
29 #ifndef M_FIGHTING_CREATURE_H
30 #define M_FIGHTING_CREATURE_H
31 
33 
34 
39 
40 #define M_DEATHFX_DURATION 1.5 //sec
41 #define M_DEATHFX_OFFSET (2*M_UNIT)
42 #define M_DEATHFX_ROTATION 360
43 
45  public laMovingCreature
46 {
47  //Can be constructed from class name
48  CLASS_NAME(laFightingCreature);
49 
50 protected:
51 
52  // Attack state and triggers
53  //
54  M_BOOL _bAttack; // attack charged and active
55 
56  unsigned _nSelectedAttack;
57  M_BOOL _bAttack_Quick;
58 
59  laTimeTrig _ttAttackCharge; // attack charge timer
60  laTimeTrig _ttAttack; // attack execution timer
61 
62  virtual void _hit_actions(unsigned nDamage); // actions to be performed after the creature is hit
63 
64  // Immunity state and triggers
65  //
66  laTimeTrig _ttHitImmunity;
67  laTimeTrig _ttDeath;
68 
69  // Sounds
70  //
71  laSound* _pAttackSound;
72  laSound* _pSufferSound;
73  laSound* _pDieSound;
74 
75  // Fx
76  fxParticleSystem _fxBlood;
77 
78  virtual unsigned _next_state( unsigned nCurrentState );
79 
80  inline void _animate_attacks();
81  inline void _trans_deathfx(laRenderer *r); //< Apply death Fx rotation and offset, and style changes
82 
83 public:
84  // Constructor/desturctor
85  //
86  laFightingCreature(rpgSheet* pSheet = NULL);
87  ~laFightingCreature(void);
88 
89  // Respawn creature
90  //
91  virtual void respawn();
92 
93  // Attack control methods
94  //
95  // attackInitiate() commences an attack but the actual hit, damage calculation etc., is
96  // not performed until the attack is fully charged;
97  //
98 
99  inline void attackSelect(unsigned nAttack) {
100  ASSERT(nAttack < ((rpgSheet_Fighter*)_pSheet)->properties()->vAttacks.size(),
101  "Attack %d not registered", nAttack);
102  _nSelectedAttack = nAttack;
103  };
104 
105  inline rpgAttack selectedAttack() {
106  ASSERT(_nSelectedAttack < ((rpgSheet_Fighter*)_pSheet)->properties()->vAttacks.size(),
107  "Attack %d not registered", _nSelectedAttack);
108  return ((rpgSheet_Fighter*)_pSheet)->modAttack( _nSelectedAttack );
109  };
110 
111  virtual void attackInitiate(M_BOOL bQuick = M_FALSE/*, M_BOOL bStrong = M_FALSE*/);
112  void attackStop();
113 
114  inline M_BOOL attackIsCharged() { return _bAttack; };
115  inline M_BOOL attackIsQuick() { return (_bAttack && _bAttack_Quick); }
116 
117  // Attack implementation methods
118  //
119  // The attack() and hit() methods are two ways of inflicting damage on ceatures;
120  // These methods act immediately and are invoked when the attack started by attackInitiate()
121  // is fully charged.
122  //
123  // NOTE: The hit() method assumes the AP modifier of the attacker = 1,
124  // and therefore it is more suitable for attacks performed by traps
125  // or other object that don't have modifiers.
126  //
127  // Attacks between monsters and the player should always be implemented
128  // with the attack() method, otherwise the AP modifiers are ignored.
129  //
130  virtual void attack( unsigned nAttackIndex, laFightingCreature* pTarget ); // hit target
131  inline void attack( laFightingCreature* pTarget ) { attack(_nSelectedAttack, pTarget); }
132 
133  virtual void hit( rpgAttack attack ); // hit me
134 
135  //rpgAttack attack(unsigned n) { return ((rpgSheet_Fighter*)_pSheet)->attack(n); }
136  //unsigned getDefence(unsigned nElement) {return ((rpgSheet_Fighter*)_pSheet)->getDefense(nElement);}
137  //double attackModifier() { return ((rpgSheet_Fighter*)_pSheet)->dMod_AP; }
138 
139  inline unsigned getHP() { return ((rpgSheet_Fighter*)_pSheet)->properties()->nHP; }
140  inline unsigned getMaxHP() { return ((rpgSheet_Fighter*)_pSheet)->properties()->nHP_Max; }
141 
142  inline M_BOOL isAlive() { return ((rpgSheet_Fighter*)_pSheet)->isAlive(); }
143  inline M_BOOL isImmune() { return !(_ttHitImmunity.isElapsed()); }
144 
145  // Overloaded movement methods
146  //
147  virtual void move(int direction){
148  laMovingCreature::move(direction);
149  if(direction && (direction != getMoveDirection())) attackStop();
150  }
151 
152  virtual M_BOOL jump(){
153  attackStop();
154  return laMovingCreature::jump();
155  }
156 
157  // Animate
158  //
159  virtual void animate(laTimer &t);
160 
161  // Specific draw method
162  //
163  virtual void _draw_positioned_rotated(laRenderer *r);
164  virtual void _drawFx_positioned(laRenderer *r);
165 
166  // This method is part of the laLoadableObj interface
167  //
168  virtual void load(class laFileParser *fp);
169 };
171 #endif
Moving Creature.
Abstract RPG Properties Sheet.
Definition: rpgSheet.h:107
Time-triggered events.
Definition: laTimeTrig.h:41
Virtual interface for the Engine graphics renderer.
Definition: laRenderer.h:98
virtual void move(int direction)
Attack RPG Properties.
Definition: rpgAttack.h:55
File Parser.
Definition: laFileParser.h:41
Sound Class.
Definition: laSound.h:40