How to use lava

From OPU Wiki

Volcano's require a bit more coding before you can use them. Just setting TethysGame::SetEruption(...) won't just do it. It will only signal the game that the eruption is about to start (in 10 marks).

What you need to do, before this, is to tell OP2 where the lava can flow. This can be done using GameMap::SetLavaPossible. Each tile must be set seperately, which can be a tedious job for the coder. There are 2 ways of doing this:

  • using an array containing all the LavaPossible-tiles;
  • using a routine that scans the entire map for a certain tile-type, which it sets to LavaPossible.

Both routines have their advantages.

// SetAllLava:
// light lavarock: 1C7-1D6
// dark lavarock:  1D7-1F8
// edges:          22F-25E  (between light & dark lavarock)

void SetAllLava()
{
  int x,y,tile;
  LOCATION mapsize(1024,1024);                         // create a point wayoff the map

  mapsize.Clip();                                      // clip it, so we have the mapsize

  for (y=0; y<mapsize.y; ++y)                          // run through all rows
  {
    for (x=31; x<mapsize.x+32; ++x)                    // check every tile on each row
    {
      tile=GameMap::GetTile(LOCATION(x,y));            // get the tile on that position
      if ( ((tile>=0x1C7) && (tile<=0x1F8))            // is this one a lavarock...
        || ((tile>=0x22F) && (tile<=0x25E)) )          // ...or an edge ?
      {
        GameMap::SetLavaPossible(LOCATION(x,y),true);  // -> then set it to LavaPossible
      }
    }
  }
}

SetAllLava checks the entire map for any of the lavarock tiles, and sets the LavaPossible bit accordingly. You can change the condition within the if ( ... ) statement to check for only the dark lavarock, or dark with edges.

Although this routine doesn't require a lot of typing (just copy & paste it to your source), it does have restrictions: you can only set the lava area, as it was created by the mapper, using the different lavarock tiles.

If you want the lava to follow a specific path, and not flood all the lavarock, you will have to use this routine instead:

void SetLavaArea(int *lavaArea)
{
  int x1=0,x2,y,p=0;

  do
  {
    x1=lavaArea[p++]-1;
    y=lavaArea[p++];
    x2=lavaArea[p++];
    while (++x1<x2)
      GameMap::SetLavaPossible(LOCATION(x1+31,y-1),1);
  } while (x1>=0);
}

It accepts an int * argument, which contains a list of lava-possible tiles, with 3 numbers on each row. Here is an example:

int lava1[]=
{
  20, 14, 26,
  20, 15, 26,
  18, 16, 28,
  18, 16, 22,
  -1, -1, -1
};

SetLavaArea(lava1);

The 3 numbers on each row correspond to a starting X position on the map, a row number, and a ending X. To clarify: the first row of 3 numbers creates a line of LavaPossible from map position (20,14) to position (26,14). The second row of 3 numbers from (20,15) to (26,15) etc, etc.. You mark the end of the list with -1,-1,-1.

Personal tools