Visit The new RRC2Soft Tutorials ^_-

We made available new tutorials in Enjoy!

Maps & their problems

Hi!. It was a loooong wait, but this lesson is finally here!. Now we'll see that tiles aren't the only part of a map, a map is a mixture of a lot of things... now, let's start!!!
(NOTE: All this document talks about maps where PC's and NPC walks with a minimun step of ONE tile. If you want to know more about pixel_by_pixel steps e-mail us)

Before Start...
Tiles in a Map
Movement flags
Encounters with enemies andinfo of the limits
Other things
Source code
Final Words


What are the basic things of a map?

But don't be scared: when you understand the basis, all is easy.


How can I represent the tiles in a map?

With a two-dimensional arrayl:
TGraphicsInMap = Array [1..MAX_X,1..MAX_Y] Of TTile(2)

1 1 2 1
1 1 2 2
1 1 1 1
3 3 3 3

Remember this graphic (previous lesson)?. OK. Well, the graphic IS a map (with MAX_X=4 and MAX_Y=4), and every cell ([X,Y]) of the two-dimensional array has information about a tile.
And where are the tile graphics stored?. Every layer have its own file of graphics, and when executing the program, these files are stored into memory (for faster access).

And how more i have to know about tiles?

There's still a couple of details: the type of the layers (Byte/Word/DWord), and an optimization.


And what are them?

Look at the above map (that of the red crosses). It would be strange that you could walk in the mountains, uh?.
In every CRPG, there're certain tiles that we cannot step, neither cross (mountains, rivers, walls,...). How can we implement that?
First way to make it: adding a new data to every tile: walk/don't walk over me. Example:

If you put the mouse above the tiles (or you disable the graphics), you will see that there are tiles with TRUE and tiles with FALSE. Well, you can walk over the TRUE tiles, and not over the FALSE tiles.
With this method there're certain things that cannot be done. But with movement flags, you can.

Movement Flags

Look at the situation that we have to our left. They are two tiles that represent a section of a wall that is in a house with wooden floor, and whose exterior has floor of grass.
A character can walk inside of the house (leaving the wall behind), but he can also walk outside of the house (the wall would cover him). And he/she should not walk inside-out and out-inside.
That is impossible to contemplate with the previous method (the one that uses a boolean methid: can/can't walk over a tile), but there is a better way: To use movement flags.
The Movement Flags are in fact 4 bits that indicate to what addresses I can move (in the tile that I am) and to which not:

0 North
0 East
0 South
0 West
0 indicate "I CAN go to that address"
1 indicate "I CANNOT go to that address"
And look again at our left. We can see the situation of before, but indicating the movement flags.
One can see that from the inferior tile we can walk towards the left, towards the right and down, but NOT up. Equal passes in the superior tile, you can't go down.
For the inferior tile, their movement bits would be 1000, and for the superior they would be 0010.


Encounters with enemies

When we'are going to fight ?
When we meet with bad guys ^_^. But there are several ways of finding them:

A) You are walking in the field area, there's a flash and...combat!!!.
B) When speaking with a VERY powerful enemy (Sephiroth, Dark Force, Gades, i.e. ^_^)

We'll see the A case.The % of encountering with enemies, the type of enemies you encounter, the quantity,... all is kept in the map.
Well, in fact not all the things are stored in the map ^_-. But the most of things, yes.
The main problem: Where are in the map the data about encounters with enemies?.

A.1) In each tile: Absolutely wasteful and useless.It would occupy a lot of space and it would be a lot of work.
A.2) In the map: It depends on the size. If it is a small map (40x20 tiles, p. e.g.), it is worthwhile. If it is bigger (160x90, i. e.),...
A.3) In sections (areas) of the map. The map is divided into sections (for example, the map 160x90 is divided in sections of 32x18 tiles each one), and in each section is saved the data of encounters.

Well. And those data,... what things contains? ("with whom","where","how much"):

  1. The enemies' data: Indispensable. We must keep with what enemies we will meet. This's saved in a separate file, and we have in the map an index to that file (the file could use an array of 5 types of enemies).

  2. But if we're creating an strategic combat (like Shinning Force, Sakura Wars, Legend Of Langrisser, Dragon Knight IV...), we must save the data in every tile (or using a separate list, or using the event compiler. See Lesson LITTLE DETAILS (not done ^_^)).
  3. Encounter percentage. Indispensable: It is necessary to indicate when we will meet with the enemies. There is a couple of treatments for this:
    1. Use percentages: Each section has a possibility (expresed in %, i.e.) of meeting with enemies in each tile. When you walk one step (tile to tile), a "die" is thrown, and if the result is minus than the %...fight!!.
    2. Use a Countdown. The game has a number that is used like a countdown counter. Every time we walk, the countdown counter decrements, and when it reaches 0...fight!!. Each area has one or two numbers that indicates the value of the countdown counter for the area (and also there are more variables for the countdown: day or night; alarm or no alarm;...)
  4. Quantity of enemies: The how many. It is not indispensable, since it can be indicated in the data of each enemy and not in the map. This section will be commented in the lesson COMBATS (to go opening mouth, think that a possibility is throwing X dices when you have X people in the party, and the dice type (1d4, 1d6,...) is saved in the enemy data)
