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

WIP Use Generic Captain and Ship Generation Functions

Pieter Boelen

Navigation Officer
Administrator
Storm Modder
Hearts of Oak Donator
Code:
int GetCaptainRank(ref SCaptain)
{
   int shipclass = GetCharacterShipClass(SCaptain);
   //Class 8 ship should have a rank 1 captain. A class 1 ship should have something round a rank 40 captain.
   int rank = (8-shipclass)*7;
   rank = rank*0.8 + 0.3*rand(rank);
   rank += GetOfficTypeRankBonus(SCaptain.quest.officertype);
   if(rank < 1) rank = 1;
   return rank;
}
Again @Levis: Should this be based on the reverse of this function?
Code:
int GetShipMinClassForSkills(int iLeadership, int iSailing)
{
   int skillN = iretMin(iLeadership, iSailing);
   return makeint(8 - skillN*0.7); // PB: Allow Tier 1 Ships
}
So that the captain should always be good enough for his/her ship? At the moment I think that isn't the case.
At least it didn't use to be until this week, so you may run into captains who cannot really run their own ship too effectively.... :wp

For Quest Ships it does work the other way around:
The captain rank is determined first based on the player, then the resulting ship tier is based on the skills of the captain.
 
Code:
int GetCaptainRank(ref SCaptain)
{
   int shipclass = GetCharacterShipClass(SCaptain);
   //Class 8 ship should have a rank 1 captain. A class 1 ship should have something round a rank 40 captain.
   int rank = (8-shipclass)*7;
   rank = rank*0.8 + 0.3*rand(rank);
   rank += GetOfficTypeRankBonus(SCaptain.quest.officertype);
   if(rank < 1) rank = 1;
   return rank;
}
Again @Levis: Should this be based on the reverse of this function?
Code:
int GetShipMinClassForSkills(int iLeadership, int iSailing)
{
   int skillN = iretMin(iLeadership, iSailing);
   return makeint(8 - skillN*0.7); // PB: Allow Tier 1 Ships
}
So that the captain should always be good enough for his/her ship? At the moment I think that isn't the case.
At least it didn't use to be until this week, so you may run into captains who cannot really run their own ship too effectively.... :wp

For Quest Ships it does work the other way around:
The captain rank is determined first based on the player, then the resulting ship tier is based on the skills of the captain.
Might need some more tweaking indeed
 
Going to work on this soon so please provide comments
 
As long as the captains have Sailing and Leadership skills to sail their own ships, that should be good, I think?

Though perhaps intentionally having some captains "struggling with their commands" might be interesting too.
Anyway, that is of secondary concern. First step would be to get them in line at all. :cheeky
 
This bug made the whole "different random characters are generated in different ways" issue stand out quite notably:
Fix in Progress - Coast Raider Captains Receive No Weapons | PiratesAhoy!

But shouldn't "generate captain of random ship" not be a general function that can be reused no matter what?
Right now, I know that WorldMap, Coast Raiders and Quest ships are created 100% independently.
So maybe instead of just getting captains in line with their ships, we should broaden this feature request to clean up the whole "captain and ship generation code".

This may go as far as ensuring they all get appropriate cargoes and ALL are affected by the difference between war/trade/pirate ships.
Maybe even use GiveShip2Character to hand out ALL ships to ALL random characters.
That way we'd have single functions controlling everything, which would make things much easier to mod.
Might even make this feature here more feasible to re-enable: Planned Feature - Include Cannon Weight and Number in Cargo Capacity | PiratesAhoy!

Related functions are:
- GenerateQuestShip in quests_common.c - Rewritten by me a few years back so it is more reusable
- RandomCaptain in quests_common.c - Gets random PIRATE captain model without using the "model array" (ideally this function should not even EXIST!!!)
- InitQuestCaptain in quests_common.c - Does as it says and creates the captain. In a way that could probably be MASSIVELY improved
- Fantom_AddFantomCharacter in AIFantom.c - Used for worldmap encounters, now uses ClearCharacter to avoid CTDs caused by "reusing dead captains" (done by me a few months ago)
- SetCoastTraffic in sea.c - Used for Coast Raiders around islands, now uses ClearCharacter to avoid CTDs caused by "reusing dead captains" (done by me LAST WEEK)
- LoadShipsToSea in sea.c - Does a whole bunch of things that make me wonder WHY IS THIS DONE HERE??? Should that not be already done before?

This does have the potential to clean up the code quite nicely and give us much more control over what happens.
But as usual, it is also risky to rework such important core game mechanics.
Plus point though is that because it IS a core game mechanic, at least any errors would occur EVERYWHERE and we'd know something needs updating again.

Anyway, thoughts anyone?
 
I agree, but do we want it now or after the public release?
 
That's why I'm asking for feedback. Of course the response is deafening. :facepalm

We could figure that if things are technically functional, we can do this later.
But it IS quite messy and hardly ideal.
And I'm not sure what else we're missing out on right now.
 
That's why I'm asking for feedback. Of course the response is deafening. :facepalm

We could figure that if things are technically functional, we can do this later.
But it IS quite messy and hardly ideal.
And I'm not sure what else we're missing out on right now.
If I'm going to tie the captain to the ship rank I probably have to do this anyways because of my OCD :p.
 
