kaputtnik
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
One Elder of Players
Location: Germany
|
Posted at: 2023-12-02, 21:29
This topic can also be made in Coding and Scripting but since my new script is probably most important for map designers, i put it in this forum.
I am working on a map analysis tool which gathers some information about a map. The information it provides are:
- players, playernr and position
- buildings plots
- the amount of mineable resources
- the amount of rocks with correlation of how many granite or/and marble can be mined
- trees
Currently this script can only be used with debug builds, but it is planned to make it accessible via the UI as addon. But i want to ask if you think if this script is useful at all. So if you want to test it:
- be sure you have a debug build (minimum widelands version is 1.2, versions before July 2023 will not work)
- start the debug console by pressing SHIFT + CTRL(or STRG) + SPACE
- enter the full path to the script in debug console like
dofile("full/path/to/map_statistics.lua")
Then you have three possibilities:
- analyse a rectangle: A rectangle consists of two coordinates, the upper left corner and the bottom right corner of the rectangle. The coordinates can be taken from the menubar. Example: type
analyse_rect(0,20, 5,50) in the debug console. This will analyse a rectangle of the map where 0,20 defines the upper left corner and 5,50 defines the bottom right corner.
- analyse the whole map by omitting the coordinates: Just type
analyse_rect() , but be warned, depending on the size of the map this may last while.
- analyse a region of the map. A region is defined by a center field and a radius. This will analyse a hexagonal region (a hexagon like shown when using an editor tool with a big toolsize). Example:
analyse_region(0,20, 36) , here 0,20 are the coordinates of the center field and 36 the radius. You can use this for example to analyse a region of a starting field of a player.
Attached is the script. A screenshot will be attached to the next post.
Top
Quote
|
|
|
kaputtnik
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
One Elder of Players
Location: Germany
|
Posted at: 2023-12-02, 21:31
A screenshot for statistics of a whole map. The map was a 160x160 map and running analyse_rect() took some seconds.
Edited: 2023-12-02, 21:31
Attachment:
Top
Quote
|
|
|
kaputtnik
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
One Elder of Players
Location: Germany
|
Posted at: 2023-12-21, 17:04
I gave the script some more love and now it shows also the vicinity of a player: The player analysis shows which resources are nearby the players starting position (as defined in the map), which amount of this resource is available and how far away this resource deposit is.
I was also able to make it incredible fast and shrunk drastically the memory consumption. For comparison: If i ran this script on the map Europe 1.2 ( with a dimension of 512x512 the biggest map) and examining the whole map:
- An intermediate version needed round about 1Minute and 20 sec and ~10GB memory
- The new Version needs round about 7 sec and needs just ~1GB memory
For smaller maps this script runs without any noticeable delay. Attached a screenshot of the current state. For a comparison i made also a screenshot with the default widelands theme.
Attachment:
Top
Quote
|
|
|
kaputtnik
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
One Elder of Players
Location: Germany
|
Posted at: 2023-12-21, 17:14
Here is the updated version of the script.
Edit: The script contains currently some memory statements which prints the used memory to stdout (or the console). If you are interested you can compare the output and the corresponding places inside the script to get an impression of memory usage and which statement is clearing memory.
Edited: 2023-12-21, 17:24
Top
Quote
|
|
|
kaputtnik
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
One Elder of Players
Location: Germany
|
Posted at: 2023-12-21, 17:35
The table of "Players and their vicinity" and an explanation:
Player |
Start pos |
Nearby |
Amount |
Around Field |
Distance |
The players name as defined in the map |
The starting field of this player as defined in the map |
The Resource found next to this player. If a resource is not found within the half of the maps width or half of the maps height the algorithm stops searching. |
The amount of this resource. Calculated are 2 fields around the found resource |
The field this resource was found on |
The distance of this field to the players starting position. This distance is a linear distance and does not yet take into account if this resource is reachable by the player, e.g. is found on an island. |
The icons below the players table are self explaining, imho.
But a word about fish and water: The values below those icons represents the overall amount of those resources. That is the amount of resources set with the "place resource tool" plus the amount of default resources included in some terrains. Especially for fish this is misleading because each water-terrain has a default amount of fish but fishers fish only at the coast. So a great ocean has a lot of fish which has no effect for game play, but all those useless fish is counted by this script. This might be fixed in an other version of this add-on.
Edited: 2024-01-24, 10:29
Top
Quote
|
|
|
Alasia
Joined: 2020-04-26, 05:07
Posts: 15
Pry about Widelands
Location: Australia
|
Posted at: 2024-09-25, 05:48
Hey Kaputtnik - Thank you for this - it's enormously helpful and really useful to determine if a map is balanced!
For new editors who might not know much in coding, I'm adding some more information:
- It seems obvious, but when Kaputtnik says the whole path, he does mean the full system path to the scripting file (and not the one relative to wherever you installed Widelands). eg, for me, it looks like
"/home/Alasia/projects/widelands/usr/share/widelands/scripting/map_statistics.lua"
- If you look at the script (in notepad will do it), the uses available to you are listed as functions, so to analyse the whole of a 128x128 map, in the debug console type
analyse_rect(0, 0, 127, 127)
- Similarly, to analyse the area around a single player HQ, use the coordinates and an appropriate radius for the script to check eg
analyse_region(73, 34, 30)
Is there a way to output this information to a text file or the initiating console screen? My screen isn't huge and it would be helpful to be able to switch between the output and editor while I make changes rather than re-running the script each time.
Edited: 2024-09-25, 05:49
github: Alasiax
Top
Quote
|
|
|
kaputtnik
Topic Opener
Joined: 2013-02-18, 20:48
Posts: 2514
OS: Archlinux
Version: current master
One Elder of Players
Location: Germany
|
Posted at: 2024-09-25, 08:18
It seems i forgot to add a post to this thread
This script is available as an add-on (needs at least widelands version 1.2) and you will find it the UI_Plugin category. After installing this as an add-on you will find the script(s) in the folder .widelands/addons/editor_analyse_map.wad .
Is there a way to output this information to a text file or the initiating console screen? My screen isn't huge and it would be helpful to be able to switch between the output and editor while I make changes rather than re-running the script each time.
When writing this scripts i also thought about writing the result to the console. But in the end i was happy it runs smooth and didn't spend much time on this idea
Anyway it should be possible to output the result to the console. If you use the add-on this will need starting widelands from a console. Saving as a text file isn't possible, afaik, due to security reasons (a script shouldn't be able to write files on a foreign computer).
To achieve writing to the console this might needs adding some more functions which outputs the result in plain text (with print() statements). Currently the output is formatted as widelands richtext which isn't easy to read for a human.
If you want to add some print() statements yourself and ran into troubles feel free to ask Maybe i find some time in winter to add such functionality to the add-on.
One remark: If you edit scripts you should use a plain text editor.
Top
Quote
|