From da9a88a35a6a0705016bc37889541839157ff13a Mon Sep 17 00:00:00 2001
From: smix8 <52464204+smix8@users.noreply.github.com>
Date: Fri, 6 May 2022 02:33:31 +0200
Subject: [PATCH] Allow AStar/AStar2D zero point weight
Allow AStar/AStar2D zero point weight.
Limit was set to 1 which seemed like an arbitrary value as lower values down to zero can be useful for common gameplay navigation elements like teleports.
---
core/math/a_star.cpp | 4 ++--
doc/classes/AStar.xml | 2 +-
doc/classes/AStar2D.xml | 2 +-
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp
index de423c5de45..3e3a8cacab0 100644
--- a/core/math/a_star.cpp
+++ b/core/math/a_star.cpp
@@ -48,7 +48,7 @@ int AStar::get_available_point_id() const {
void AStar::add_point(int p_id, const Vector3 &p_pos, real_t p_weight_scale) {
ERR_FAIL_COND_MSG(p_id < 0, vformat("Can't add a point with negative id: %d.", p_id));
- ERR_FAIL_COND_MSG(p_weight_scale < 1, vformat("Can't add a point with weight scale less than one: %f.", p_weight_scale));
+ ERR_FAIL_COND_MSG(p_weight_scale < 0, vformat("Can't add a point with weight scale less than 0.0: %f.", p_weight_scale));
Point *found_pt;
bool p_exists = points.lookup(p_id, found_pt);
@@ -97,7 +97,7 @@ void AStar::set_point_weight_scale(int p_id, real_t p_weight_scale) {
Point *p;
bool p_exists = points.lookup(p_id, p);
ERR_FAIL_COND_MSG(!p_exists, vformat("Can't set point's weight scale. Point with id: %d doesn't exist.", p_id));
- ERR_FAIL_COND_MSG(p_weight_scale < 1, vformat("Can't set point's weight scale less than one: %f.", p_weight_scale));
+ ERR_FAIL_COND_MSG(p_weight_scale < 0, vformat("Can't set point's weight scale less than 0.0: %f.", p_weight_scale));
p->weight_scale = p_weight_scale;
}
diff --git a/doc/classes/AStar.xml b/doc/classes/AStar.xml
index fb6bb3192bb..fefa08c68dd 100644
--- a/doc/classes/AStar.xml
+++ b/doc/classes/AStar.xml
@@ -47,7 +47,7 @@
- Adds a new point at the given position with the given identifier. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 1 or larger.
+ Adds a new point at the given position with the given identifier. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 0.0 or greater.
The [code]weight_scale[/code] is multiplied by the result of [method _compute_cost] when determining the overall cost of traveling across a segment from a neighboring point to this point. Thus, all else being equal, the algorithm prefers points with lower [code]weight_scale[/code]s to form a path.
[codeblock]
var astar = AStar.new()
diff --git a/doc/classes/AStar2D.xml b/doc/classes/AStar2D.xml
index 6c2d0dd6353..a54a13d23ad 100644
--- a/doc/classes/AStar2D.xml
+++ b/doc/classes/AStar2D.xml
@@ -33,7 +33,7 @@
- Adds a new point at the given position with the given identifier. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 1 or larger.
+ Adds a new point at the given position with the given identifier. The [code]id[/code] must be 0 or larger, and the [code]weight_scale[/code] must be 0.0 or greater.
The [code]weight_scale[/code] is multiplied by the result of [method _compute_cost] when determining the overall cost of traveling across a segment from a neighboring point to this point. Thus, all else being equal, the algorithm prefers points with lower [code]weight_scale[/code]s to form a path.
[codeblock]
var astar = AStar2D.new()