• 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!

Map Enncounters Question

Luke159

Buccaneer
Storm Modder
I don't know why, but for a while before I went inactive I remembered looking at this file thinking that the ability to encounter ships without ever going to the world map was here in this file or at least some of the code needed for such features to work, only they had been quoted out. Can someone take a quick look at put my mind to rest please?

Also because it points to utils.c but has been quoted out, I have included that file aswell (please note these are not vanilla files, but from GOF2)
 

Attachments

  • Encounters_map.c
    13.4 KB · Views: 194
  • utils.c
    44 KB · Views: 196
I see all sorts of additional code compared to PotC, but nothing that seems to be related to on-sea encounters.
Of course this was a mod-added feature in PotC originally done by CouchcaptainCharles. Here is part of the relevant code:
Code:
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 ");
}
Most important seems to be this:
Code:
  // encountertype ? Rand(6) for now
   int enctype = makeint(rand(6) );
   int iNumShips = Fantom_GenerateEncounter(groupname, enctype, Encnation);
That selects an encounter type from PROGRAM\Encounters\Encounters_init.c .
I suspect any such feature in CoAS would also need that Fantom_GenerateEncounter call.
 
Ok thanks, at least now I can stop looking at that file thinking the answer lies in there some where. A shame there isn't a coder around for COAS, this was one features Jonathan.A asked if we should include it after he finished the direct sail features for GOF 1.2, but sadly it never materialised from there.:(
 
A shame there isn't a coder around for PotC either. Basically, it's just me and that's really not enough.
"Lucky" I am home for so long now, which of course was never supposed to be happening. :facepalm
 
A shame I don't have the time to put into learning how to put my own coding together and go from there, I would love to be able to do such things. Then I could really get onto trying to implement things I would love to see in COAS.
 
That's the only way I know of getting most stuff done: Doing it myself.
I only ever learned by doing as well, but now I nearly single-handedly sorted out some thoroughly complicated new, but unfinished code for PotC.
So it IS possible. To a certain extent.
 
I wish I had the time to commit to learning how to code, I know some but its very basic compared to the true coding. I can make sense of most of the stuff I look at, which is the most important part. But putting that code (if it wasn't there) in and making it work would be something I couldn't do. You never know, in time I might have more spare time to learn things and move up a little and be able to get a little more done.

Is there a site that is good for newbies? then I can bookmark the site and when I have some free time, look into it and start to get a better understanding of the code and what it all means. Once I understand how a code works I can then move on to trying to make my own code through trial and error.
 
There might be some useful stuff here: http://www.piratesahoy.net/forums/tutorials.86/
Also check "Documentation\New Horizons Tutorials & History.pdf" in PotC; that contains quite a lot of information on game engine specific information.

Other things that really help me out:
- Basing your new coding on copy-pasting of existing code that you know does something similar to what you want
- Add your game folder to the Windows Search Index so that you automatically and quickly search IN all files, then search for whatever springs to mind
- Last but not least, ask on the forum. I may not be the best coder in the world, but if I can point you in the right direction, I most certainly will :yes
 
Back
Top