Path_ScriptBinding.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2013 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. /*! Attaches a sceneObject to the path.
  23. @param SceneObject The object that will be attached to the path.
  24. @param speed The rate that the sceneObject will follow the path.
  25. @param orient If true, the object will automatically rate to face the direction that it is moving.
  26. @param angOff The offset that will be applied to the rotation if orient is true.
  27. @param snapToNode If true, the object will have to get close to a node instead of reaching it exactly. The distance is based on the distance given a node when it is created.
  28. @param startNode A zero-based integer that represents the node that the object should start at.
  29. @param loop If true, the object will start the path again when it reaches the last node. The object will travel from the last node to the first.
  30. @param maxLoop An integer value describing the number of times the object will travel the path if looping is turned on.
  31. @return No return value.
  32. */
  33. ConsoleMethodWithDocs(Path, attachObject, ConsoleVoid, 4, 11, (sceneObject, float speed,[float force], [bool orient], [float angOff], [bool snapToNode],[integer startNode],[bool loop],[integer maxLoop]))
  34. {
  35. // Set Group.
  36. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
  37. // Did we find the object?
  38. if (!pSceneObject)
  39. {
  40. // No, so warn.
  41. Con::warnf("Path::attachObject() - Could not find the specified object '%s'.", argv[2]);
  42. return;
  43. }
  44. F32 speed = dAtof(argv[3]);
  45. F32 force = 3.0f;
  46. if (argc > 4)
  47. {
  48. force = dAtof(argv[4]);
  49. }
  50. bool orient = false;
  51. if (argc > 5)
  52. {
  53. orient = dAtob(argv[5]);
  54. }
  55. F32 angleOff = 0.0f;
  56. if (argc > 6)
  57. {
  58. angleOff = dAtof(argv[6]);
  59. }
  60. bool snapToNode = false;
  61. if (argc > 7)
  62. {
  63. snapToNode = dAtob(argv[7]);
  64. }
  65. S32 startNode = 0;
  66. if (argc > 8)
  67. {
  68. startNode = dAtoi(argv[8]);
  69. }
  70. bool loop = true;
  71. if (argc > 9)
  72. {
  73. loop = dAtob(argv[9]);
  74. }
  75. S32 maxLoop = 0;
  76. if (argc > 10)
  77. {
  78. maxLoop = dAtoi(argv[10]);
  79. }
  80. object->attachObject(pSceneObject, speed, force, orient, angleOff, snapToNode, startNode, loop, maxLoop);
  81. }
  82. /*! Removes a sceneObject from a path.
  83. @param SceneObject The object that will be detached from the path.
  84. @return No return value.
  85. */
  86. ConsoleMethodWithDocs(Path, detachObject, ConsoleVoid, 3, 3, (sceneObject))
  87. {
  88. // Set Group.
  89. SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
  90. if (pSceneObject)
  91. object->detachObject(pSceneObject);
  92. else
  93. Con::warnf("Path::detachObject() - Could not find the specified object '%s'.", argv[2]);
  94. }
  95. /*! Adds a node to a path.
  96. @param x The horizontal position of the node in world units.
  97. @param y The vertical position of the node in world units.
  98. @param distance The distance a from a node that it object must reach before it is considered to have reached the node, if snapToNode is set true for the object.
  99. @return No return value.
  100. */
  101. ConsoleMethodWithDocs(Path, addNode, ConsoleVoid, 3, 6, (float x, float y, [float distance], [float weight]))
  102. {
  103. Vector2 position;
  104. position.Set(dAtof(argv[2]), dAtof(argv[3]));
  105. F32 distance = 0.0f;
  106. if (argc > 4)
  107. {
  108. distance = dAtof(argv[4]);
  109. }
  110. F32 weight = 0.0f;
  111. if(argc > 5)
  112. {
  113. weight = dAtof(argv[5]);
  114. }
  115. object->addNode(position, distance, weight);
  116. }