activeobject.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU Lesser General Public License as published by
  6. the Free Software Foundation; either version 2.1 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public License along
  13. with this program; if not, write to the Free Software Foundation, Inc.,
  14. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  15. */
  16. #pragma once
  17. #include "irr_aabb3d.h"
  18. #include "irr_v3d.h"
  19. #include <string>
  20. enum ActiveObjectType {
  21. ACTIVEOBJECT_TYPE_INVALID = 0,
  22. ACTIVEOBJECT_TYPE_TEST = 1,
  23. // Obsolete stuff
  24. // ACTIVEOBJECT_TYPE_ITEM = 2,
  25. // ACTIVEOBJECT_TYPE_RAT = 3,
  26. // ACTIVEOBJECT_TYPE_OERKKI1 = 4,
  27. // ACTIVEOBJECT_TYPE_FIREFLY = 5,
  28. // ACTIVEOBJECT_TYPE_MOBV2 = 6,
  29. // End obsolete stuff
  30. ACTIVEOBJECT_TYPE_LUAENTITY = 7,
  31. // Special type, not stored as a static object
  32. ACTIVEOBJECT_TYPE_PLAYER = 100,
  33. // Special type, only exists as CAO
  34. ACTIVEOBJECT_TYPE_GENERIC = 101,
  35. };
  36. // Other types are defined in content_object.h
  37. struct ActiveObjectMessage
  38. {
  39. ActiveObjectMessage(u16 id_, bool reliable_=true, const std::string &data_ = "") :
  40. id(id_),
  41. reliable(reliable_),
  42. datastring(data_)
  43. {}
  44. u16 id;
  45. bool reliable;
  46. std::string datastring;
  47. };
  48. enum ActiveObjectCommand {
  49. AO_CMD_SET_PROPERTIES,
  50. AO_CMD_UPDATE_POSITION,
  51. AO_CMD_SET_TEXTURE_MOD,
  52. AO_CMD_SET_SPRITE,
  53. AO_CMD_PUNCHED,
  54. AO_CMD_UPDATE_ARMOR_GROUPS,
  55. AO_CMD_SET_ANIMATION,
  56. AO_CMD_SET_BONE_POSITION,
  57. AO_CMD_ATTACH_TO,
  58. AO_CMD_SET_PHYSICS_OVERRIDE,
  59. AO_CMD_OBSOLETE1,
  60. // ^ UPDATE_NAMETAG_ATTRIBUTES deprecated since 0.4.14, removed in 5.3.0
  61. AO_CMD_SPAWN_INFANT,
  62. AO_CMD_SET_ANIMATION_SPEED
  63. };
  64. /*
  65. Parent class for ServerActiveObject and ClientActiveObject
  66. */
  67. class ActiveObject
  68. {
  69. public:
  70. ActiveObject(u16 id):
  71. m_id(id)
  72. {
  73. }
  74. u16 getId() const
  75. {
  76. return m_id;
  77. }
  78. void setId(u16 id)
  79. {
  80. m_id = id;
  81. }
  82. virtual ActiveObjectType getType() const = 0;
  83. /*!
  84. * Returns the collision box of the object.
  85. * This box is translated by the object's
  86. * location.
  87. * The box's coordinates are world coordinates.
  88. * @returns true if the object has a collision box.
  89. */
  90. virtual bool getCollisionBox(aabb3f *toset) const = 0;
  91. /*!
  92. * Returns the selection box of the object.
  93. * This box is not translated when the
  94. * object moves.
  95. * The box's coordinates are world coordinates.
  96. * @returns true if the object has a selection box.
  97. */
  98. virtual bool getSelectionBox(aabb3f *toset) const = 0;
  99. virtual bool collideWithObjects() const = 0;
  100. virtual void setAttachment(int parent_id, const std::string &bone, v3f position,
  101. v3f rotation, bool force_visible) {}
  102. virtual void getAttachment(int *parent_id, std::string *bone, v3f *position,
  103. v3f *rotation, bool *force_visible) const {}
  104. virtual void clearChildAttachments() {}
  105. virtual void clearParentAttachment() {}
  106. virtual void addAttachmentChild(int child_id) {}
  107. virtual void removeAttachmentChild(int child_id) {}
  108. protected:
  109. u16 m_id; // 0 is invalid, "no id"
  110. };