Per-kind movement cost through a composable movement_cost() function #79
Labels
No labels
assets
bug
duplicate
enhancement
help wanted
invalid
question
testing
ui
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
liamjd/UntitledColonyBuilder#79
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of milestone #4. No dependencies.
Each terrain kind (sand, grass, snow) should cost a different amount to walk across, and A* should balance that cost against distance.
AStar2D.add_point()takes aweight_scalethat multiplies the cost of entering the point, and the graph is one point per tile, so per-tile cost is a one-line change at graph build time plus a test.The costs will need to flex later: presets may apply multipliers, and roads built on the terrain will lower the cost of specific cells. So the A* weight is never read from a table directly.
Design:
KIND_MOVE_COST: PackedFloat32Arrayconst onTerrainGridnext toKIND_COLORS, in enum order, base cost per kind. Water stays impassable viais_walkable(), not via a high cost.movement_cost(cell) -> float: the single function that composes the base kind cost with any modifiers. Today it returns the base cost. A preset multiplier or a road overlay changes this function and nothing else._build_navigation()passesmovement_cost(cell)asweight_scaleinadd_point().recost_cells(cells: Array[Vector2i]): callsAStar2D.set_point_weight_scale()for each cell, so a future road (or any modifier change) re-costs a handful of points without rebuilding the graph. Same argument #56 makes forremove_point()over a full rebuild. No caller yet; it exists so roads never reach into_astarfrom outside.path_cost(from, to) -> floator equivalent, so tests can assert on cost and not only on the route.AC:
test/unit/test_terrain_navigation.gd(shared with #56) using a realTerrainGridwith flat amplitude and hand-set levels: a path detours around a band of costly ground when the detour is short, and goes straight through it when the detour is long.recost_cells()changes the chosen route on the nextfind_path()withoutgenerate()being called.movement_cost()is the only reader ofKIND_MOVE_COST.