Torque3D Documentation / _generateds / afxEA_Damage.cpp

afxEA_Damage.cpp

Engine/source/afx/ea/afxEA_Damage.cpp

More...

Classes:

Detailed Description

  1
  2
  3//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  4// Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  5// Copyright (C) 2015 Faust Logic, Inc.
  6//
  7// Permission is hereby granted, free of charge, to any person obtaining a copy
  8// of this software and associated documentation files (the "Software"), to
  9// deal in the Software without restriction, including without limitation the
 10// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 11// sell copies of the Software, and to permit persons to whom the Software is
 12// furnished to do so, subject to the following conditions:
 13//
 14// The above copyright notice and this permission notice shall be included in
 15// all copies or substantial portions of the Software.
 16//
 17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 23// IN THE SOFTWARE.
 24//
 25//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 26
 27#include <typeinfo>
 28#include "afx/arcaneFX.h"
 29#include "afx/afxEffectDefs.h"
 30#include "afx/afxEffectWrapper.h"
 31#include "afx/afxChoreographer.h"
 32#include "afx/ce/afxDamage.h"
 33
 34//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 35// afxEA_Damage 
 36
 37class afxEA_Damage : public afxEffectWrapper
 38{
 39  typedef afxEffectWrapper Parent;
 40
 41  afxDamageData*    damage_data;
 42  bool              started;
 43  U8                repeat_cnt;
 44  U32               dot_delta_ms;
 45  U32               next_dot_time;
 46  Point3F           impact_pos;
 47  SimObjectId       impacted_obj_id;
 48
 49  void              do_runtime_substitutions();
 50
 51public:
 52  /*C*/             afxEA_Damage();
 53  /*C*/             ~afxEA_Damage();
 54
 55  virtual bool      isDone();
 56
 57  virtual void      ea_set_datablock(SimDataBlock*);
 58  virtual bool      ea_start();
 59  virtual bool      ea_update(F32 dt);
 60  virtual void      ea_finish(bool was_stopped);
 61};
 62
 63//~~~~~~~~~~~~~~~~~~~~//
 64
 65afxEA_Damage::afxEA_Damage()
 66{
 67  damage_data = 0;
 68  started = false;
 69  repeat_cnt = 0;
 70  dot_delta_ms = 0; 
 71  next_dot_time = 0;
 72  impact_pos.zero();
 73  impacted_obj_id = 0;
 74}
 75
 76afxEA_Damage::~afxEA_Damage()
 77{
 78  if (damage_data && damage_data->isTempClone())
 79    delete damage_data;
 80  damage_data = 0;
 81}
 82
 83bool afxEA_Damage::isDone() 
 84{ 
 85  return (damage_data) ? (repeat_cnt >= damage_data->repeats) : true;
 86}
 87
 88void afxEA_Damage::ea_set_datablock(SimDataBlock* db)
 89{
 90  damage_data = dynamic_cast<afxDamageData*>(db);
 91}
 92
 93bool afxEA_Damage::ea_start()
 94{
 95  if (!damage_data)
 96  {
 97    Con::errorf("afxEA_Damage::ea_start() -- missing or incompatible datablock.");
 98    return false;
 99  }
100
101  do_runtime_substitutions();
102
103  if (damage_data->repeats > 1)
104  {
105    dot_delta_ms = mFull_lifetime /(damage_data->repeats - 1);
106    next_dot_time = dot_delta_ms;
107  }
108
109  return true;
110}
111
112bool afxEA_Damage::ea_update(F32 dt)
113{
114  if (!started)
115  {
116    started = true;
117
118    afxConstraint* pos_cons = getPosConstraint();
119    if (pos_cons)
120      pos_cons->getPosition(impact_pos);
121
122    afxConstraint* aim_cons = getAimConstraint();
123    if (aim_cons && aim_cons->getSceneObject())
124      impacted_obj_id = aim_cons->getSceneObject()->getId();
125
126    if (mChoreographer)
127      mChoreographer->inflictDamage(damage_data->label, damage_data->flavor, impacted_obj_id, damage_data->amount, 
128                                   repeat_cnt, damage_data->ad_amount, damage_data->radius, impact_pos, 
129                                   damage_data->impulse);
130    repeat_cnt++;
131  }
132  else if (repeat_cnt < damage_data->repeats)
133  {
134    if (next_dot_time <= mLife_elapsed)
135    {
136      // CONSTRAINT REMAPPING <<
137      afxConstraint* aim_cons = getAimConstraint();
138      if (aim_cons && aim_cons->getSceneObject())
139        impacted_obj_id = aim_cons->getSceneObject()->getId();
140      // CONSTRAINT REMAPPING >>
141
142      if (mChoreographer)
143        mChoreographer->inflictDamage(damage_data->label, damage_data->flavor, impacted_obj_id, damage_data->amount,
144                                     repeat_cnt, 0, 0, impact_pos, 0);
145      next_dot_time += dot_delta_ms;
146      repeat_cnt++;
147    }
148  }
149
150  return true;
151}
152
153void afxEA_Damage::ea_finish(bool was_stopped)
154{
155  if (started && (repeat_cnt < damage_data->repeats))
156  {
157    if (next_dot_time <= mLife_elapsed)
158    {
159      if (mChoreographer)
160        mChoreographer->inflictDamage(damage_data->label, damage_data->flavor, impacted_obj_id, damage_data->amount,
161                                     repeat_cnt, 0, 0, impact_pos, 0);
162    }
163  }
164
165  started = false;
166}
167
168void afxEA_Damage::do_runtime_substitutions()
169{
170  // only clone the datablock if there are substitutions
171  if (damage_data->getSubstitutionCount() > 0)
172  {
173    // clone the datablock and perform substitutions
174    afxDamageData* orig_db = damage_data;
175    damage_data = new afxDamageData(*orig_db, true);
176    orig_db->performSubstitutions(damage_data, mChoreographer, mGroup_index);
177  }
178}
179
180//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
181
182class afxEA_DamageDesc : public afxEffectAdapterDesc, public afxEffectDefs 
183{
184  static afxEA_DamageDesc desc;
185
186public:
187  virtual bool  testEffectType(const SimDataBlock*) const;
188  virtual bool  requiresStop(const afxEffectWrapperData*, const afxEffectTimingData&) const { return false; }
189  virtual bool  runsOnServer(const afxEffectWrapperData*) const { return true; }
190  virtual bool  runsOnClient(const afxEffectWrapperData*) const { return false; }
191
192  virtual afxEffectWrapper* create() const { return new afxEA_Damage; }
193};
194
195afxEA_DamageDesc afxEA_DamageDesc::desc;
196
197bool afxEA_DamageDesc::testEffectType(const SimDataBlock* db) const
198{
199  return (typeid(afxDamageData) == typeid(*db));
200}
201
202//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
203