![]() |
Dominions II mapfile parser
1 Attachment(s)
I have made a Python script that reads a .map file and prints out info from it on the screen. The script is attached as a zip file to this post.
It started when I wanted to get the terrain specifications to a more readable format, and I later decided to add all map-file commands that I know of. It should be considered beta, so report any errors and suggestions for improvements. Feel free to host it on your Dom 2 sites if you want. EDIT: Updated to v0.6.0: v0.6.0: - Reworked internal handling of terrain. - Added calculation of number of land and sea neighbours. - Prints out terrain as plains if no other terrain type is set. - Moved many-sites from terrain line. - Use only one type of output for nostart. - Added information based on terrain of neighbours (island, coastal , etc.) - Allways print out province owner special info line and moved it after neighbours. - Switched province id and province name in output. - Added parsing of independents command. |
Re: Dominions II mapfile parser
Interesting, but I can't make it work, the .py files aren't executables, I suppose I should have some Pythonnesque runtime lib ??
|
Re: Dominions II mapfile parser
I wanted to test it and I receive the following error:
IndexError: list index out of range File "mapinfo.py", line 156, in ? fname = sys.argv[1] What should I do? |
Re: Dominions II mapfile parser
Quote:
- First make sure you have installed Python. It can be found at Python Programming Language. The only libraries used are sys, re and string which should be part of the standard installation. - I have no Windows installation, so I can't test, but try either to open it in IDLE and run it from there or type the following at command line: <font class="small">Code:</font><hr /><pre>python mapinfo.py <mapfile.map> </pre><hr /> |
Re: Dominions II mapfile parser
Quote:
(sys.argv[1] = first command line argument) Did you use IDLE to run in windows? Is it possible to add command line arguments when you use IDLE? EDIT: A new Version is now available, which has some improvements. For details & download, see the first post. |
Re: Dominions II mapfile parser
I tested it again with orania nasty ed. and it works great!
Last thing, he warned about one unknown command: #independents 9. I'm pretty sure this maps use almost all possible map commands so it is indeed a good result. This will be surely very usefull for making maps Thanks! |
Re: Dominions II mapfile parser
Quote:
|
Re: Dominions II mapfile parser
Nicely done. The format isnt as friendly toward further programming as I might want, but I can see where it would be useful for many.
|
Re: Dominions II mapfile parser
Quote:
|
Re: Dominions II mapfile parser
Only my own comment. If others dont jump in then its not worth doing anything about it. It depends on what you program in..
<font class="small">Code:</font><hr /><pre> <random>(46): NOSTART forest small neighbours: ['37', '55', '68'] <random>(62): NOSTART neighbours: ['58', '76'] <random>(82): neighbours: ['73', '78', '81', '84', '89'] <random>(100): forest mountain neighbours: ['85', '87', '91', '97'] </pre><hr /> Its a very readable format for user info which may be all it needs to do. But not good for programming. If there is no terrain you leave a blank line. Actually 0 terrain is plains (default) so you might want to make that change. But if there is no blankline for NOSTART. That means that in a program the code would be something like "find swamp, check next line for neighboring 32, back up one or two lines to get province number for including special site location". Im not sure if everything can be placed on one line and still be good for user reading, but possibly the NOSTART and terrains could be on the same line as the province number. That would make parsing abit easier, and make the neighbor line always be in the same spot in relation to those. |
Re: Dominions II mapfile parser
By The Way, your neighbor line could be used by someone for computing "quickest path from A to B" routines. Very nice.
DomMap added some info to its output for programming special sites and such.. <font class="small">Code:</font><hr /><pre> #neighbour 49 50 #neighbour 51 53 #neighbour 52 53 #terrain 1 2 -- L-S0L2 #terrain 2 208 -- L-S0L1 #terrain 3 130 -- L-S0L4 </pre><hr /> If a province is L-S4L1 then its saying its Land with 4 Sea neighbors and 1 Land neighborsm or a penninsula. L-S4L0 would be Land with 4 Sea and no Land neighbors, or an island. S-L4S0 would be Sea with 4 land neighbors and no Sea neighbors, or a lake. Yoiu might want to do something like that but probably in a more user format like actually saying island and lake. |
Re: Dominions II mapfile parser
Quote:
Quote:
Line 1: Name, id Line 2: Terrain Line 3: Neighbours Line 4: NOSTART, START, VP, etc. Line 5->: commanders, features, population, buildings There is also the problem that there are two ways to add nostart. As a terrain flag and as a separate command. Should the output differ for them? I will consider these changes and adding counting of number of land-sea neighbours to next Version. It will take to after Christmas before I have time however. |
Re: Dominions II mapfile parser
Quote:
Line 1: Name Line 2: id, Terrain, NOSTART, VP, etc Line 3: Neighbors That way even if there are no Neighbors it should still have a line which says Neighbors with no other output. Quote:
Quote:
OK now Im thinking there are two ways to go. One is to have a unique character or Groups of characters flagging the begining of each province output. Such as -=- which can be used to count from or jump to the next province. The problem is finding something which in a script environment such as linux doesnt mean something special already. OR add a switch such as -v for more verbose output and have two outputs. One for all info, and the other for easy-parse info. Hmmm wait, the more casual user should always be considered for defaults. So maybe have the fully englished curious-user output be default with a -s short-Version for script programmers. |
Re: Dominions II mapfile parser
Quote:
I decided to move the province id first in the first line of province info to make parsing easier. Just look for lines starting with "(". some basic neighbour info is also added. For details & download see first post. |
All times are GMT -4. The time now is 12:41 AM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©1999 - 2025, Shrapnel Games, Inc. - All Rights Reserved.