navigation_agent_2d.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*************************************************************************/
  2. /* navigation_agent_2d.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "navigation_agent_2d.h"
  31. #include "core/math/geometry_2d.h"
  32. #include "scene/resources/world_2d.h"
  33. #include "servers/navigation_server_2d.h"
  34. void NavigationAgent2D::_bind_methods() {
  35. ClassDB::bind_method(D_METHOD("get_rid"), &NavigationAgent2D::get_rid);
  36. ClassDB::bind_method(D_METHOD("set_avoidance_enabled", "enabled"), &NavigationAgent2D::set_avoidance_enabled);
  37. ClassDB::bind_method(D_METHOD("get_avoidance_enabled"), &NavigationAgent2D::get_avoidance_enabled);
  38. ClassDB::bind_method(D_METHOD("set_path_desired_distance", "desired_distance"), &NavigationAgent2D::set_path_desired_distance);
  39. ClassDB::bind_method(D_METHOD("get_path_desired_distance"), &NavigationAgent2D::get_path_desired_distance);
  40. ClassDB::bind_method(D_METHOD("set_target_desired_distance", "desired_distance"), &NavigationAgent2D::set_target_desired_distance);
  41. ClassDB::bind_method(D_METHOD("get_target_desired_distance"), &NavigationAgent2D::get_target_desired_distance);
  42. ClassDB::bind_method(D_METHOD("set_radius", "radius"), &NavigationAgent2D::set_radius);
  43. ClassDB::bind_method(D_METHOD("get_radius"), &NavigationAgent2D::get_radius);
  44. ClassDB::bind_method(D_METHOD("set_neighbor_distance", "neighbor_distance"), &NavigationAgent2D::set_neighbor_distance);
  45. ClassDB::bind_method(D_METHOD("get_neighbor_distance"), &NavigationAgent2D::get_neighbor_distance);
  46. ClassDB::bind_method(D_METHOD("set_max_neighbors", "max_neighbors"), &NavigationAgent2D::set_max_neighbors);
  47. ClassDB::bind_method(D_METHOD("get_max_neighbors"), &NavigationAgent2D::get_max_neighbors);
  48. ClassDB::bind_method(D_METHOD("set_time_horizon", "time_horizon"), &NavigationAgent2D::set_time_horizon);
  49. ClassDB::bind_method(D_METHOD("get_time_horizon"), &NavigationAgent2D::get_time_horizon);
  50. ClassDB::bind_method(D_METHOD("set_max_speed", "max_speed"), &NavigationAgent2D::set_max_speed);
  51. ClassDB::bind_method(D_METHOD("get_max_speed"), &NavigationAgent2D::get_max_speed);
  52. ClassDB::bind_method(D_METHOD("set_path_max_distance", "max_speed"), &NavigationAgent2D::set_path_max_distance);
  53. ClassDB::bind_method(D_METHOD("get_path_max_distance"), &NavigationAgent2D::get_path_max_distance);
  54. ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationAgent2D::set_navigation_layers);
  55. ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationAgent2D::get_navigation_layers);
  56. ClassDB::bind_method(D_METHOD("set_navigation_layer_value", "layer_number", "value"), &NavigationAgent2D::set_navigation_layer_value);
  57. ClassDB::bind_method(D_METHOD("get_navigation_layer_value", "layer_number"), &NavigationAgent2D::get_navigation_layer_value);
  58. ClassDB::bind_method(D_METHOD("set_navigation_map", "navigation_map"), &NavigationAgent2D::set_navigation_map);
  59. ClassDB::bind_method(D_METHOD("get_navigation_map"), &NavigationAgent2D::get_navigation_map);
  60. ClassDB::bind_method(D_METHOD("set_target_location", "location"), &NavigationAgent2D::set_target_location);
  61. ClassDB::bind_method(D_METHOD("get_target_location"), &NavigationAgent2D::get_target_location);
  62. ClassDB::bind_method(D_METHOD("get_next_location"), &NavigationAgent2D::get_next_location);
  63. ClassDB::bind_method(D_METHOD("distance_to_target"), &NavigationAgent2D::distance_to_target);
  64. ClassDB::bind_method(D_METHOD("set_velocity", "velocity"), &NavigationAgent2D::set_velocity);
  65. ClassDB::bind_method(D_METHOD("get_nav_path"), &NavigationAgent2D::get_nav_path);
  66. ClassDB::bind_method(D_METHOD("get_nav_path_index"), &NavigationAgent2D::get_nav_path_index);
  67. ClassDB::bind_method(D_METHOD("is_target_reached"), &NavigationAgent2D::is_target_reached);
  68. ClassDB::bind_method(D_METHOD("is_target_reachable"), &NavigationAgent2D::is_target_reachable);
  69. ClassDB::bind_method(D_METHOD("is_navigation_finished"), &NavigationAgent2D::is_navigation_finished);
  70. ClassDB::bind_method(D_METHOD("get_final_location"), &NavigationAgent2D::get_final_location);
  71. ClassDB::bind_method(D_METHOD("_avoidance_done", "new_velocity"), &NavigationAgent2D::_avoidance_done);
  72. ADD_GROUP("Pathfinding", "");
  73. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01,suffix:px"), "set_path_desired_distance", "get_path_desired_distance");
  74. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "target_desired_distance", PROPERTY_HINT_RANGE, "0.1,100,0.01,suffix:px"), "set_target_desired_distance", "get_target_desired_distance");
  75. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_max_distance", PROPERTY_HINT_RANGE, "10,100,1,suffix:px"), "set_path_max_distance", "get_path_max_distance");
  76. ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
  77. ADD_GROUP("Avoidance", "");
  78. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "avoidance_enabled"), "set_avoidance_enabled", "get_avoidance_enabled");
  79. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius", PROPERTY_HINT_RANGE, "0.1,500,0.01,suffix:px"), "set_radius", "get_radius");
  80. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "neighbor_distance", PROPERTY_HINT_RANGE, "0.1,100000,0.01,suffix:px"), "set_neighbor_distance", "get_neighbor_distance");
  81. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_neighbors", PROPERTY_HINT_RANGE, "1,10000,1"), "set_max_neighbors", "get_max_neighbors");
  82. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_horizon", PROPERTY_HINT_RANGE, "0.1,10000,0.01,suffix:s"), "set_time_horizon", "get_time_horizon");
  83. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_speed", PROPERTY_HINT_RANGE, "0.1,100000,0.01,suffix:px/s"), "set_max_speed", "get_max_speed");
  84. ADD_SIGNAL(MethodInfo("path_changed"));
  85. ADD_SIGNAL(MethodInfo("target_reached"));
  86. ADD_SIGNAL(MethodInfo("navigation_finished"));
  87. ADD_SIGNAL(MethodInfo("velocity_computed", PropertyInfo(Variant::VECTOR3, "safe_velocity")));
  88. }
  89. void NavigationAgent2D::_notification(int p_what) {
  90. switch (p_what) {
  91. case NOTIFICATION_POST_ENTER_TREE: {
  92. // need to use POST_ENTER_TREE cause with normal ENTER_TREE not all required Nodes are ready.
  93. // cannot use READY as ready does not get called if Node is readded to SceneTree
  94. set_agent_parent(get_parent());
  95. set_physics_process_internal(true);
  96. } break;
  97. case NOTIFICATION_PARENTED: {
  98. if (is_inside_tree() && (get_parent() != agent_parent)) {
  99. // only react to PARENTED notifications when already inside_tree and parent changed, e.g. users switch nodes around
  100. // PARENTED notification fires also when Node is added in scripts to a parent
  101. // this would spam transforms fails and world fails while Node is outside SceneTree
  102. // when node gets reparented when joining the tree POST_ENTER_TREE takes care of this
  103. set_agent_parent(get_parent());
  104. set_physics_process_internal(true);
  105. }
  106. } break;
  107. case NOTIFICATION_UNPARENTED: {
  108. // if agent has no parent no point in processing it until reparented
  109. set_agent_parent(nullptr);
  110. set_physics_process_internal(false);
  111. } break;
  112. case NOTIFICATION_PAUSED: {
  113. if (agent_parent && !agent_parent->can_process()) {
  114. map_before_pause = NavigationServer2D::get_singleton()->agent_get_map(get_rid());
  115. NavigationServer2D::get_singleton()->agent_set_map(get_rid(), RID());
  116. } else if (agent_parent && agent_parent->can_process() && !(map_before_pause == RID())) {
  117. NavigationServer2D::get_singleton()->agent_set_map(get_rid(), map_before_pause);
  118. map_before_pause = RID();
  119. }
  120. } break;
  121. case NOTIFICATION_UNPAUSED: {
  122. if (agent_parent && !agent_parent->can_process()) {
  123. map_before_pause = NavigationServer2D::get_singleton()->agent_get_map(get_rid());
  124. NavigationServer2D::get_singleton()->agent_set_map(get_rid(), RID());
  125. } else if (agent_parent && agent_parent->can_process() && !(map_before_pause == RID())) {
  126. NavigationServer2D::get_singleton()->agent_set_map(get_rid(), map_before_pause);
  127. map_before_pause = RID();
  128. }
  129. } break;
  130. case NOTIFICATION_EXIT_TREE: {
  131. agent_parent = nullptr;
  132. set_physics_process_internal(false);
  133. } break;
  134. case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
  135. if (agent_parent) {
  136. if (avoidance_enabled) {
  137. // agent_position on NavigationServer is avoidance only and has nothing to do with pathfinding
  138. // no point in flooding NavigationServer queue with agent position updates that get send to the void if avoidance is not used
  139. NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
  140. }
  141. _check_distance_to_target();
  142. }
  143. } break;
  144. }
  145. }
  146. NavigationAgent2D::NavigationAgent2D() {
  147. agent = NavigationServer2D::get_singleton()->agent_create();
  148. set_neighbor_distance(500.0);
  149. set_max_neighbors(10);
  150. set_time_horizon(20.0);
  151. set_radius(10.0);
  152. set_max_speed(200.0);
  153. }
  154. NavigationAgent2D::~NavigationAgent2D() {
  155. NavigationServer2D::get_singleton()->free(agent);
  156. agent = RID(); // Pointless
  157. }
  158. void NavigationAgent2D::set_avoidance_enabled(bool p_enabled) {
  159. avoidance_enabled = p_enabled;
  160. if (avoidance_enabled) {
  161. NavigationServer2D::get_singleton()->agent_set_callback(agent, this, "_avoidance_done");
  162. } else {
  163. NavigationServer2D::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done");
  164. }
  165. }
  166. bool NavigationAgent2D::get_avoidance_enabled() const {
  167. return avoidance_enabled;
  168. }
  169. void NavigationAgent2D::set_agent_parent(Node *p_agent_parent) {
  170. // remove agent from any avoidance map before changing parent or there will be leftovers on the RVO map
  171. NavigationServer2D::get_singleton()->agent_set_callback(agent, nullptr, "_avoidance_done");
  172. if (Object::cast_to<Node2D>(p_agent_parent) != nullptr) {
  173. // place agent on navigation map first or else the RVO agent callback creation fails silently later
  174. agent_parent = Object::cast_to<Node2D>(p_agent_parent);
  175. if (map_override.is_valid()) {
  176. NavigationServer2D::get_singleton()->agent_set_map(get_rid(), map_override);
  177. } else {
  178. NavigationServer2D::get_singleton()->agent_set_map(get_rid(), agent_parent->get_world_2d()->get_navigation_map());
  179. }
  180. // create new avoidance callback if enabled
  181. set_avoidance_enabled(avoidance_enabled);
  182. } else {
  183. agent_parent = nullptr;
  184. NavigationServer2D::get_singleton()->agent_set_map(get_rid(), RID());
  185. }
  186. }
  187. void NavigationAgent2D::set_navigation_layers(uint32_t p_navigation_layers) {
  188. bool navigation_layers_changed = navigation_layers != p_navigation_layers;
  189. navigation_layers = p_navigation_layers;
  190. if (navigation_layers_changed) {
  191. _request_repath();
  192. }
  193. }
  194. uint32_t NavigationAgent2D::get_navigation_layers() const {
  195. return navigation_layers;
  196. }
  197. void NavigationAgent2D::set_navigation_layer_value(int p_layer_number, bool p_value) {
  198. ERR_FAIL_COND_MSG(p_layer_number < 1, "Navigation layer number must be between 1 and 32 inclusive.");
  199. ERR_FAIL_COND_MSG(p_layer_number > 32, "Navigation layer number must be between 1 and 32 inclusive.");
  200. uint32_t _navigation_layers = get_navigation_layers();
  201. if (p_value) {
  202. _navigation_layers |= 1 << (p_layer_number - 1);
  203. } else {
  204. _navigation_layers &= ~(1 << (p_layer_number - 1));
  205. }
  206. set_navigation_layers(_navigation_layers);
  207. }
  208. bool NavigationAgent2D::get_navigation_layer_value(int p_layer_number) const {
  209. ERR_FAIL_COND_V_MSG(p_layer_number < 1, false, "Navigation layer number must be between 1 and 32 inclusive.");
  210. ERR_FAIL_COND_V_MSG(p_layer_number > 32, false, "Navigation layer number must be between 1 and 32 inclusive.");
  211. return get_navigation_layers() & (1 << (p_layer_number - 1));
  212. }
  213. void NavigationAgent2D::set_navigation_map(RID p_navigation_map) {
  214. map_override = p_navigation_map;
  215. NavigationServer2D::get_singleton()->agent_set_map(agent, map_override);
  216. _request_repath();
  217. }
  218. RID NavigationAgent2D::get_navigation_map() const {
  219. if (map_override.is_valid()) {
  220. return map_override;
  221. } else if (agent_parent != nullptr) {
  222. return agent_parent->get_world_2d()->get_navigation_map();
  223. }
  224. return RID();
  225. }
  226. void NavigationAgent2D::set_path_desired_distance(real_t p_dd) {
  227. path_desired_distance = p_dd;
  228. }
  229. void NavigationAgent2D::set_target_desired_distance(real_t p_dd) {
  230. target_desired_distance = p_dd;
  231. }
  232. void NavigationAgent2D::set_radius(real_t p_radius) {
  233. radius = p_radius;
  234. NavigationServer2D::get_singleton()->agent_set_radius(agent, radius);
  235. }
  236. void NavigationAgent2D::set_neighbor_distance(real_t p_distance) {
  237. neighbor_distance = p_distance;
  238. NavigationServer2D::get_singleton()->agent_set_neighbor_distance(agent, neighbor_distance);
  239. }
  240. void NavigationAgent2D::set_max_neighbors(int p_count) {
  241. max_neighbors = p_count;
  242. NavigationServer2D::get_singleton()->agent_set_max_neighbors(agent, max_neighbors);
  243. }
  244. void NavigationAgent2D::set_time_horizon(real_t p_time) {
  245. time_horizon = p_time;
  246. NavigationServer2D::get_singleton()->agent_set_time_horizon(agent, time_horizon);
  247. }
  248. void NavigationAgent2D::set_max_speed(real_t p_max_speed) {
  249. max_speed = p_max_speed;
  250. NavigationServer2D::get_singleton()->agent_set_max_speed(agent, max_speed);
  251. }
  252. void NavigationAgent2D::set_path_max_distance(real_t p_pmd) {
  253. path_max_distance = p_pmd;
  254. }
  255. real_t NavigationAgent2D::get_path_max_distance() {
  256. return path_max_distance;
  257. }
  258. void NavigationAgent2D::set_target_location(Vector2 p_location) {
  259. target_location = p_location;
  260. _request_repath();
  261. }
  262. Vector2 NavigationAgent2D::get_target_location() const {
  263. return target_location;
  264. }
  265. Vector2 NavigationAgent2D::get_next_location() {
  266. update_navigation();
  267. if (navigation_path.size() == 0) {
  268. ERR_FAIL_COND_V_MSG(agent_parent == nullptr, Vector2(), "The agent has no parent.");
  269. return agent_parent->get_global_position();
  270. } else {
  271. return navigation_path[nav_path_index];
  272. }
  273. }
  274. real_t NavigationAgent2D::distance_to_target() const {
  275. ERR_FAIL_COND_V_MSG(agent_parent == nullptr, 0.0, "The agent has no parent.");
  276. return agent_parent->get_global_position().distance_to(target_location);
  277. }
  278. bool NavigationAgent2D::is_target_reached() const {
  279. return target_reached;
  280. }
  281. bool NavigationAgent2D::is_target_reachable() {
  282. return target_desired_distance >= get_final_location().distance_to(target_location);
  283. }
  284. bool NavigationAgent2D::is_navigation_finished() {
  285. update_navigation();
  286. return navigation_finished;
  287. }
  288. Vector2 NavigationAgent2D::get_final_location() {
  289. update_navigation();
  290. if (navigation_path.size() == 0) {
  291. return Vector2();
  292. }
  293. return navigation_path[navigation_path.size() - 1];
  294. }
  295. void NavigationAgent2D::set_velocity(Vector2 p_velocity) {
  296. target_velocity = p_velocity;
  297. NavigationServer2D::get_singleton()->agent_set_target_velocity(agent, target_velocity);
  298. NavigationServer2D::get_singleton()->agent_set_velocity(agent, prev_safe_velocity);
  299. velocity_submitted = true;
  300. }
  301. void NavigationAgent2D::_avoidance_done(Vector3 p_new_velocity) {
  302. const Vector2 velocity = Vector2(p_new_velocity.x, p_new_velocity.z);
  303. prev_safe_velocity = velocity;
  304. if (!velocity_submitted) {
  305. target_velocity = Vector2();
  306. return;
  307. }
  308. velocity_submitted = false;
  309. emit_signal(SNAME("velocity_computed"), velocity);
  310. }
  311. TypedArray<String> NavigationAgent2D::get_configuration_warnings() const {
  312. TypedArray<String> warnings = Node::get_configuration_warnings();
  313. if (!Object::cast_to<Node2D>(get_parent())) {
  314. warnings.push_back(RTR("The NavigationAgent2D can be used only under a Node2D inheriting parent node."));
  315. }
  316. return warnings;
  317. }
  318. void NavigationAgent2D::update_navigation() {
  319. if (agent_parent == nullptr) {
  320. return;
  321. }
  322. if (!agent_parent->is_inside_tree()) {
  323. return;
  324. }
  325. if (update_frame_id == Engine::get_singleton()->get_physics_frames()) {
  326. return;
  327. }
  328. update_frame_id = Engine::get_singleton()->get_physics_frames();
  329. Vector2 o = agent_parent->get_global_position();
  330. bool reload_path = false;
  331. if (NavigationServer2D::get_singleton()->agent_is_map_changed(agent)) {
  332. reload_path = true;
  333. } else if (navigation_path.size() == 0) {
  334. reload_path = true;
  335. } else {
  336. // Check if too far from the navigation path
  337. if (nav_path_index > 0) {
  338. Vector2 segment[2];
  339. segment[0] = navigation_path[nav_path_index - 1];
  340. segment[1] = navigation_path[nav_path_index];
  341. Vector2 p = Geometry2D::get_closest_point_to_segment(o, segment);
  342. if (o.distance_to(p) >= path_max_distance) {
  343. // To faraway, reload path
  344. reload_path = true;
  345. }
  346. }
  347. }
  348. if (reload_path) {
  349. if (map_override.is_valid()) {
  350. navigation_path = NavigationServer2D::get_singleton()->map_get_path(map_override, o, target_location, true, navigation_layers);
  351. } else {
  352. navigation_path = NavigationServer2D::get_singleton()->map_get_path(agent_parent->get_world_2d()->get_navigation_map(), o, target_location, true, navigation_layers);
  353. }
  354. navigation_finished = false;
  355. nav_path_index = 0;
  356. emit_signal(SNAME("path_changed"));
  357. }
  358. if (navigation_path.size() == 0) {
  359. return;
  360. }
  361. // Check if we can advance the navigation path
  362. if (navigation_finished == false) {
  363. // Advances to the next far away location.
  364. while (o.distance_to(navigation_path[nav_path_index]) < path_desired_distance) {
  365. nav_path_index += 1;
  366. if (nav_path_index == navigation_path.size()) {
  367. _check_distance_to_target();
  368. nav_path_index -= 1;
  369. navigation_finished = true;
  370. emit_signal(SNAME("navigation_finished"));
  371. break;
  372. }
  373. }
  374. }
  375. }
  376. void NavigationAgent2D::_request_repath() {
  377. navigation_path.clear();
  378. target_reached = false;
  379. navigation_finished = false;
  380. update_frame_id = 0;
  381. }
  382. void NavigationAgent2D::_check_distance_to_target() {
  383. if (!target_reached) {
  384. if (distance_to_target() < target_desired_distance) {
  385. emit_signal(SNAME("target_reached"));
  386. target_reached = true;
  387. }
  388. }
  389. }