• New Horizons on Maelstrom
    Maelstrom New Horizons


    Visit our website www.piratehorizons.com to quickly find download links for the newest versions of our New Horizons mods Beyond New Horizons and Maelstrom New Horizons!

Directsail ship encounters

stljeffbb

Sailor Apprentice
Storm Modder
Hello everyone....the purpose of this thread is to discuss and figure out how we can get ship battles independent from our own ship into the Directsail mod...here is some code I've identified as the very likely caller for ships when a "sail ho" is received:

Code:
//-------------------------------- Encounters and events -----------------------------------

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 ");
}

My main question at the moment is this....what does the "sti" stand for in a line like:
sti(rPlayer.DirectSailEncounterGroup) ? And for that matter, the "stf" in a line like: stf(rPlayer.ship.pos.x) ?

I tried something like this:

OLD CODE

Code:
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);

NEW CODE

Code:
if(CheckAttribute(rPlayer, "DirectSailEncounterGroupA")) rPlayer.DirectSailEncounterGroupA = sti(rPlayer.DirectSailEncounterGroupA) + 1;
else rPlayer.DirectSailEncounterGroupA = 1;
if(rPlayer.DirectSailEncounterGroupA > 20) rPlayer.DirectSailEncounterGroupA = 1;
groupname = "Directenc" + sti(rPlayer.DirectSailEncounterGroupA);
if(CheckAttribute(rPlayer, "DirectSailEncounterGroupB")) rPlayer.DirectSailEncounterGroupB = sti(rPlayer.DirectSailEncounterGroupB) + 1;
else rPlayer.DirectSailEncounterGroupB = 1;
if(rPlayer.DirectSailEncounterGroupB > 20) rPlayer.DirectSailEncounterGroupB = 1;
groupname = "Directenc" + sti(rPlayer.DirectSailEncounterGroupB);

I was hoping to make two separate groups spawn....I have much to learn about coding! :p

The above did not work as I hoped, but it did not crash the game either.....a neutral result is better than a bad one, lol

(Go easy on me, I'm a hack when it comes to code ;) )

Jeff
 
sti = String To Integer (whole number) and stf is String To Float (decimal number).

Great that you be working on this one! The way I'd do it is by searching the code that sets up the battle encounters for the worldmap and replicate that in the DirectSail code.
 
Back
Top