Forum



Spike am 23.06.2012 22:32 #10043

Im Ruhestand
... Paint!

At the moment a fellow member of our community, namely Hubert, is working on a "picture to map" tool. This tool is already
able to read 16 colours .bmp files to generate Settlers II .swd maps. For every aviable texture we use a corresponding
colour. Hopefully we will be able to use that tool soon to build fair maps or "real world parts" by drawing them.

For example you got this picture:


and generates this map:


---


Editiert von Spike am 29.06.2012 11:52

Parasit am 24.06.2012 00:12 #10044

RTTR-Doofie
this method of creating maps from real maps is very precisely, you can see the original topographic map of iceland here:




you only have to convert a real map to this 4bit colourtable (16 colours)



(5 colours are not defined yet)

---
>> My Youtube Channel <<




jh am 24.06.2012 00:18 #10045


Nice. I think something like that exists already for Settlers 3... Was it inspired from there?


PR90 am 12.07.2012 18:31 #10109


gute Idee! :)
Ich kenne was ähnliches von einem Autorennspiel, bei dem man eigene Rennstrecken erstellen kann. Dort kann man, statt im normalen Editor, auch alternativ in Paint mit verschiedenen Farben verschiedene Streckenbeläge festlegen oder auch Auslaufzonen, die dann je nach Farbe aus Asphalt, Kies, Sand oder Gras bestehen.
@Spike: Falls Hubert sich da Ideen holen will: Das Spiel heißt GeneRally, man kann es legal und kostenlos im Internet herunterladen. Ich habe dort immer in Paint die Landschaft erstellt und dann erst die fertige Landschaft in den eigentlichen Editor geladen, in dem ich dann z.B. noch Bäume hinzugefügt habe. Also im Prinzip fast genauso, wie er es für Siedler 2 geplant hat. Natürlich waren es beim Autorennen keine Landkarten, sondern Streckenlayouts, z.B. auch von echten Strecken, von denen man dann den Streckenverlauf für die zu erstellende Rennstrecke übernommen hat, in dem man einfach die Streckenumrisse reingeladen hat. Also eigentlich genauso, wie es auch mit einer Landkarte möglich wäre.
Sorry, dass ich in Deutsch geschrieben habe. Aber für diesen Text hätte ich in Englisch Stunden gebraucht ^^

---
Siedlersüchtig seit 1999 ^^


RFM am 16.07.2012 07:05 #10137


And... Where can i test the tool ?

---
RTTR auf YouTube: RTTR Channel  | Channel von Spike


Spike am 16.07.2012 11:06 #10140

Im Ruhestand
No where at the moment but hopefully we will get this tool, you can ask Hubert too :)

---



Merri am 01.08.2012 17:44 #10201


Kinda related, but a very different approach: http://settlers2.net/2012/08/setting-a-png-standard/

This isn't intended for direct manipulation, instead it is for webserver (PHP) to client (browser canvas/JavaScript) communication.

---
Settlers II.net admin

Editiert von Merri am 01.08.2012 17:44

RFM am 02.08.2012 00:09 #10202


Thanks Merri, that is that what i searched for :) Great work!

I testet it with some Maps.

Starmine - GoldenCookies.swd


K17zwei.swd


deutsch.swd


Salvodor.swd



Note for other Testers: put the mapfile and the php file in the same dir. and set the name of the swd file,
like: path/s2canvaspng.php?file=mapname.swd
You have to run a php server.

---
RTTR auf YouTube: RTTR Channel  | Channel von Spike

Editiert von RFM am 02.08.2012 00:23

Merri am 02.08.2012 12:45 #10205


I found a bug in the code I posted earlier. Here is a fix.

Around line 273:
Code:
        // 8-bit to 7-bit... 23 title + 19 author = 42 chars
        // 42 / 7 = 6, so 6 extra chars for bits dropped from the 8-bit side
        // = total of 48 characters (bytes) reserved for title and author information
        for($k = $j = 0, $maxj = 6; $j < $maxj; $j++)
        {
            $b = 0;
            for($i = 0, $maxi = 7; $i < $maxi; $i++, $k++)
            {
                $c = ord($title[$k]);
                if($c & 0x80)
                {
                    $b |= 1 << $i;
                    $title[$k] = chr($c & 0x7F);
                }
            }
            $title[42 + $j] = chr($b);
        }


I had forgotten to remove the highest bit from the byte, which caused all 7 lower bits to be lost after PHP's processing. This means any character in the range of 128 - 255 was lost, including ü, ä, ö and the like.


At the moment I'm writing JavaScript code to read the PNG formatted images. I started by dealing with the code page 437 issue, which also lead into fixing the bug above :)

I'll be posting further code when I have something more to show.

---
Settlers II.net admin

Editiert von Merri am 02.08.2012 13:04

Merri am 02.08.2012 16:51 #10206


http://stackoverflow.com/questions/4309364/why-does-html-canvas-getimagedata-not-return-the-exact-same-values-that-were-j

