[Ohrrpgce] Cost maps

Ralph Versteegen teeemcee at gmail.com
Thu Oct 11 16:56:19 PDT 2018


(Long train of thought leading to some conclusions, included only to
indicate my reasoning)

What our A* implementation is missing is some way to customise the cost of
moving to a tile. It's just a matter of deciding how to specify the costs.
Call that a "costmap". I was discussing this with kylekrack, who wanted to
use them.

I would like to have the ability to have multiple costmaps - that's quite
important for tactical games, and for flying/swimming NPCs or vehicles.
We don't necessarily need to support an unlimited number - e.g. 3 would
probably be enough for almost anyone.

If we had multidimensional arrays in HS, clearly we should have a way to
pass a 2D array of costs to a pathfinding function, but that doesn't cover
pathfinding for normal movement by NPCs unless you're going to script it.
(For efficiency it would be best if these were "typed arrays", like FB
arrays, numpy ndarrays or javascript typed arrays - meaning they can only
store numbers, not objects. We would want these anyway, for accessing
tilemaps/passmaps/etc and sprite pixels.)

An obvious way to specify costs would be zones... but you would need a
different zone for each different cost value, and how do you support
multiple costmaps? Lower zone IDs override higher ones? Plus reading zones
is relatively slow, especially if you need to check every zone on a tile;
it would probably slow down pathing a lot unless caching is used and the
cache isn't recreated every tick.

Another obvious solution is to use a tilemap. But just using the tile IDs
as costs? Then they aren't tiles; this would be a costmap, basically the
same thing as a foemap, with a different purpose. With its own map editor
mode? You could use the Paint tool to set the same cost on each tile, but
that would be unnecessarily laborious. I can't see the need for a costmap
editor.

Assigning a cost to each tile in a tileset and using a tilemap to specify
costs is a more obvious and far easier to use solution.
But... which map layer to use? That has to be a setting somewhere. And how
to support multiple cost maps? You could use different map layers, but
that's going to be a problem if you want cavalry units and soldier units
which have different costs for the same terrain, hence they should inspect
the same map layer. Sounds like you'd want multiple cost lookup tables for
the same tileset.
And if you use a single map layer for costs, that places heavy constraints
on how you split your tiles across map layers.

Maybe this is silly, and there's little desire to have cost maps for normal
NPC or hero movement as they'll only be used for scripted movement?
What are the uses of costmaps for normal NPC/hero pathing movement? Having
the hero avoid walking on grass. Chase NPCs which follow something other
than the shortest path, for a puzzle...  There don't seem to be many.

Hence we can just add some script commands to read/write costmaps? Just
like reading/writing map layers - multiple costmaps can be treated the same
as multiple map layers. No "create costmap" and "delete costmap" commands,
only maybe "set number of costmaps".
And there's always the option to add an editing mode to the map editor for
costmaps later. Since cost maps and foe maps are practically the same, they
could even be merged.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.motherhamster.org/pipermail/ohrrpgce-motherhamster.org/attachments/20181012/09878d07/attachment.html>


More information about the Ohrrpgce mailing list