afxMachineGun.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #include "afx/arcaneFX.h"
  25. #include "console/consoleTypes.h"
  26. #include "core/stream/bitStream.h"
  27. #include "lighting/lightInfo.h"
  28. #include "T3D/projectile.h"
  29. #include "afx/ce/afxMachineGun.h"
  30. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  31. // afxMachineGunData
  32. IMPLEMENT_CO_DATABLOCK_V1(afxMachineGunData);
  33. ConsoleDocClass( afxMachineGunData,
  34. "@brief A datablock that specifies a Machine Gun effect.\n\n"
  35. "Machine Gun is a simple but useful effect for rapidly shooting standard Torque Projectile objects. For performance "
  36. "reasons, keep in mind that each bullet is a separate Projectile object, which is not a very lightweight object."
  37. "\n\n"
  38. "@ingroup afxEffects\n"
  39. "@ingroup AFX\n"
  40. "@ingroup Datablocks\n"
  41. );
  42. afxMachineGunData::afxMachineGunData()
  43. {
  44. projectile_data = 0;
  45. rounds_per_minute = 60;
  46. }
  47. afxMachineGunData::afxMachineGunData(const afxMachineGunData& other, bool temp_clone) : GameBaseData(other, temp_clone)
  48. {
  49. projectile_data = other.projectile_data;
  50. rounds_per_minute = other.rounds_per_minute;
  51. }
  52. #define myOffset(field) Offset(field, afxMachineGunData)
  53. void afxMachineGunData::initPersistFields()
  54. {
  55. addField("projectile", TYPEID<ProjectileData>(), myOffset(projectile_data),
  56. "A ProjectileData datablock describing the projectile to be launched.");
  57. addField("roundsPerMinute", TypeS32, myOffset(rounds_per_minute),
  58. "Specifies the number of projectiles fired over a minute of time. A value of 1200 "
  59. "will create 20 projectiles per second.\n"
  60. "Sample values for real machine guns:\n"
  61. " AK-47 = 600, M16 = 750-900, UZI = 600");
  62. Parent::initPersistFields();
  63. // disallow some field substitutions
  64. disableFieldSubstitutions("projectile");
  65. }
  66. bool afxMachineGunData::onAdd()
  67. {
  68. if (Parent::onAdd() == false)
  69. return false;
  70. if (projectile_data)
  71. {
  72. if (getId() >= DataBlockObjectIdFirst && getId() <= DataBlockObjectIdLast)
  73. {
  74. SimObjectId pid = projectile_data->getId();
  75. if (pid < DataBlockObjectIdFirst || pid > DataBlockObjectIdLast)
  76. {
  77. Con::errorf(ConsoleLogEntry::General,"afxMachineGunData: bad ProjectileData datablock.");
  78. return false;
  79. }
  80. }
  81. }
  82. return true;
  83. }
  84. void afxMachineGunData::packData(BitStream* stream)
  85. {
  86. Parent::packData(stream);
  87. if (stream->writeFlag(projectile_data))
  88. stream->writeRangedU32(projectile_data->getId(), DataBlockObjectIdFirst, DataBlockObjectIdLast);
  89. stream->write(rounds_per_minute);
  90. }
  91. void afxMachineGunData::unpackData(BitStream* stream)
  92. {
  93. Parent::unpackData(stream);
  94. if (stream->readFlag())
  95. {
  96. SimObjectId id = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
  97. Sim::findObject(id, projectile_data);
  98. }
  99. stream->read(&rounds_per_minute);
  100. }
  101. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//