Forts
Not enough ratings
Destructible Terrain
By Ximsa
This guide will teach you how to create destructible terrain in the map editor. Experience with the commandline is recommended (Being able to navigate directories and execute programs/scripts is enough)
   
Award
Favorite
Favorited
Unfavorite
Preliminaries
To be able to make the terrain destructible you need a few things:
Creating a new map
To create a destructible map simply copy the demo map into your local Forts maps folder and adjust a few properties.
  • Navigate to the workshop folder of the "destructible terrain demo" map. It is located at
    [SteamLibrary]\steamapps\workshop\content\410900\2384295365
  • Copy that folder into the maps folder located at
    [SteamLibrary]\steamapps\common\Forts\data\maps
  • Rename that folder to "DestructibleTerrainDemo"
  • Open the folder and remove "itemversion.lua" and "publishedfileid.lua"
  • Edit "displayname.lua" with your favorite plain text editor (Notepad should suffice) and enter the name you want to give to your map.
You can now see your map in the Forts map editor. When you open it you will see that some blocks have names. You can set the name by selecting the block and running
\name_block "your name"
in the forts shell (F3).
Here's what those names do:
  • a non-numerical name (e.g.: "Wambo") makes the block indestructible
  • a unnamed block will be made destructible using the default settings (radius: 76, hitpoints: 32)
  • a single number name (e.g.: "50") makes the block desctructible with the size of destructible blocks set to a radius of 50
  • 2 number names (e.g.: "50 100") additionally allow for setting the hitpoints
Making the map destructible
Now you have marked which Terrain blocks you want to be destructible.
Here's a brief overview of the script files:
Filename
Purpose
2dTree.lua
Lua library which allows the creation and query of a k-d Tree[en.wikipedia.org] of dimensionality 2
coordsToTree.lua
Lua script that creates a k-d Tree from a list of blocks
destructible.py
Python script that transforms your map to become destructible
map_editor.py
Python library that allows for forts terrain editing
map_script.lua
a map script you want to paste in your [mapname].lua file
It is important to create a backup of your map.fwe file before running the scripts! It is not reversible elsewise.*

To make your map destructible you have to open a Terminal in that folder. In windows simply do
"File -> Open Command Prompt / Open Powershell". The script requires "matplotlib" and "shapely" to run. To install those dependencies simply run
pip3 install matplotlib shapely
Now run the actual script via
python3 destructible.py [mapname.fwe]
The script will now output it's progress and when finished show a rough plot on how your map will look like. If you're ok with the changes simply close the plot window and the file will be written. If you want to abort go back to the Terminal and hit Ctrl-c.
Now you should append the contents of "mapscript.lua" to your map.lua file. Having done that the python script also dumped a k-d Tree into "lua_coords.lua". Append the contents of that file to your map file too.

Gratulations - you made a destructible terrain map. You can test it in skirmish or local/private multiplayer

* well, there might still be something in your undo folder
13 Comments
kibi_the_robot 11 Jun, 2022 @ 9:56am 
i dont know why but demo map dont work :(
Void 4 Apr, 2022 @ 2:15pm 
I think something is screwed with my installation, using that reinstall command fixed something but also broke the thing that outputs coords to to lua_coords.lua, meaning i no longer see any numbers in that file, just empty brackets.
I'll come back to this in the future, maybe by then my python installation will be fixed while doing something else.
Thanks for the help!
Ximsa  [author] 4 Apr, 2022 @ 7:10am 
welp - i can't help with your python installation, this really is unusual. You can try
"python3 -m pip install matplotlib shapely --force-reinstall" but from there im out of ideas.

"side note ive been copying my map folder and renaming everything to create a separate test map to do this on"
- yeah, everytime the script finishes (successfully) it dumps the terrain data to lua_coords.lua - which contents you'll have to manually append to the end of the map lua file each time you run the script. (data.hitpoints and data.tree)
Void 2 Apr, 2022 @ 8:23pm 
im probably doing something wrong, as ive never touched python before, but when i run t he command import matplotlib.pyplot as plt it gives me the error "no such module "matplotlib" "
am i suppose to be doing this in a powershell window attached to the map folder or the python shell? (im running that command in the python shell)
side note ive been copying my map folder and renaming everything to create a separate test map to do this on
when i run pip3 uninstall matplotlib shapely in powershell attached to the folder it successfully uninstalls, and successfully reinstalls it with the install command
when i do that i get the same errors

-its probably some sort of user error as your test map wont work in skirmish/acts the same as my map in skirmish
Ximsa  [author] 1 Apr, 2022 @ 4:02pm 
you can also try to run a interactive python shell via "python3"
if you then type "import matplotlib.pyplot as plt" there shouldn't be any errors occuring.
after i.e.:
"plt.plot([1,2,3,4])"
and
"plt.show()"
you should see the plot of a diagonal
Ximsa  [author] 1 Apr, 2022 @ 3:57pm 
hmm, that's indeed strange (welcome to dependency hell btw) - you might want to reinstall matplot lib and shapely and also verify that the pip3 also is the same python version as your python3 command. for that do "pip3 uninstall matplotlib shapely". You can check the version using "pip3 --version" and "python --version"

ifor the latest issue i reccomend to restore the backup fwe file and rerun the script on it (if the script runs ;) )

as a last option just completely wipe python from your computer via the control panel and do a clean reinstall
Void 30 Mar, 2022 @ 2:31pm 
in addition projectiles are hitting collision boxes for the terrain where terrain isnt, where i fire a cannon the projectile hits a hitbox and vanishes out in the open not near terrain
Void 30 Mar, 2022 @ 2:30pm 
Scratch that, i just attempted to run the script again and its giving me "ModuleNotFoundError: No module named 'matplotlib'"
When i attempt to run the install command it gives me this, i have no clue if its an error or not
https://paste.ee/p/Irv3k
Void 30 Mar, 2022 @ 2:17pm 
I was testing it in sandbox, could be the reason your maps wouldnt work either, i'll give it a shot
In the console window i was getting a warning, but not an error and the warning was saying something about mismatching versions, but i dont think that could of been causing any problems