An example: Breath Of Fire II. Their field map is 256x256 tiles, and each section measures 16x16 tiles. It can have up to 14 possible enemies in a section. It uses the countdown system, although the map doesn't have information for accelerating the countdown.
Information taken out of "The Breath of Fire II Handbook", written by Ben Siron.

Information of limits.

What happens if I'm in the limit of the map and i walk outside it?. I teleport into other map.
Well, the we must keep that info (the map we teleport) saved in some place(5) (or if we don't go to anywhere).
This is made with an Array of 4 positions ( Array[0 ..3] Of Word) for each map. In each position is saved where to go if we go up (0), right (1), below (2) or left (3).
And how can we indicate: "No teleport"?. Using the maximun value of the Array's type ( In the previous example, if a limit is 65535, we cannot walk toward that address [Limit pos. 0 is 65535, we can't go up])
For example, the array of limits _arraylim is equal to (34,2,3,65535) in a map of size [1 ..20,1 ..20]. If we are in the position X=1 and Y=1 and we go up, we load the map n 34 (_arraylim[0]). But if we go to the left, we don't load any map: we cannot move (_arraylim[3]=65535).

Games like Knigths of Xentar (Dragon Knight 3) do this stuff. But there's games with other techniques (Phantasy Star saga, with a map they have enoguh to represent a planet, and the map is circular, without stopping the scroll).


This is left for later

Each map has a series of "mini-programs" that, when run, make the complicated stuff of CRPG's (to speak with somebody, to fight with a bad guy, to go to stores, to open a wall that was closed, special effects, move the PC's or NPC's...). These mini-programs are activated when looking or going into certain tiles. When this happens, an event is shot, and executes the corresponding mini-program.
...And explaining all of this needs an special lesson. So sorry, you must wait mooooooore time :_ (.
NOTE: People that knows RPG Maker 95 from ASCII will known of what i'm speaking ;-).


Diagonal movements

Now, we can only go towards the 4 cardinal points. But there're games (Emerald Dragon for SNES, Y's V, Shinning Force II) where people can walk in diagonal.
We supossed that this was implemented with events, but we have discovered other solution. We'll post it when required ^_-.


It will be commented in the lessons of COMBATS, but this is saved in the map, so it is necessary to point out it here.
If the combats are strategic, we can use the movement flags to indicate if a Pj can shoot or not into a tile (with an enemy inside...or not). But... there're certain tiles for which we cannot move (a river, i.e.) but we can see what there is in the other bank.
For that this Flag exists. It indicates that a tile can be seen, although one cannot walk into it. This way, a river would have active this flag, and although we could not walk on it, we could shoot above it.

Other flags

Roof Tiles, Mobile tiles,... these flags (we saw them in the previous lesson) also stays in the map.

Pnj's moving

We have made them (and programmed them ^_^). But is complicated: needs a special lesson.


In TIPOS.PAS/PP is the type TPantallaHDD, the map. For an explanation of the flags, look at the beginning of the MAPMAKE2.PAS/PP. Also execute the MAPMAKE2.EXE to see the movement flags (inferior zone, option 6. I advise to load the map n 0 to see the flags of the town)


(1): NPC: Non-Player Character.
(2): Look in the previous lesson the tile definition.
(3): An example: Now the game has 3 files for the transparent layer (TRANS000?.PCX). Each map chooses what file wants to use, and it loads the graphics to memory when the map is loaded.
(4): This is the RLE compression. Other compressions, as the ZIP, are based on the patterns: they look at the bits pieces that repeat, and they substitute it for an index to a dictionary of pieces:

AAADDD | FFFRR | DS | DS | LG | AAADDD | GT | FFFRR => _1_2_3_3LG_1GT_2
Dictionary: AAADDD=_1 | FFFRR=_2 | DS=_3 |
With this compression, I dunno what structure is the best (although I believe that the 2 continues being the best).
(5):Remember that maps are saved (like enemies and objects, and...) in files.

The end. The next lesson should go about the types of the characters, about the items,...; or about the scroll. But there are desires of writing a lesson about the combat, so for the next one: COMBATS: TYPES OF COMBATS.

See you!!!. And remember: we love mails ^_^!!!!. Send us your opinions about this tutorial (you see, isn't dead) 1