Dynamic Maps

There are two scripts available that allow the developer to change part of a map:


Tsukihime's Tile Swap (http://himeworks.wordpress.com/2013/02/17/tile-swap/) and


Fomar0153's Region Map Loader (http://cobbtocs.co.uk/wp/?p=334).


Both were limited in their intentions and thereby fall short of the options needed for a truly dynamic map - which is basically needed to provide random map options.


I have thought of a script that may allow such a map in an RM-Game, but I don't know enough of RGSS3 and the internals of the RM-Engine to make such a script myself. I'm describing the idea here as a request to learn if it is possible and if some scripter would be interested enough to make such a script available to the public.


The script needs several commands or options described as following:


1) A way to designate one or more of the editor's maps as "dynamic"


This will basically tell the engine that this map needs to be saved and loaded when saving the game, instead of using the default map file from the editor.


This will also tell the script about the general map data - the size set for the map in the editor should be the maximum size, and all map properties like tileset will be taken from this map.


2) Maps as dynamic Mapparts to be made by the game developer


This is not directly part of the script, but the script has to have a way to get that data based on the map-ID used in the script's functions


3) Scriptcall to copy data from one map (mappart, see 2) into the dynamic map (see 1)


Input data for the function:


ID of the dynamic map (most probably the current map, but might be another ID if called before a transfer)


X,Y Koordinates on the dynamic map (1) to specify where to place the new part (2)


ID of the map used as mappart (2)


Then, beginning on the specified coordinates and going to the size of the map to be copied, for all positions on that area the following sequence should be prozessed:


- coordinate check for target outside dynamic map, skip if target coordinate has already left dynamic map


(if the selected mappart is larger than the size available from the specified coordinates, anything outside the dynamic map will be ignored)


- If the bottom map layer of the current tile on the mappart is set, that tile is copied/placed to the bottom tile on the current coordinates of the dynamic map


(this is to allow for non-regular mapparts - wherever the parallax would show on the source map for the mappart, the previous data on the dynamic map will be retained)


- if the top map layer of the current tile on the mappart is set, then that tile is copied/placed to the top tile on the current coordinates of the dynamic map.


(again to allow irregular source forms, or to place different decorations on the bottom layer of the dynamic map)


- if there is an event on the coordinates of the source map, that event will be copied to the coordinates on the dynamic map (replacing a previous event there if neccessary)


These steps should be repeated for every tile on the source map, until that has been copied to the dynamic map.


Previous data on the dynamic map is always deleted/overwritten.


When saving a game, the last/current structure of all dynamic maps is always saved (to be loaded again when the game is loaded or when the player enters the map again later


(If neccessary, I can make a flowchart for this - but it's basically only a loop over all tile coordinates)


4) script call to reset the dynamic map to the original editor structure


If several dynamic maps exist, this need the MapID to prevent loosing other dynamic maps.


This would allow a developer to use a map for a random dungeon, later clearing it and using it for a different random dungeon without worrying about which parts of the dynamic map were changed and which not.


----------------------------------------------------


It should be clear that in all cases, the dynamic map and the smaller maps used as sources for the mapparts need to be set to the same tileset. That is one of the reasons I consider the option of allowing several dynamic maps, so that different tilesets might be used with different sets of dynamic maps.


----------------------------------------------------


Intention:


Such a script could be used for several types of random or non-random maps. The examples I can think of:


- random dungeon grid


Make an empty dynamic map of 105x105, and partial maps of 15x15 each containing one room with possible exits NSWE and different contents. An autorun event on the dynamic map can fill it with a random selection of 7x7 of those "dungeon rooms" with different content.


It would even be possible (with a bit more tricky eventing) to have the randomization not upon entering the dynamic map, but have the next room appear when the player gets to the exit of the room he currently is in (make the event with the script call for copying the next room into the dynamic map on the mapparts near the exit areas).


- changing world


Make the dynamic map with the beginning town/castle, and later call in smaller mapparts to reflect changes done on the map, like burned down parks or new construction like a player's home.


- mission specific maps


In an XCOM-Type game where the player has to clear an UFO crash-site, have the dynamic maps different parts of earth (town, forest, etc) and make just one scriptcall to place the UFO wreck at a more or less random position on that map. If there are several possible wrecks and several basic earth maps, the result will be a multiply of possible mission maps (is it a small or a big UFO that crashed, and was it placed on a town or forest map etc).


- different mapping type


Instead of using random placement, the entire game world might be created with fixed copying of premade smaller structures into the player's maps. That way is an alternative to copying the maps in the editor and perhaps some developers might choose this way instead of manually copying the tiles in the editor.


This would have some advantages in teamwork (people can work on different parts of the map without needing coordination) or when the developer doesn't have good mapping skills and might commission the parts.


---------------------------------------------------


If no scripter is interested in such a request, I would appreciate a few comments on possible problems or advice to improve the description or idea
Personally, I'd rather use for pictures for dynamic mapping... can be a bit of performance drainer if used largely though... but I'm curious if somebody will make this... 🙂


PS: looked at Hime's script... to me it seems like good manipulation of it can still do this... to some extent...


For other cases (like different tilesets), I think it might be hard via tiles alone... at least from what I've seen from how the game handles tiles... I've actually been trying to dabble with that some months ago, but decided to just use pictures... but then again, I haven't touched it much...
Personally, I'd rather use for pictures for dynamic mapping...
With pictures, you can't change passability (or other specific tile data) of the map area - this isn't just to change the display of the map, it's to create all map data.
And yes, theoretically Tsukihime's script could do something like this - but it's designed for single tile change mostly and it would be very time consuming to make complex structures appear by single tile edits.
Hm.. that sounds really useful. If i understand 2) and 3) correctly, you basicly want to have a bigger dynamic map, basicly serving as a kind of canvas on which you can copy smaller maps (map-parts)?

