void DirectEncounter(float encay) // called by SeaLoginDirect
// creates ships that appear in the direction encay (playerheading as currently called )
{
int i, j;
float x, z, ay;
ref rGroup;
ref rPlayer = GetMainCharacter();
// string groupname = "Directenc"+rand(100);
// PB: Attemped CTD Fix -->
string groupname;
if(CheckAttribute(rPlayer, "DirectSailEncounterGroup")) rPlayer.DirectSailEncounterGroup = sti(rPlayer.DirectSailEncounterGroup) + 1;
else rPlayer.DirectSailEncounterGroup = 1;
if(rPlayer.DirectSailEncounterGroup > 20) rPlayer.DirectSailEncounterGroup = 1;
groupname = "Directenc" + sti(rPlayer.DirectSailEncounterGroup);
// PB: Attemped CTD Fix <--
int Encnation = rand(5); // RANDOM nation for encounterships
// int Encnation = FindEnemyNation2Character(GetMainCharacterIndex()); // another choice: Only ENEMY encounters
// ships shall appear ahead of player(aprox!), so we set coords according to player coords & heading
// encay = encay - 1.5 + rand(3); // random deviation from playerheading, so that ships are not always dead ahead
float bearing = randnorm(60.0, 30.0); // LDH better random number for bearing - 10Jan09
if (bearing > 90.0) bearing = 180.0 - bearing;
if (rand(1)) bearing = -bearing;
if (bearing > 180.0) Bearing -= 360.0;
DSTrace("Encounter - bearing to ship " + makeint(bearing));
encay += Degree2Radian(bearing);
z = stf(rPlayer.Ship.Pos.z) + (cos(encay)*DIRECTENCOUNTERDISTANCE); // add Z component
x = stf(rPlayer.Ship.Pos.x) + (sin(encay)*DIRECTENCOUNTERDISTANCE); // add X component
Traceandlog("Strange sail " + GetBearingFromShip16(Degree2Radian(bearing))); // LDH 26Feb09
ay = randnorm(encay + 3.2, Degree2Radian(20.0)); // LDH random heading 29Jan09
ReloadProgressUpdate();
Sea_AddGroup2TaskList(groupname);
rGroup = Group_GetGroupByIndex(Group_CreateGroup(groupname));
Group_SetXZ_AY(groupname, x, z, ay);
Group_SetType(groupname, "war");
Group_DeleteAtEnd(groupname);
// encountertype ? Rand(6) for now
int enctype = makeint(rand(6) );
int iNumShips = Fantom_GenerateEncounter(groupname, enctype, Encnation);
DSTrace("Directsail encounter type: " + enctype + ", at x = " + x + ", z = " + z);
// load ships to sea
if (iNumShips > 0) LoadShipsToSea(iNumShips, groupname, Encnation, -1); // KK
// task: ENEMY attacks you, others sail towards you
if (GetRMRelationType(GetRMRelation(GetMainCharacter(),Encnation)) != RELATION_ENEMY)
{
// LDH 29Jan09
x = x + 10000.0 * sin(ay);
z = z + 10000.0 * cos(ay);
Group_SetTaskMove(groupname, x, z);
// Group_SetTaskMove(groupname, stf(rPlayer.ship.pos.x), stf(rPlayer.ship.pos.z));
Trace("Directsail encounter nation: " + Encnation + ", task move ");
} else {
Group_SetTaskAttack(groupname, PLAYER_GROUP);
Group_LockTask(groupname);
Trace("Directsail encounter nation: " + Encnation + ", task attack ");
UpdateRelations();
}
ReloadProgressUpdate();
Trace("Directencounter done ");
}