If I'm going to tie the captain to the ship rank I probably have to do this anyways because of my OCD :p.
In the end, it WOULD be better if it all uses the same general functions instead of three separate and completely different ones.
Right now there is no consistency whatsoever, but it should really be "ship = ship".

So I can give no guarantees right now on if each type of captain is 100% correctly initialized.
Maybe good enough to not cause obvious errors now, but there can still be stuff missing that isn't obvious.
 
Okay, so @Pieter Boelen would you mind if after I'm back from vacation I'm going to revive my older mod for encounter calculation based on the island size etc. But this time implement it right.
When working on it we can take a look at ship and captain generation properly. I suspect I just rewrite it but copy a lot of existing code but make it readable etc.

I will try at the start to use completely different functions so we can add a toggle here so people can test this sytem but can also use the old system for now.

Agreed?
 
would you mind if after I'm back from vacation I'm going to revive my older mod for encounter calculation based on the island size etc.
You mean for the WorldMap Encounters? You know I like that mod and would definitely like to see it operational.
I'm pretty sure some of the related code has been quite wrong since the original game:
Awaiting Info - WorldMap: Serious Lapses in Coding Logic? | PiratesAhoy!
Doesn't actually harm the game, but also doesn't function as actually intended.

When working on it we can take a look at ship and captain generation properly.
If I think about it, the "captain generation" and the "worldmap encounters" aren't necessarily related.
For the sake of being cautious, would you consider tackling those two one at a time?

I will try at the start to use completely different functions so we can add a toggle here so people can test this sytem but can also use the old system for now.
Alternatively, maybe I should release Build 14 Beta 4.1 to the public BEFORE we start on large rewrites again.
Then we'll have the time for sure and we'll also have a stable base to revert back to, just in case.
 
The whole generation of ships and captains etc is pretty complicated. It doesn't help either that encounters generated during the opensea mod are done completly different compared to the ones on the world map.
I will take me quite some time to get this working, thats why I tought to program it the same like for example the collission detection. We can work on it and ask people to test it but for the public release we just disable it so we know it doesn't cause problems.
Altough I can understand you first want to do a release. So I could just look into the captain generation for now and do some other smaller things (like finishing the apothecary quest properly). If you want to do a public release in september I can wait :).
 
The whole generation of ships and captains etc is pretty complicated.
Yep, but only because it is handled differently in different spots of the code.
The only real challenge is that in some cases, you can generate the captain first, then figure out his maximum ship Tier, then generate a ship for him.
But for WorldMap/DirectSail encounters, the ship is generated FIRST, so generating a captain with the proper skills to be able to command her is going to be annoying indeed.

Other than that, it seems to me like it should be relatively straight-forward.
I made a start on this ages ago with the generic function to generate quests ships that you can find at the top of quests_common.c .
If I would do this, I'd use that as a base, but make it work for the other types of encounters too.

If you want to do a public release in september I can wait :).
I'm just thinking it would be a good idea to do that before starting on big stuff.
Since you want to start on the big stuff half August and I'll be leaving then, I *could* release Build 14 Beta 4.1 before that (so this coming weekend then).

But I'd rather not do that, since I consider releasing stuff just prior to leaving is bad practice (had some issues with people doing that at work last year :facepalm ).
So if I could convince you to focus on only fixing and finishing stuff this month, that would be great. :cheeky
 
I will try fixing some other bugs which pop up first and work some more on the apothecary quest and smuggling in general :).
 
and smuggling in general
I've got high hopes that part does actually work properly now.
We ran into various issues with it, but all the ones I know of have been tackled now.

Of course some people are still very uncomfortable with the new system (for example @Grey Roger and also Hylie Pistof when he's around),
so I'd say any further changes should probably approached with great care.... :ninja
 
You guys are amazing. :)

@Levis was working on having the level of captain depend on ship tier for directsail and coastraiders then? That sounds like a wonderful improvement, very exciting! I would love to see that implemented!

Will it also make military ships a bit tougher than trade ships, etc?
 
No work was done on that yet.

I think the GenerateQuestShip function that I wrote should serve as a good example for how it can be more "generic" (that function used to be several separate ones in the past).
Main thing that is annoying here is that the logic needs to be reversed.
For the Quest Ships, the level of the enemy is decided first, then it calculates the captain's skills, then what Tier of ship he can command and then generates an appropriate ship.

But in most other type of encounters, most notably WorldMap/Directsail, the Ship Tier is determined before the captain is created.
So that's the other way around, which means the captain would need to be Levelled up in a loop until he can actually command his own ship.

This does beg the question: What about captains being "too good" for the ship they command?
Should we want that?

Will it also make military ships a bit tougher than trade ships, etc?
Military ships can be bigger and bigger ships would get better captains and crews.
 
I think if it is a small chance, then captains occasionally being too good isn't a big deal at all, but it shouldn't be too regular.

I love this feature idea. :) blunting the degree to which the world levels with the player, and instead forcing the player to think critically about what challanges they are ready for, is a wonderful thing.
 
Back
Top