I had a similar idea to make a random-dungeon grid (but having each dungeon-tile "seen" as a different map by the player, with clever use of transfering) - and that script is already half-finished (the random-part is still missing), but your idea has indeed a wider range of use.

I may have a look at how maps are represented in RGSS3 and might give this idea a shot - if no other scripter finish this before me =).
Hm.. that sounds really useful. If i understand 2) and 3) correctly, you basicly want to have a bigger dynamic map, basicly serving as a kind of canvas on which you can copy smaller maps (map-parts)?
Yes, exactly - using smaller maps as source data allows the developer to create complex map structures in the editor, and the checks for empty data instead of simple copies allow the superposing of map parts over each other (eleminating the grid character as well as making several other uses possible).
- coordinate check for target outside dynamic map, skip if target coordinate has already left dynamic map


(if the selected mappart is larger than the size available from the specified coordinates, anything outside the dynamic map will be ignored)
I don't understand what this check is about or for.
I don't understand what this check is about or for.
Originally that was to prevent the placing of tiles outside the dynamic map area, for example if the dynymic map was 30x30, the part map were 20x10 and the target koordinates were something like 25,25 then most part of the sourcemap would be outside the dynamic map area. The check would then prevent the extra tiles to be placed on the map.However, I made a logik mockup to better describe the coding.

I also added another idea to make an "endless" map possible without too much lag due to mapsize:

* Logic Mock-up, NOT real codefunction placepart(DynamicMap, targetX, targetY, Sourcemap)loopY: for countY = 1 to Sourcemap.sizeY if countY + targetY > DynamicMap.sizeY if DynamicMap.scrolltype == loopY or loopboth DestY = countY + targetY - DynamicMap.sizeY else Exit LoopY endif else DestY = countY + targetY endif LoopX: for countX = 1 to Sourcemap.sizeX if countX + targetX > DynamicMap.sizeX if DynamicMap.scrolltype == loopX or loopboth DestX = countX + targetX - DynamicMap.sizeX else Exit LoopX endif else DestX = countX + targetX endif placetile(DynamicMap, DestX, DestY, Sourcemap, countX, countY) repeat LoopXrepeat LoopYendfunction placetile(DynamicMap, DestX, DestY, Sourcemap, countX, countY)if BottomLayerTile(Sourcemap, countx, countY).exists? BottomLayerTile(DynamicMap, DestX, DestY) = BottomLayerTile(Sourcemap, countX, countY)if TopLayerTile(Sourcemap, countx, countY).exists? TopLayerTile(DynamicMap, DestX, DestY) = TopLayerTile(Sourcemap, countX, countY)if EventonTile(Sourcemap, countx, countY).exists? EventonTile(DynamicMap, DestX, DestY) = EventonTile(Sourcemap, countX, countY)endThe added option to allow for scrolling dynamic map allows a common event to copy the next part of a much larger (but divided) map on the dynamic map in the direction the player is walking, effectively simulating an endless map without the need for transfer commands while keeping the active part of that endless map small enough to prevent lag.
I can understand the part where you're going to have out-of-bound errors if you don't properly check that you've hit the edge of the map, or that you'll have to properly offset your map-part if you're going to use negative offsets (eg: you're on the left edge of the map and you see the right half of a house, since the left half is outside the map).


