Torque3D Documentation / _generateds / afxMachineGun.cpp

afxMachineGun.cpp

Engine/source/afx/ce/afxMachineGun.cpp

More...

Public Defines

define
myOffset(field) (field, )

Public Functions

ConsoleDocClass(afxMachineGunData , "@brief A datablock that specifies <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Machine Gun <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "Machine Gun is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> simple but useful effect <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> rapidly shooting standard Torque <a href="/coding/class/classprojectile/">Projectile</a> objects. For performance " " reasons, keep in mind that each bullet is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> separate <a href="/coding/class/classprojectile/">Projectile</a> object, which is not <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> very lightweight object." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

Detailed Description

Public Defines

myOffset(field) (field, )

Public Functions

ConsoleDocClass(afxMachineGunData , "@brief A datablock that specifies <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> Machine Gun <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">effect.\n\n</a>" "Machine Gun is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> simple but useful effect <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1a2732ab74fa0237854c2ba0f75f88a624">for</a> rapidly shooting standard Torque <a href="/coding/class/classprojectile/">Projectile</a> objects. For performance " " reasons, keep in mind that each bullet is <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> separate <a href="/coding/class/classprojectile/">Projectile</a> object, which is not <a href="/coding/file/pointer_8h/#pointer_8h_1aeeddce917cf130d62c370b8f216026dd">a</a> very lightweight object." "\<a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">n\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">afxEffects\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">AFX\n</a>" " @ingroup <a href="/coding/file/cmdscan_8cpp/#cmdscan_8cpp_1aeab71244afb687f16d8c4f5ee9d6ef0e">Datablocks\n</a>" )

IMPLEMENT_CO_DATABLOCK_V1(afxMachineGunData )

  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 "afx/arcaneFX.h"
 28
 29#include "console/consoleTypes.h"
 30#include "core/stream/bitStream.h"
 31#include "lighting/lightInfo.h"
 32#include "T3D/projectile.h"
 33
 34#include "afx/ce/afxMachineGun.h"
 35
 36//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
 37// afxMachineGunData
 38
 39IMPLEMENT_CO_DATABLOCK_V1(afxMachineGunData);
 40
 41ConsoleDocClass( afxMachineGunData,
 42   "@brief A datablock that specifies a Machine Gun effect.\n\n"
 43
 44   "Machine Gun is a simple but useful effect for rapidly shooting standard Torque Projectile objects. For performance "
 45   "reasons, keep in mind that each bullet is a separate Projectile object, which is not a very lightweight object."
 46   "\n\n"
 47
 48   "@ingroup afxEffects\n"
 49   "@ingroup AFX\n"
 50   "@ingroup Datablocks\n"
 51);
 52
 53afxMachineGunData::afxMachineGunData()
 54{
 55  projectile_data = 0;
 56  rounds_per_minute = 60;
 57}
 58
 59afxMachineGunData::afxMachineGunData(const afxMachineGunData& other, bool temp_clone) : GameBaseData(other, temp_clone)
 60{
 61  projectile_data = other.projectile_data;
 62  rounds_per_minute = other.rounds_per_minute;
 63}
 64
 65#define myOffset(field) Offset(field, afxMachineGunData)
 66
 67void afxMachineGunData::initPersistFields()
 68{
 69  addField("projectile", TYPEID<ProjectileData>(), myOffset(projectile_data),
 70    "A ProjectileData datablock describing the projectile to be launched.");
 71  addField("roundsPerMinute", TypeS32, myOffset(rounds_per_minute),
 72    "Specifies the number of projectiles fired over a minute of time. A value of 1200 "
 73    "will create 20 projectiles per second.\n"
 74    "Sample values for real machine guns:\n"
 75    "    AK-47 = 600, M16 = 750-900, UZI = 600");
 76
 77  Parent::initPersistFields();
 78
 79  // disallow some field substitutions
 80  disableFieldSubstitutions("projectile");
 81}
 82
 83bool afxMachineGunData::onAdd()
 84{
 85  if (Parent::onAdd() == false)
 86    return false;
 87
 88  if (projectile_data)
 89  { 
 90    if (getId() >= DataBlockObjectIdFirst && getId() <= DataBlockObjectIdLast)
 91    {
 92      SimObjectId pid = projectile_data->getId();
 93      if (pid < DataBlockObjectIdFirst || pid > DataBlockObjectIdLast)
 94      {
 95        Con::errorf(ConsoleLogEntry::General,"afxMachineGunData: bad ProjectileData datablock.");
 96        return false;
 97      }
 98    }
 99  }
100
101  return true;
102}
103
104void afxMachineGunData::packData(BitStream* stream)
105{
106   Parent::packData(stream);
107
108  if (stream->writeFlag(projectile_data))
109    stream->writeRangedU32(projectile_data->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast);
110
111  stream->write(rounds_per_minute);
112}
113
114void afxMachineGunData::unpackData(BitStream* stream)
115{
116  Parent::unpackData(stream);
117
118  if (stream->readFlag()) 
119  {
120    SimObjectId id = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
121    Sim::findObject(id, projectile_data);
122  }
123  
124  stream->read(&rounds_per_minute);
125}
126
127
128//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
129