Replacing elements in all levels

Discussion around programming R'n'D, its source code and its tools.

Moderators: Flumminator, Zomis

Post Reply
Posts: 7
Joined: Thu Jan 26, 2017 2:28 pm
Location: Poland

Replacing elements in all levels

Post by balinek »

Hello. I have written short program in python that replaces some simple elements to another simple elements in all levels.
It works fine with original supaplex levels imported from levels.dat.
So, in a directory I have 111 files (001.level .. 111.level) and this program.
Example what I have replaced you can see in screen.txt file.
All zonks to stones.
All electrons to diamonds.
All base to dirt.
After all this replacements I have changed game engine to Rocks'n'Diamonds (It was necessary).
I was trying to change another levels but program damaged them.
Probably they have different hex codes for elements.
For example it is not possible to replace empty space - level will be unusable.
I know that is a little bit crazy using it, but I just wanted quickly replace some elements in all levels in 'one click'.
If you would like to use it make a backup of your levels necessarily.
Please tell me what you think about it.
Will be nice to see any suggestions.

Edit: I have added to this program random number of replaces.
(1011 Bytes) Downloaded 168 times
(1.36 KiB) Downloaded 185 times
(826 Bytes) Downloaded 168 times
User avatar
Site Admin
Posts: 3522
Joined: Fri Jun 18, 2004 4:13 pm
Location: Germany

Re: Replacing elements in all levels

Post by Holger »

I've had a look at your Python script, and indeed it is a bit "dangerous" (to the levels) to convert levels/elements this way.

The main problem as far as I can see is that it uses fixed offsets/ranges in the level file. The problem with this approach is that R'n'D level files are stored in IFF / Interchange File Format, which is a generic container file format which uses different "chunks" (of bytes) that may occur in arbitrary order or may even be optional, like level header data, level playfield data and level element data. So you may or may not hit the right bytes to change (or damage it if you hit the wrong bytes).

So, what would work better is if you would first look out for the right chunk you would like to modify (like "NAME" for the level title, "AUTH" for the level author or, probably more what you want to do, "BODY" for the playfield data (but beware, game elements might be stored as 8 or 16 bit values, depending on a flag in the "INFO" chunk)).

You can find more details in "src/files.c" -- look our for functions named "LoadLevel_INFO()" or "LoadLevel_BODY()" etc..
Posts: 7
Joined: Thu Jan 26, 2017 2:28 pm
Location: Poland

Re: Replacing elements in all levels

Post by balinek »

Thank you for your suggestions. I will try to investigate a little more as you proposed. Now I have nearly finished graphical version which is clickable only (elements are taken from 256 gif files), no need to enter hex codes. But it works like previous versions. Maybe I can manage this problems or maybe not.
Thank you once again.

In new gui version I restricted element replacement only to levels with BODY chunk and I replacing only in BODY chunk. However, it may happen that behavior of this script will be unpredictable and can damage level or do nothing:

1. If author name or level name or INFO chunk will contain 6 byte string - "BODY" and 2 bytes with values 0.
2. If we choose wrong value between "1 byte elements" and "2 byte elements".
(I couldn't manage to make this choice automatic.)
Backup and Restore buttons are rather for convenience during testing, not for real backup and restore.

If someone of you will test it and find some errors, please answer.

(Many thanks for gif files!)
Post Reply