However, if you introduce scrolling logic, that would seem kind of weird to suddenly cut off the map-part just because it's outside of the bounds of the map size.


Or maybe that's what that algorithm is supposed to illustrate but I'm not seeing it because it's mainly math checking.
However, if you introduce scrolling logic, that would seem kind of weird to suddenly cut off the map-part just because it's outside of the bounds of the map size.


Or maybe that's what that algorithm is supposed to illustrate but I'm not seeing it because it's mainly math checking.
As I said, the scrolling logic came later - and that's what the if-sequences about the scrolltype are for:


If the dynamic map is scrolling, the destination coordinates are corrected (the minus mapsize) to the other side of the dynamic map.


If it doesn't scroll, the loop is aborted to prevent the out-of-bound errors that would otherwise occur.


Edit:


I made the entire logic to work without negative offsets and on the assumption that the map parts can only be cut on the higher coordinates. To allow for placements where the parts start outside the map coordinates (the negative offsets) would require some modifications, I simply didn't think of that possibility.


That's probably the reason for the confusion, I see when I have time to modify the logic mockup for that option...
How would this differ from fomar's region loading?

The purpose of the region is to allow devs to mark off map parts without having to specify (x, y, width, height) tuples themselves manually. It might not be the intended purpose, but there are only so many ways to have someone identify a map part, and it makes sense to provide "named" map parts (in the form of ID's or otherwise) and expose that as the interface.

For example, both are possible ways to implement map part ID'ing

<map parts> "house1" : region 2 // region ID "house2" : 10x10+50+50 // dimensions and offset (I use imagemagick)</map parts>Then you just need to make script calls like

Code:
fetch_map_part(map 3, "house1", ... )
Perhaps specify a rect as a bounding box for the target location. Or event extract a particular portion of the source. Anyways those are irrelevant.It doesn't seem to function that much different from how region loader is designed (I never actually looked at what the script can do. I'm just assuming it based on what I think it should be doing)
How would this differ from fomar's region loading?
In Fomar's region loading you would replace preselected parts of maps that are otherwise identical (same size etc) with each other.
You can basically switch between the maps, but not change the position of the map structures


This script would allow you to place smaller parts on random or mathematically calculated positions. For example a smaller player home might be placed at coordinates the player selects (as long as they are within the allowed area).


Or you can have twenty possible dungeon rooms (20 small maps) as a selection and place one randomly at the next part of the larger dungeon map - in Fomar's case, that would need multiple copies if the same room could appear at different coordinates because Fomar's script can't move the parts around on the map.
So if someone wanted to use the region loader, assuming the map part was created in a 100x100 map at the top corner of the map, if a user wanted to copy that to the current map, they can only place it in the top corner and only that corner?


That's rather limiting.
It's been a while since i looked at the region-loader, so i don't know if that is already possible with it, but this is how i understood Andars request:

If you think of a map as a bitmap and each tile represents a pixel, then Andars wants the functionality of the blit-method, including "copying" of transparent pixel, that don't alter the pixel/tile that is currently in place on the target-map.

The limitation of the region-loader, as far as i remember is, that each tile can only have one region. So when copying parts of Map A onto Map B i only have the option of either copying the complete region or not. I can't copy part A onto place B and part C onto part D if A and C partly overlap or B and D overlap.

Another feature i read out of the initial request was copying of events and persistent maps, meaning the map-state (events and changed tiles) should be saved, instead of reloading the map every time it is entered, like it is done in the default scripts. Then again i don't remember how the region loader handles events.
So if someone wanted to use the region loader, assuming the map part was created in a 100x100 map at the top corner of the map, if a user wanted to copy that to the current map, they can only place it in the top corner and only that corner?


That's rather limiting.
Yes, exactly - Fomar's region loader is a very nice and small script for the purpose of limited structural map changes, but it can't be used for a lot of variances... 
One of the reasons I started thinking about this request.

If you think of a map as a bitmap and each tile represents a pixel, then Andars wants the functionality of the blit-method, including "copying" of transparent pixel, that don't alter the pixel/tile that is currently in place on the target-map.


Another feature i read out of the initial request was copying of events and persistent maps, meaning the map-state (events and changed tiles) should be saved, instead of reloading the map every time it is entered, like it is done in the default scripts. Then again i don't remember how the region loader handles events.
Yes, exactly - and the region loader doesn't handle events, events have to be on the basic map. Which is also a limit because you can't place chests in the copied parts, only the tiles themselves are loaded.

Original thread: https://forums.rpgmakerweb.com/threads/dynamic-maps.23188/