op2_sdk:disasters

Disasters

Reviewed for SDK 2.1

All disasters in Outpost 2 are fully supported by the SDK. This section covers Meteors, Electrical Storms, Earthquakes, and Vortices. Volcanoes are handled in the Volcano Section here: Volcanoes.

When setting a disaster, you are setting when the first warning that the disaster will occur. No disaster can occur at mark 0 (when a scenario first starts). Even if you set a disaster to immediately occur, it actually will not happen until mark 15.

static void __fastcall SetMeteor(int tileX, int tileY, int size);

There are 3 sizes of meteors available.

static void __fastcall SetLightning(int startTileX, int startTileY, int duration, int endTileX, int endTileY);

An electrical storm will disappear once its duration has expired. Duration is set as number of marks. If the electrical storm reaches its end tile before the duration expires, it will continue on past the end point.

static void __fastcall SetEarthquake(int tileX, int tileY, int magnitude);

Earthquake magnitudes above about 7 become very dangerous.

static void __fastcall SetTornado(int startTileX, int startTileY, int duration, int endTileX, int endTileY, int bImmediate);

If you set the vortex duration to 0, it will continue indefinitely.

Create a randomized disaster. Note, this code will require Hacker's Function Library (HFL) to run. If not using HFL, replace the functions GeTMapWidth and GetMapHeight with the actual width and height of the map.

LOCATION getRandMapLoc()
{
    return LOCATION(
	TethysGame::GetRand(GameMapEx::GetMapWidth()) + 31,
	TethysGame::GetRand(GameMapEx::GetMapHeight()) - 1);
}
 
void CreateMeteor()
{
    LOCATION disasterLoc = getRandMapLoc();
 
    int size = TethysGame::GetRand(3);
    if (size = 3)
    {
	size = TethysGame::GetRand(3);
    }
 
    TethysGame::SetMeteor(disasterLoc.x, disasterLoc.y, size);
}
 
void CreateStorm()
{    
    LOCATION startLoc = getRandMapLoc();
    LOCATION endLoc = getRandMapLoc();
    TethysGame::SetLightning(
	startLoc.x, startLoc.y, TethysGame::GetRand(55), endLoc.x, endLoc.y);
}
 
void CreateEarthquake()
{
    LOCATION loc = getRandMapLoc();
 
    TethysGame::SetEarthquake(loc.x, loc.y, TethysGame::GetRand(5));
}
 
void CreateVortex()
{
    LOCATION startLoc = getRandMapLoc();
 
    TethysGame::SetTornado(
	startLoc.x,
	startLoc.y,
	TethysGame::GetRand(45) + 5,
	startLoc.x + TethysGame::GetRand(15),
	startLoc.y + TethysGame::GetRand(15),
	0);
}
 
SCRIPT_API void CreateRandomDisaster()
{
    //Set a disaster. This uses a weighted random. Picking a random number 0 to 100:
    //0-19 = no action
    //20-69 = meteor
    //70-84 = quake
    //85-94 = electrical storm
    //95-100 = vortex
 
    int randNum = TethysGame::GetRand(100);
 
    if (randNum < 20)
    {
	return;
    }
 
    if (randNum < 70)
    {
	CreateMeteor();
    }
    else if (randNum < 85)
    {
		CreateEarthquake();
    }
    else if (randNum < 95)
    {
	CreateStorm();
    }
    else
    {
        CreateVortex();
    }
}
 
int InitProc()
{
 
}

- Go Back to Programming a Scenario
- Go Back to Outpost 2 Mapmaking
- Go Back to Outpost 2 Main page
- Go Back to Wiki Home Page

  • op2_sdk/disasters.1480147790.txt.gz
  • Last modified: 2016/11/26 08:09
  • by vagabond