• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Is it possible to interact with the map and/or cpp pathing logic in Lua?

Akela

Active Member
Joined
Dec 14, 2020
Messages
42
Solutions
2
Reaction score
25
I'm (very) slowly starting up an AI project that will require controlling the movement of multiple monsters.
I'll need two things:
  1. My logic will need some understanding of a section of the map - possibly a large section. Certainly hundreds of tiles, perhaps a few thousand
  2. I'll be updating my navigation instructions to controlled creatures moderately frequently (perhaps once every 5 or 10 ticks) even if the creature doesn't interact with anything. I'd prefer to be able to send each creature to an intermediate location (a waypoint), then make a new plan when it gets there - unless one of them meets e.g. a player.
I don't know the options for either of those, so any input would be helpful.

1. The Map.
I'll need a model of the relevant part of the game map in my Lua code. Initially it will be just the 2-D surface. Later I'll probably want 3-D (underground levels), but I don't need to start there.

Storing the data is a question of scale rather than difficulty, so that's not currently an issue. Getting it efficiently in the first place might be a challenge though.
I can probably get it via manual input, or perhaps pull it from a map editor or a map definition file. In either case it's a fair amount of work, and more importantly, locked to a single map implementation.

I'd much prefer to get it dynamically via Lua API calls - assuming they exist. What I have in mind is to start by defining a large rectangle (effectively the tile coordinates of the four corners), step through them, and load my in-program simplified and limited version of the game map by querying tile properties.
This would only be necessary when the game is started or reloaded, so performance shouldn't matter. And once coded (or appropriated if it's already been done :) it could be adapted quickly to different maps.

So the map question is: is it possible for me to query a lot of tiles by stepping through their coordinates (or something similar) so I can make a private version? And if so,
  • What's the Lua call to see a tile's properties (including e.g. if there's something standing on it, like a monster)?
  • Where can I see a list of all the possible properties? Preferably one that's easy to understand - the XML files generally seem to be easier that the LUA tables.
2, Navigation
The logic for constrained pathing is fairly complicated. I definitely don't want to do it myself - especially because there's probably something in the C++ game engine already.

Assuming there's good pathing logic in place, can I use it to get information about the path it would use to move between two different tiles? Note that I'll be controlling multiple creatures simultaneously, and sometimes they'll be fairly close together. Some of the pathing decisions (like on a large flat space with no obstacles) won't be hard, but where there are obstacles and other creatures it won't be so easy.
I think interacting with an existing pathing component would save me a lot of effort: I'll know where I want my controlled monster's new "waypoint" to be, but I'd rather not work out myself. e.g. I'll need to know:
  • Can it get to the target location from where it is now?
  • Will it need to take a roundabout route (e.g. due to obstacles)?
  • ... and maybe more stuff - but those would be a good start.
The answers could be yes/no to the first, and the distance for the second. Even that much would save me a lot of code.

So the navigation question: is there a "pathing engine" in OT already, and if so:
  • Can I interact with it?
  • If I can. how?
/A
 
I've looked around for awhile, but I can't seem to find a source code that has it.

In my old TFS 0.3.7 server we had a Lua function called "doSteerCreature".
It was limited to about 5-6 squares, but with some looping and pre-designated waypoints in a table, you could essentially do what you're describing above, but in a limited fashion.

Maybe you can find it on your own.
It pre-dated 0.3.7 afaik, so maybe 0.3.6 or 0.3 might have had it as well.

Sorry that I couldn't be of more help.
 
Hi Xikini

Do you have the code for doSteerCreature()? It doesn't have to work on current versions - I just want to get a feel for what's possible.

FWIW I've started design work (core objects, ideas for the obvious issues, etc).

You're right about waypoints, paths, etc.

I'll need to analyze as much of the map as my group of creatures will "patrol", and use that to identify "easy areas" (like flat areas with no obstacles) where pathing will be easy, "problems" (like an impassible ridge that significantly influences the effective distance between two points), and areas with more or fewer obstacles.
An occasional isolated rock in a large flat area will be easy to handle, but e.g. a forest with only 50% navigable tiles will be a coding challenge.

Anyway the idea is to analyze the game map to identify useful accessible locations (lookout points), paths (possibly with some variation in the exact tiles traversed where there's extra open space), identify significant impassible objects, and "zones" that are of opposite sides of major obstacles (i.e. where geometric distance and movement distance differ by a lot), with pre-determined paths between zones. And waypoints are a part of anchoring it together.

It won't be easy to code, but from my perspective this is half of what I "signed on for". Even if it's a lot of work, or fails, the process will be interesting.
 
I'm going to try to contact a friend, and see if they still have the old server files.
If he does, I'll see if I can find the function for you.
 
Back
Top