Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Tactics3DAction.h
Go to the documentation of this file.
1 // Copyright (C) 2006-2015 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This file is part of Tactics3D.
7 //
8 // Tactics3D is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // Tactics3D is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23 #ifndef TACTICS3DACTION_H
24 #define TACTICS3DACTION_H
25 
26 #include <vector>
27 
28 #include "../Libs/Utils_LIB/UTypes.h"
29 
30 #include "Tactics3DFightingStyle.h"
31 #include "Tactics3DSuperPower.h"
32 
33 namespace Tactics3D {
34  class Warrior;
35  class AttackRange;
36 
39 
40  struct Action {
42 
43  std::string _name;
45  bool _isAuto;
48  std::vector<OpenSkyNet::Utils::TaggedUnion> _params;
49 
50  Action(const std::string& name_="NO_ACTION", ACTION_TYPE type_=NO_ACTION, bool isAuto_=true) :
51  _name(name_), _type(type_), _isAuto(isAuto_), _isContinuous(false), _performer(0) {}
52 
53  virtual ~Action() {}
54 
55  virtual void getPrePerformInfo(char* buffer_, int bufferLen_) const { memset(buffer_,0,bufferLen_); }
56  virtual void getAnimationName(char* buffer_, int bufferLen_) const { memset(buffer_,0,bufferLen_); }
57  static void getPlayerInfo(char* buffer_, int bufferLen_) { memset(buffer_,0,bufferLen_); }
58 
59  virtual bool canMoveInSameRound() const { return true; }
60  virtual bool canTranslate() const { return false; }
61  virtual bool canRotate() const { return false; }
62 
63  virtual void perform() {}
64  };
65 
66  struct NoPAction : public Action {
67  NoPAction() : Action("No Performance",NOP_ACTION,true) {}
68  };
69 
70  struct DelayAction : public Action {
71  DelayAction() : Action("Delay",DELAY_ACTION,true) {}
72 
73  static void getPlayerInfo(char* buffer_, int bufferLen_);
74  };
75 
76  struct MoveAction : public Action {
77  MoveAction() : Action("Move",MOVE_ACTION,true) {}
78 
79  static void getPlayerInfo(char* buffer_, int bufferLen_);
80 
81  virtual bool canTranslate() const { return true; }
82  virtual bool canRotate() const { return true; }
83 
84  virtual void perform();
85  };
86 
87  struct RepairThrustersAction : public Action {
88  RepairThrustersAction() : Action("Repair Thrusters",REPAIR_THRUSTERS,true) {}
89 
90  static void getPlayerInfo(char* buffer_, int bufferLen_);
91 
92  virtual void perform();
93  };
94 
95  struct BreakGrappleAction : public Action {
96  BreakGrappleAction() : Action("Break Grapple",BREAK_GRAPPLE,true) {}
97 
98  static void getPlayerInfo(char* buffer_, int bufferLen_);
99 
100  virtual void perform();
101  };
102 
103  struct AttackAction : public Action {
104  AttackAction() : Action("Attack",ATTACK_ACTION,false) {}
105 
106  AttackAction(Warrior* performer_, const AttackRange* attackRange_, Warrior* defender_)
107  : Action("Attack",ATTACK_ACTION,false) {
108  _performer = performer_;
109  _params.push_back(attackRange_);
110  _params.push_back(defender_);
111  }
112 
113  inline const AttackRange* getAttackRange() const {
114  assert(_params.size() > 0);
115  return static_cast<const AttackRange*>(_params[0].getConstPointer());
116  }
117 
118  inline Warrior* getDefender() const {
119  assert(_params.size() > 1);
120  return static_cast<Warrior*>(_params[1].getPointer());
121  }
122 
123  virtual void getAnimationName(char* buffer_, int bufferLen_) const { strncpy(buffer_, "attack", bufferLen_); }
124  static void getPlayerInfo(char* buffer_, int bufferLen_);
125 
126  virtual void perform();
127  };
128 
129  struct SpecialMoveAction : public Action {
131 
132  SpecialMoveAction(Warrior* performer_, SPECIAL_MOVE specialMove_, const AttackRange* attackRange_,
133  std::vector<Warrior*> defenders_,
134  std::vector<OpenSkyNet::Utils::TaggedUnion>& specialMoveParams_);
135 
136  virtual void getPrePerformInfo(char* buffer_, int bufferLen_) const { getSpecialMove()->getPrePerformInfo(buffer_, bufferLen_); }
137  virtual void getAnimationName(char* buffer_, int bufferLen_) const { getSpecialMove()->getAnimationName(buffer_, bufferLen_); }
138  static void getPlayerInfo(char* buffer_, int bufferLen_);
139 
140  virtual bool canMoveInSameRound() const { return getSpecialMove()->canMoveInSameRound(); }
141  virtual bool canTranslate() const { return getSpecialMove()->canTranslate(); }
142  virtual bool canRotate() const { return getSpecialMove()->canRotate(); }
143 
144  virtual void perform();
145 
146  inline const SpecialMove* getSpecialMove() const {
147  assert(_params.size() > 0);
148  return g_specialMoves[static_cast<SPECIAL_MOVE>(_params[0].getInt())];
149  }
150 
151  inline const AttackRange* getAttackRange() const {
152  assert(_params.size() > 1);
153  return static_cast<const AttackRange*>(_params[1].getConstPointer());
154  }
155 
156  inline std::vector<Warrior*> getDefenders() const {
157  assert(_params.size() > 2);
158  std::vector<Warrior*> defenders;
159  int numDefenders = _params[2].getInt();
160  assert(numDefenders > -1);
161  assert(static_cast<OpenSkyNet::Utils::uint>(numDefenders) <= MAX_DEFENDERS);
162  defenders.reserve(numDefenders);
163 
164  std::size_t indexAfterLastDefender = numDefenders + 3;
165  assert(_params.size() >= indexAfterLastDefender);
166  for (std::size_t i = 3; i < indexAfterLastDefender; ++i)
167  defenders.push_back(static_cast<Warrior*>(_params[i].getPointer()));
168 
169  return defenders;
170  }
171 
172  inline std::vector<OpenSkyNet::Utils::TaggedUnion> getSpecialMoveParams() const {
173  assert(_params.size() > 3);
174  std::vector<OpenSkyNet::Utils::TaggedUnion> specialMoveParams;
175 
176  int numDefenders = _params[2].getInt();
177  int numSpecialMoveParams = _params[numDefenders + 3].getInt();
178 
179  if (numSpecialMoveParams) {
180  int firstSpecialMoveParam = numDefenders + 3 + 1;
181  int indexAfterLastSpecialMoveParam = firstSpecialMoveParam + numSpecialMoveParams;
182  specialMoveParams.reserve(numSpecialMoveParams);
183  for (int i = firstSpecialMoveParam; i < indexAfterLastSpecialMoveParam; ++i)
184  specialMoveParams.push_back(_params[i]);
185  }
186 
187  return specialMoveParams;
188  }
189  };
190 
191  struct SuperPowerAction : public Action {
193 
194  SuperPowerAction(Warrior* performer_, SUPER_POWER superPower_, SuperPower::Warriors& targets_, SuperPower::Params& superPowerParams_);
195 
196  virtual void getPrePerformInfo(char* buffer_, int bufferLen_) const { getSuperPower()->getPrePerformInfo(buffer_, bufferLen_); }
197  virtual void getAnimationName(char* buffer_, int bufferLen_) const { getSuperPower()->getAnimationName(buffer_, bufferLen_); }
198  static void getPlayerInfo(char* buffer_, int bufferLen_);
199 
200  virtual bool canMoveInSameRound() const { return getSuperPower()->canMoveInSameRound(); }
201  virtual bool canTranslate() const { return getSuperPower()->canTranslate(); }
202  virtual bool canRotate() const { return getSuperPower()->canRotate(); }
203 
204  virtual void perform();
205 
206  inline const SuperPower* getSuperPower() const {
207  assert(_params.size() > 0);
208  return g_superPowers[static_cast<SUPER_POWER>(_params[0].getInt())];
209  }
210 
212  assert(_params.size() > 1);
213  SuperPower::Warriors targets;
214  int numTargets = _params[1].getInt();
215  assert(numTargets > -1);
216  assert(static_cast<OpenSkyNet::Utils::uint>(numTargets) <= MAX_TARGETS);
217  targets.reserve(numTargets);
218 
219  std::size_t indexAfterLastTarget = numTargets + 2;
220  assert(_params.size() >= indexAfterLastTarget);
221  for (std::size_t i = 2; i < indexAfterLastTarget; ++i)
222  targets.push_back(static_cast<Warrior*>(_params[i].getPointer()));
223 
224  return targets;
225  }
226 
228  assert(_params.size() > 2);
229  SuperPower::Params superPowerParams;
230 
231  int numTargets = _params[1].getInt();
232  int numSuperPowerParams = _params[numTargets + 2].getInt();
233 
234  if (numSuperPowerParams) {
235  int firstSuperPowerParam = numTargets + 2 + 1;
236  int indexAfterLastSuperPowerParam = firstSuperPowerParam + numSuperPowerParams;
237  superPowerParams.reserve(numSuperPowerParams);
238  for (int i = firstSuperPowerParam; i < indexAfterLastSuperPowerParam; ++i)
239  superPowerParams.push_back(_params[i]);
240  }
241 
242  return superPowerParams;
243  }
244  };
245 }
246 
247 #endif //TACTICS3DACTION_H
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.cpp:49
virtual bool canRotate() const
Definition: Tactics3DFightingStyle.h:105
virtual void perform()
Definition: Tactics3DAction.cpp:132
SPECIAL_MOVE
Definition: Tactics3DFightingStyle.h:37
virtual void getPrePerformInfo(char *buffer_, int bufferLen_) const
Definition: Tactics3DFightingStyle.h:100
virtual void perform()
Definition: Tactics3DAction.cpp:32
const ACTION_TYPE _type
Definition: Tactics3DAction.h:44
Definition: Tactics3DAction.h:40
BreakGrappleAction()
Definition: Tactics3DAction.h:96
Definition: Tactics3DAction.h:38
virtual bool canTranslate() const
Definition: Tactics3DFightingStyle.h:104
RepairThrustersAction()
Definition: Tactics3DAction.h:88
Definition: Tactics3DAction.h:191
virtual void getAnimationName(char *buffer_, int bufferLen_) const
Definition: Tactics3DSuperPower.h:62
static const OpenSkyNet::Utils::uint MAX_TARGETS
Definition: Tactics3DAction.h:192
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.cpp:83
Definition: Tactics3DAction.h:103
std::vector< Warrior * > getDefenders() const
Definition: Tactics3DAction.h:156
virtual bool canRotate() const
Definition: Tactics3DAction.h:82
SuperPowerAction(Warrior *performer_, SUPER_POWER superPower_, SuperPower::Warriors &targets_, SuperPower::Params &superPowerParams_)
Definition: Tactics3DAction.cpp:108
virtual void perform()
Definition: Tactics3DAction.h:63
Definition: Tactics3DAction.h:95
virtual bool canRotate() const
Definition: Tactics3DAction.h:142
Definition: Tactics3DAction.h:38
virtual bool canRotate() const
Definition: Tactics3DAction.h:61
virtual void getPrePerformInfo(char *buffer_, int bufferLen_) const
Definition: Tactics3DSuperPower.h:61
Definition: Tactics3DSuperPower.h:37
std::vector< OpenSkyNet::Utils::TaggedUnion > getSpecialMoveParams() const
Definition: Tactics3DAction.h:172
virtual ~Action()
Definition: Tactics3DAction.h:53
std::vector< OpenSkyNet::Utils::TaggedUnion > _params
Definition: Tactics3DAction.h:48
std::string _name
Definition: Tactics3DAction.h:43
Definition: Tactics3DWarrior.h:42
SuperPower::Warriors getTargets() const
Definition: Tactics3DAction.h:211
virtual bool canTranslate() const
Definition: Tactics3DSuperPower.h:65
std::vector< Warrior * > Warriors
Definition: Tactics3DSuperPower.h:43
virtual bool canRotate() const
Definition: Tactics3DAction.h:202
Definition: Tactics3DAction.h:129
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.cpp:25
Definition: Tactics3DAction.h:38
virtual void getPrePerformInfo(char *buffer_, int bufferLen_) const
Definition: Tactics3DAction.h:196
Definition: Tactics3DAction.h:87
virtual bool canMoveInSameRound() const
Definition: Tactics3DSuperPower.h:64
virtual bool canMoveInSameRound() const
Definition: Tactics3DFightingStyle.h:103
MoveAction()
Definition: Tactics3DAction.h:77
SuperPower::Params getSuperPowerParams() const
Definition: Tactics3DAction.h:227
virtual bool canTranslate() const
Definition: Tactics3DAction.h:60
virtual bool canMoveInSameRound() const
Definition: Tactics3DAction.h:59
static const OpenSkyNet::Utils::uint MAX_PARAMS
Definition: Tactics3DAction.h:41
bool _isAuto
Definition: Tactics3DAction.h:45
virtual void perform()
Definition: Tactics3DAction.cpp:21
virtual bool canRotate() const
Definition: Tactics3DSuperPower.h:66
virtual void getAnimationName(char *buffer_, int bufferLen_) const
Definition: Tactics3DAction.h:56
Definition: Tactics3DAction.h:38
virtual void getPrePerformInfo(char *buffer_, int bufferLen_) const
Definition: Tactics3DAction.h:136
NoPAction()
Definition: Tactics3DAction.h:67
std::map< SUPER_POWER, const SuperPower * > g_superPowers
Definition: Tactics3DSuperPower.cpp:18
Definition: Tactics3DAction.h:76
Tactics3D::Warrior * _performer
Definition: Tactics3DAction.h:47
ACTION_TYPE
Definition: Tactics3DAction.h:38
Definition: Tactics3DAction.h:70
Definition: Tactics3DAttackRange.h:33
const AttackRange * getAttackRange() const
Definition: Tactics3DAction.h:151
virtual void perform()
Definition: Tactics3DAction.cpp:55
virtual void perform()
Definition: Tactics3DAction.cpp:44
virtual void perform()
Definition: Tactics3DAction.cpp:89
virtual void getAnimationName(char *buffer_, int bufferLen_) const
Definition: Tactics3DFightingStyle.h:101
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.cpp:15
unsigned int uint
Definition: UTypes.h:39
Warrior * getDefender() const
Definition: Tactics3DAction.h:118
SUPER_POWER
Definition: Tactics3DSuperPower.h:35
Action(const std::string &name_="NO_ACTION", ACTION_TYPE type_=NO_ACTION, bool isAuto_=true)
Definition: Tactics3DAction.h:50
AttackAction(Warrior *performer_, const AttackRange *attackRange_, Warrior *defender_)
Definition: Tactics3DAction.h:106
Definition: Tactics3DAction.h:38
Definition: Tactics3DAction.h:38
virtual void getAnimationName(char *buffer_, int bufferLen_) const
Definition: Tactics3DAction.h:137
bool _isContinuous
Definition: Tactics3DAction.h:46
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.cpp:126
const SuperPower * getSuperPower() const
Definition: Tactics3DAction.h:206
virtual void getPrePerformInfo(char *buffer_, int bufferLen_) const
Definition: Tactics3DAction.h:55
std::vector< OpenSkyNet::Utils::TaggedUnion > Params
Definition: Tactics3DSuperPower.h:44
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.cpp:9
Definition: Tactics3DAction.h:38
SpecialMoveAction(Warrior *performer_, SPECIAL_MOVE specialMove_, const AttackRange *attackRange_, std::vector< Warrior * > defenders_, std::vector< OpenSkyNet::Utils::TaggedUnion > &specialMoveParams_)
Definition: Tactics3DAction.cpp:64
AttackAction()
Definition: Tactics3DAction.h:104
const SpecialMove * getSpecialMove() const
Definition: Tactics3DAction.h:146
virtual bool canMoveInSameRound() const
Definition: Tactics3DAction.h:200
Definition: Tactics3DAction.h:38
DelayAction()
Definition: Tactics3DAction.h:71
virtual bool canTranslate() const
Definition: Tactics3DAction.h:201
virtual bool canMoveInSameRound() const
Definition: Tactics3DAction.h:140
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.cpp:36
const AttackRange * getAttackRange() const
Definition: Tactics3DAction.h:113
static void getPlayerInfo(char *buffer_, int bufferLen_)
Definition: Tactics3DAction.h:57
virtual bool canTranslate() const
Definition: Tactics3DAction.h:141
static const OpenSkyNet::Utils::uint MAX_DEFENDERS
Definition: Tactics3DAction.h:130
virtual void getAnimationName(char *buffer_, int bufferLen_) const
Definition: Tactics3DAction.h:197
virtual void getAnimationName(char *buffer_, int bufferLen_) const
Definition: Tactics3DAction.h:123
Definition: Tactics3DFightingStyle.h:61
virtual bool canTranslate() const
Definition: Tactics3DAction.h:81
Definition: Tactics3DAction.h:38
Definition: Tactics3DAction.h:66
std::map< SPECIAL_MOVE, const SpecialMove * > g_specialMoves
Definition: Tactics3DFightingStyle.cpp:283