Description (from link):
Provides other widgets with the location of maps metal spots, by itself it does nothing.
What it does:
Basically the widget is a replacement for the Area Mex code that a lot of people seem to be using, based on a better algorithm that is faster and provides information about spot dimensions. The main use of knowing spot dimensions is that it can determine locations which would give 100% extraction.
It puts this information in the global WG table and then terminates. This means anything using the information will be running in its own widget space which prevents the bugs that happened with area mex (i.e. button version causing freezing).
Advantages:
- Faster (40x), takes less time to find metal spots than it does for custom formations to work out a line move, ~0.04 seconds for standard maps, 85% of which is spent extracting metal values from the map.
- Detects every metal spot, area mex code will sometimes join two spots that are close.
- Provides information for all widgets: prevents duplicate metal-scanning code running.
- Provides information about metal spot dimensions.
- Provides information about what extractor positions would result in 100% extraction.
- Properly detects metal maps or maps with cloud metal and terminates, rather than freezing.
Disadvantages:
- Terminates on metal maps or cloud metal maps, hence providing no information. In the case of cloud metal maps an arbitrary 'tolerance' like that used in area mex would solve this, but arbitrary isn't good in every case (and cloud metal maps are reasonably uncommon)
Data:
Code: Select all
WG.metalSpots[1..#] = spot
spot = {
.x, .y, .z, -- Position
.worth,
.minX, .maxX, .minZ, .maxZ, -- Bounds
.left[z], .right[z] -- Gives X bounds for particular z (valid Z ranges from minZ to maxZ with step 16)
}
WG.GetMexPositions(spot, uDefID, facing, testBuild)
Given a spot (taken from the global table) and a building uDefID/facing, it will return a table of all valid positions for that building that would extract 100% of the spots metal. The testBuild parameter indicates whether the function should test if the build positions are blocked, if so they won't be included in return table.
WG.IsMexPositionValid(spot, x, z)
Given a spot (taken from the global table) and a location it will return whether an extractor built at the location would extract 100% of the spots metal.
Example - Snap Mex:
To actually give the release of a widget which does nothing some substance, I made a small widget that makes use of the information that this widget gives, namely the knowledge of valid extractor positions. The widget also acts as a demonstration of how to use the metal spot table, and both of the functions.
The widget is called snap mex and has been released seperately, the download link for snap mex can be found here: http://widgets.springrts.de/index.php#184
Description - Snap mex (from link):
When placing mexes, if the mex position would not give 100% of the spots metal, then the position will be moved to one which would give 100%. Works especially well for placing mexes when zoomed out.
[Snap Mex Screenshot]