There goes my hope of this working. HTML5 Canvas is implemented in a slightly cheatty way for performance, which means any pixel that holds some alpha transparency gives me incorrect RGB byte values. So after all the hard work getting PHP's 7-bit alpha channel limitation to work and have data there I find out there can't be any data in the alpha channel. Canvas is to my knowledge the only element in JavaScript that allows me to access RGB values so I have to reimplement the PHP generated PNG image in a different way.

The only good thing about this is that I found out about this now and not later.


Update!

http://settlers2.net/canvas/

---
Settlers II.net admin

Editiert von Merri am 02.08.2012 21:14

Merri am 06.08.2012 01:07 #10234


Recoded JavaScript + new features added to showcase how rewriting code helped: can now change palette and terrain type in real time, accessing and changing map data is instant in Firefox and Chrome.

There are some nasty things awaiting me, like figuring out the exact calculation method S2 uses for determining building sites. That information is a must.


http://settlers2.net/canvas/


Development update
2012-08-06: map blocks 13 (gouraud) & 14 (passable areas) recalculated.

---
Settlers II.net admin

Editiert von Merri am 06.08.2012 21:40

RFM am 07.08.2012 00:01 #10242


This is a really great Script! Thanks a lot!!! :)

---
RTTR auf YouTube: RTTR Channel  | Channel von Spike


Merri am 09.08.2012 01:12 #10276


You're welcome :)

At the moment I'm getting close to solving how building sites are calculated in the original game (as far as I can remember RttR just uses it's own algorithm that is different from the original game). At the moment my main problem is a case of a hut or castle site being marked too easily as a flag. This is quite bad as it tells me there are more rules behind hut/castle calculation than is easily figured out based on a single point height difference.

I've about 99% of all points calculated correctly on Glücksspirale map that I use as my primary test case. For example all mine sites and flags (there are two variants!) are 100% correct. I have only one single case of 0x01 flag point being marked as 0x09, which I don't think is too big of a problem as it is a rare case and a flag either way.

---
Settlers II.net admin


Spike am 09.08.2012 03:35 #10277

Im Ruhestand
Well I think you could ask Xaser or search in his code for a good algorithm - I don't know how he calculates the building sites but I as far as I remember they were 100% right in every case.

---



Merri am 09.08.2012 11:04 #10279


His code only calculates the nearby locations for the correct icon, but does not calculate exact same values for the file as the original map editor. Looking at Xaser's source did help to locate the error I had though, now I'm down to only two incorrect results with the entire Glücksspirale :) I think these are simply a result of checking things in different order than the original game does, at the moment I'm ranking those points as flag 0x09 (because granite nearby) while original game uses flag 0x01 (because of nearby height differences).

I post an update to the url above soon after this post.


Edit!
Done. Just noticed the file size of the HTML file has doubled since last update!

---
Settlers II.net admin

Editiert von Merri am 09.08.2012 11:06

Spike am 09.08.2012 14:38 #10283

Im Ruhestand
Well, that sounds nice, that means we could maybe use your way to calculate the building sites in RttR too?

And did you really use Glücksspiral because Glück means luck? :D

---



Merri am 09.08.2012 15:32 #10284


RttR doesn't need the extra information ingame unless the game's inner workings are to be optimized to emulate how the original game does things (notably memory & processing efficiency). For example the original game "cheats" information from bit flags so that it doesn't need to do as much processing. Anyway for saving map files the information should be correct, atleast for maps that could be used in the original game as well.

My current bit of code isn't likely to be any better than Xaser's if we look at it from performance perspective. My code is a little bit shorter and accounts for a few extra things regarding textures. In the future I'll probably spend some time optimizing performance and reducing code length, and I need to write it in PHP as well - I won't be trusting client side responses and that is also why PNG format provides only the minimal amount of map information :)

---
Settlers II.net admin


Merri am 12.08.2012 18:46 #10303


http://settlers2.net/editor/

Okay, this isn't much as it is, but lets you upload a few maps, open for some editing like changing the world type and then download the map. Now only for personal use, you can't share your maps yet with others (ie. Map Database is missing).

If something seems broken I might have been changing something, just hard refresh the page (Ctrl + F5) and it should reload new JavaScript.


There is a lot of work waiting for me in cleaning up the code as I now have three separate PHP codes dealing with reading or saving a WLD/SWD file. Really have to pull all of those together into one clean file.

JavaScript also needs cleaning up for more performance and to make it easier to add new features.

---
Settlers II.net admin


jh am 14.08.2012 17:53 #10316


Cool, looks nice! Do you plan any editing features? Or is it just for sharing worlds?


Merri am 14.08.2012 18:48 #10317


Yes, there will be more editing features :)


A moment ago I fixed a bug that made some mining resources disappear. I also wrote a bit of code to speed up writing of additional code, but the downside is increased memory usage (shouldn't matter on modern computers, we're talking about 3+ MB here).

It also seems like my download routine has slightly broken at some point, browser no longer uncompresses a downloaded map file. I have no idea why it does that as I haven't changed any line near that routine. So any downloaded map is actually GZIP compressed atm and that is why game or editor refuses to open it, if having problems.

---
Settlers II.net admin

Editiert von Merri am 14.08.2012 18:48