activeobject.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 <string>
  19. enum ActiveObjectType {
  20. ACTIVEOBJECT_TYPE_INVALID = 0,
  21. ACTIVEOBJECT_TYPE_TEST = 1,
  22. // Deprecated stuff
  23. ACTIVEOBJECT_TYPE_ITEM = 2,
  24. // ACTIVEOBJECT_TYPE_RAT = 3,
  25. // ACTIVEOBJECT_TYPE_OERKKI1 = 4,
  26. // ACTIVEOBJECT_TYPE_FIREFLY = 5,
  27. ACTIVEOBJECT_TYPE_MOBV2 = 6,
  28. // End deprecated stuff
  29. ACTIVEOBJECT_TYPE_LUAENTITY = 7,
  30. // Special type, not stored as a static object
  31. ACTIVEOBJECT_TYPE_PLAYER = 100,
  32. // Special type, only exists as CAO
  33. ACTIVEOBJECT_TYPE_GENERIC = 101,
  34. };
  35. // Other types are defined in content_object.h
  36. struct ActiveObjectMessage
  37. {
  38. ActiveObjectMessage(u16 id_, bool reliable_=true, const std::string &data_ = "") :
  39. id(id_),
  40. reliable(reliable_),
  41. datastring(data_)
  42. {}
  43. u16 id;
  44. bool reliable;
  45. std::string datastring;
  46. };
  47. /*
  48. Parent class for ServerActiveObject and ClientActiveObject
  49. */
  50. class ActiveObject
  51. {
  52. public:
  53. ActiveObject(u16 id):
  54. m_id(id)
  55. {
  56. }
  57. u16 getId() const
  58. {
  59. return m_id;
  60. }
  61. void setId(u16 id)
  62. {
  63. m_id = id;
  64. }
  65. virtual ActiveObjectType getType() const = 0;
  66. /*!
  67. * Returns the collision box of the object.
  68. * This box is translated by the object's
  69. * location.
  70. * The box's coordinates are world coordinates.
  71. * @returns true if the object has a collision box.
  72. */
  73. virtual bool getCollisionBox(aabb3f *toset) const = 0;
  74. /*!
  75. * Returns the selection box of the object.
  76. * This box is not translated when the
  77. * object moves.
  78. * The box's coordinates are world coordinates.
  79. * @returns true if the object has a selection box.
  80. */
  81. virtual bool getSelectionBox(aabb3f *toset) const = 0;
  82. virtual bool collideWithObjects() const = 0;
  83. protected:
  84. u16 m_id; // 0 is invalid, "no id"
  85. };