Knighttime
Prince
- Joined
- Sep 20, 2002
- Messages
- 380
More than a few scenario developers have probably wished there was a way to implement supply lines into a scenario, in an abstract way -- that is, without the micromanagement of moving dozens of supply train units across the map each turn. This concept is now possible and can be integrated into a TOT scenario using Lua events and TOTPP, and the attached module provides a working implementation.
This is a separate supplyLines.lua file that would be stored within a scenario directory and referenced from the scenario's main events.lua file. It allows the scenario designer to first customize the definition of a valid supply link -- that is, what criteria determine whether or not a supply line can pass through a given tile. Then you can customize the definition of a valid supply depot, from which supplies would originate to reach units in the field. The remainder of the code in the module contains the pathfinding logic that searches for a connection between the unit and depot that meets all of the criteria. Each time a unit is activated, the main events.lua file runs this module to immediately determine whether or not that unit is supplied.
As an aid to the designer, the module also contains a "review" feature that will highlight the shortest valid path connecting the active unit to the nearest valid supply depot. (If there are multiple paths of equal length, the first one found by the pathfinding logic is the one which will be highlighted.) If no such depot could be found, the highlighting can be used to reveal the area of the map from which the active unit *could* be supplied, if a depot was located there.
More details, including a working example, are available within the attachment. Here are a series of screen shots to illustrate the behavior:

In this first screen shot, the Warrior cannot be supplied from the city of Rome, because it is not a port city. (This example defined supply lines that are permitted to cross ocean tiles, but only to reach port cities -- they may not proceed further inland.) Therefore the closest depot is the city of Antium, so the supply line ignores Rome and connects Antium to the Warrior.

In this second screen shot, a barbarian Trireme has now blockaded the north side of the city of Antium, which was previously part of the supply line. However, the pathfinding logic determined that it is still possible for supplies from Antium to reach the Warrior, by a longer southern route.

In this third screen shot, another barbarian Trireme has now occupied a narrow channel that was previously part of the southern supply line to Antium. The pathfinding logic correctly identified that now Antium is no longer reachable at all, so the shortest valid supply line extends all the way to Cumae.

The Lua console, which provides information to the scenario designer, reveals the actions taken by the module in the above examples. As you can see, Lua is pretty quick! The pathfinding logic analyzed 1731 tiles in order to find the supply line between the Warrior and Cumae, which was 65 tiles long, and it did so in less than 1/10 of a second. It should be possible to support supply lines of just about any length, even on large maps, with no discernible lag in performance. However, it's very easy to configure a maximum supply line length, which may be more realistic for scenarios anyway. This would limit the number of tiles the module would need to analyze, and would also ensure that performance remains acceptable even on extremely large maps.
If this feature would be useful in a scenario you are designing, you're welcome to incorporate it and customize it as you wish. I'll do my best to answer any qustions you may have as you do so. Please let me know if you have any feedback, including requests for new features.
As with all Lua features for TOT, a big round of applause for TheNamelessOne who created TOTPP and made it possible for Lua events to interact with the game, at a level far surpassing what was possible with the original macro language.
Happy Civing!
This is a separate supplyLines.lua file that would be stored within a scenario directory and referenced from the scenario's main events.lua file. It allows the scenario designer to first customize the definition of a valid supply link -- that is, what criteria determine whether or not a supply line can pass through a given tile. Then you can customize the definition of a valid supply depot, from which supplies would originate to reach units in the field. The remainder of the code in the module contains the pathfinding logic that searches for a connection between the unit and depot that meets all of the criteria. Each time a unit is activated, the main events.lua file runs this module to immediately determine whether or not that unit is supplied.
As an aid to the designer, the module also contains a "review" feature that will highlight the shortest valid path connecting the active unit to the nearest valid supply depot. (If there are multiple paths of equal length, the first one found by the pathfinding logic is the one which will be highlighted.) If no such depot could be found, the highlighting can be used to reveal the area of the map from which the active unit *could* be supplied, if a depot was located there.
More details, including a working example, are available within the attachment. Here are a series of screen shots to illustrate the behavior:

In this first screen shot, the Warrior cannot be supplied from the city of Rome, because it is not a port city. (This example defined supply lines that are permitted to cross ocean tiles, but only to reach port cities -- they may not proceed further inland.) Therefore the closest depot is the city of Antium, so the supply line ignores Rome and connects Antium to the Warrior.

In this second screen shot, a barbarian Trireme has now blockaded the north side of the city of Antium, which was previously part of the supply line. However, the pathfinding logic determined that it is still possible for supplies from Antium to reach the Warrior, by a longer southern route.

In this third screen shot, another barbarian Trireme has now occupied a narrow channel that was previously part of the southern supply line to Antium. The pathfinding logic correctly identified that now Antium is no longer reachable at all, so the shortest valid supply line extends all the way to Cumae.

The Lua console, which provides information to the scenario designer, reveals the actions taken by the module in the above examples. As you can see, Lua is pretty quick! The pathfinding logic analyzed 1731 tiles in order to find the supply line between the Warrior and Cumae, which was 65 tiles long, and it did so in less than 1/10 of a second. It should be possible to support supply lines of just about any length, even on large maps, with no discernible lag in performance. However, it's very easy to configure a maximum supply line length, which may be more realistic for scenarios anyway. This would limit the number of tiles the module would need to analyze, and would also ensure that performance remains acceptable even on extremely large maps.
If this feature would be useful in a scenario you are designing, you're welcome to incorporate it and customize it as you wish. I'll do my best to answer any qustions you may have as you do so. Please let me know if you have any feedback, including requests for new features.
As with all Lua features for TOT, a big round of applause for TheNamelessOne who created TOTPP and made it possible for Lua events to interact with the game, at a level far surpassing what was possible with the original macro language.
Happy Civing!
Attachments
Last edited: