Hi all,
Have created a more stable version of DirectSail.
Busy with the deck loading part and encounters on sea.
Two Eyed
Have created a more stable version of DirectSail.
Code:
/*
This scoop (from void InitIslands()) is stoc POTC I thought,
don't know for sure. For this DirectSail to work correctly
_all_ Islands[] must have the .id and set at least
to "" (empty string)
for ( i = 0; i < MAX_ISLANDS; i++ )
{
DeleteAttribute( &Islands[i], "" );
Islands[ i ].id = "";
Islands[ i ].reload_enable = true;
Islands[ i ].visible = true;
}
*/
// TODO : Adjust the radius of the island so that the next island is out of sight before
// the next island can show up.
// TODO : When entering the worldmap out of range of any island then go back to OpenSea,
// the coordinates are set to 0, 0. They should be converted too.
// TODO : Enter deck and cabins while sailing. (Try to get it keep sailing, change weather,
// get encounters etc.)
// TODO : Update weather (dynamicly changing over time)
// TODO : Integrate the EternalString as the interface just like the wind speed and direction.
void DirectSailUpdate()
{
// event added in void InitBattleInterface();
// event removed in void DeleteBattleInterface();
// event first called in StartBattleInterface();
FindNearestIsland();
if( CheckAttribute( MainCharacter, "location.ReloadTo" ) )
{
if( MainCharacter.location.ReloadTo != MainCharacter.location )
{
Sea_ReloadStartSea_Reload();
}
}
Log_SetEternalString( sti( worldMap.playerShipX ) + ", " + sti( worldMap.playerShipZ ) + " " +
MainCharacter.location );
PostEvent( "DirectSailUpdate", 1000 );
}
string ConvertIslandNameToShortName( string name )
{
if( name == "FalaiseDeFleur" ) name = "FaleDeFler"; //else
//if( name == "asdfg" ) name = "asd";
return name;
}
void DirectSailUpdateCoordinates()
{
if( MainCharacter.location == "" || MainCharacter.location == "open_sea" )
return;
string Island = ConvertIslandNameToShortName( MainCharacter.location );
float psX = MakeFloat( MainCharacter.Ship.Pos.x );
float psZ = MakeFloat( MainCharacter.Ship.Pos.z );
float ix = MakeFloat( worldMap.islands.( Island ).position.rx );
float iz = MakeFloat( worldMap.islands.( Island ).position.rz );
worldMap.playerShipX = ( psX / WDM_MAP_TO_SEA_SCALE ) + ix;
worldMap.playerShipZ = ( psZ / WDM_MAP_TO_SEA_SCALE ) + iz;
}
void FindNearestIsland()
{
DirectSailUpdateCoordinates();
int i;
string island = "";
float shipX = MakeFloat( worldMap.playerShipX );
float shipZ = MakeFloat( worldMap.playerShipZ );
float islandX;
float islandZ;
float distanceX;
float distanceZ;
float distance;
float distanceCurr = -1;
for( i = 0; i < MAX_ISLANDS; i++ )
{
island = ConvertIslandNameToShortName( Islands[ i ].id );
if( island != "" )
{
islandX = stf( worldMap.islands.( island ).position.rx );
islandZ = stf( worldMap.islands.( island ).position.rz );
distanceX = islandX - shipX;
distanceZ = islandZ - shipZ;
distance = sqrt( ( distanceX * distanceX ) + ( distanceZ * distanceZ ) );
if( distanceCurr > distance || distanceCurr == -1 )
{
MainCharacter.location.ReloadTo = Islands[ i ].id;
distanceCurr = distance;
}
} else
{
TraceLog( 1, "Invalid island id (" + island + ")" );
}
}
}
void DirectSailSea_Reload()
{
TraceLogStart( 3, "void DirectSailSea_Reload()" );
// Same as Sea_Reload() but initializes Login with coordinates translated to the new island.
DelEventHandler("DirectSailSea_Reload", "DirectSailSea_Reload");
if( CheckAttribute( MainCharacter, "location.ReloadTo" ) )
{
string island = MainCharacter.location.ReloadTo;
if( island == "" || island == MainCharacter.location )
{
TraceLogEnd();
return;
}
TraceLog( 1, "Loading island: " + MainCharacter.location.ReloadTo );
// Convert worldmap coordinates to island coordinates
float psX = MakeFloat( worldMap.playerShipX );
float psZ = MakeFloat( worldMap.playerShipZ );
float ix = MakeFloat( worldMap.islands.( island ).position.rx );
float iz = MakeFloat( worldMap.islands.( island ).position.rz );
object Login;
Login.PlayerGroup.ay = stf( MainCharacter.Ship.Ang.y );
Login.PlayerGroup.x = ( psX - ix ) * WDM_MAP_TO_SEA_SCALE;
Login.PlayerGroup.y = 0.0;
Login.PlayerGroup.z = ( psZ - iz ) * WDM_MAP_TO_SEA_SCALE;
Login.Island = island;
DeleteAttribute( MainCharacter, "location.ReloadTo" );
SeaLogin( &Login );
}
TraceLogEnd();
}
void Sea_ReloadStartSea_Reload()
{
TraceLogStart( 3, "void Sea_ReloadStartSea_Reload()" );
// Same as Sea_ReloadStart() but calls DirectSailSea_Reload() instead of Sea_Reload().
if( !bSeaActive )
return;
DeleteSeaEnvironment();
SetEventHandler( "DirectSailSea_Reload", "DirectSailSea_Reload", 0 );
PostEvent( "DirectSailSea_Reload", 1 );
TraceLogEnd();
}
Busy with the deck loading part and encounters on sea.
Two Eyed