Latest Posts

Topic: Map analyse script

kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 19:48
Posts: 2480
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-02, 20: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.


Attachment:
map_statistics.lua (7.4 KB)

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 19:48
Posts: 2480
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-02, 20: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, 20:31

Attachment:
map_statistic.png

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 19:48
Posts: 2480
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-21, 16: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:
map_statistic_2.png

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 19:48
Posts: 2480
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-21, 16: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, 16:24

Attachment:
map_statistics.lua (16.6 KB)

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote
kaputtnik
Avatar
Topic Opener
Joined: 2013-02-18, 19:48
Posts: 2480
OS: Archlinux
Version: current master
Ranking
One Elder of Players
Location: Germany
Posted at: 2023-12-21, 16: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, 09:29

Fight simulator for Widelands:
https://wide-fighter.netlify.app/

Top Quote