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.

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

Stub

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

Stub

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

Stub

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

Stub

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.1454302405.txt.gz
  • Last modified: 2016/02/01 04:53
  • by vagabond