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

Linking cargo type to encounter type

:eek: hit a rather serious snag : the iGetEncounterType that saves the encounter type from the spawning in Fantom_GenerateEncounter seems to work well when running into encounters in the wild, but when generating ships outside harbors and around islands it always returns 0 as far as I can tell; Ive seen warships trace 0 as encounter type, which should be impossible because enc type 0 is traders only. SetCoastTraffic in sea.c (see dot see :cheeky) seems to be the one that puts them there. so got to add a check for if the SetGoods thing is ran from somewhere else that does not give an enc num I can save. it does send with it a character ref and the trader/war/pirate type, so its still possible to do some checks for booty that makes sense, but think its gonna be harder to do specifics :type1 @Mad Jack Wolfe, if you do any pirating you might wanna hold off any serious pillaging around the coast :p sail-ho and map encounters should be fine tho! xD

also had a discouraging encounter; I was playing a smuggler and sailing around in a small lugger. I got caught in a violent storm outside Hispaniola that almost ruined me, but it finally calmed down. that's when I saw a hostile spanish treasure galleon also caught in the storm, that had lost two masts and overall fared much worse than me. she surrendered as soon as I approached. I boarded her and killed the captain, but after all that the cargo hold was empty. I think I was fooled by the name honestly, and that it was generated as a coastguard ie war encounter and didnt imply infinite riches ;)
therefore it was probably because of
Code:
if (rFantom.FantomType == "war" && rand(100) > 15) randGoods = 0;
I'm considering adding GetCharacterShipType(rFantom) != "trade" to the if too; that way ships that are classed as both war and trade should still carry a bit of cargo even in a war encounter, but pure warships will mostly carry nothing. or make it so that the treasure galleon is exempt to avoid similar disappointments because of childish expectations :p or just leave it as is, not rewarding naivety? :shrug

gonna try and have a closer look at it later today when I find the time. any thoughts are still appreciated tho! xD
 
Indeed only world map/DirectSail encounters are created through those encounter types.
So quest ships and coast raiders are not covered.

I'm considering adding GetCharacterShipType(rFantom) != "trade" to the if too; that way ships that are classed as both war and trade should still carry a bit of cargo even in a war encounter, but pure warships will mostly carry nothing. or make it so that the treasure galleon is exempt to avoid similar disappointments because of childish expectations :p or just leave it
Looking at a ship's flag tells you whether it is a navy or merchant one, if that is of any help.
 
my plan is to set iGetEncType to -1 by default instead of undefined which I guess is 0, so if the switch case is -1 a different generic chance calc runs. something like this:
Code:
case -1: // Fantom_GenerateEncounter not run, do something else
            iBootyQuality = GOODS_QUANTITY - rand(iShipClass);
        break;
rn only ship class is considered. are there other things that should be accounted for?

Looking at a ship's flag tells you whether it is a navy or merchant one, if that is of any help.
it is! xD I didnt think of that!
 
Last edited:
Maybe whether it is a war/merchant/versatile ship? And perhaps Pirates should be an exception of some kind.
while traders and pirates already get a larger amount of the cargo they get, I think it aint unreasonable traders get more expensive loot too :ninja
Code:
case "-1": // Fantom_GenerateEncounter not run, do something else
            iBootyQuality = GOODS_QUANTITY - rand(iShipClass);
            if(rand(100) > 60 && rFantom.FantomType != "pirate"){ // for fun! better cargo potential for trader vessels
                if(GetCharacterShipType(rFantom) == "trade" && GetCharacterShipType(rFantom) != "war") iBootyQuality -= rand(round(randnorm(iShipClass*2,iShipClass)));
                if(GetCharacterShipType(rFantom) == "trade" && GetCharacterShipType(rFantom) == "war") iBootyQuality -= rand(round(randnorm(iShipClass,iShipclass/2)));
            }
            if(iShipClass > 5){ iStart += 6;} // lesser vessels don't carry the most valuble cargo
            else{
                if(rand(100) > 20) iStart += 2; // higher end ships could sometimes in a blue moon carry noble metals!
            }
        break;
the odds are a bit chaotic and arbitrary, but if I dun it right it gives pure traders a chance for fairly much better cargo, versatile ships get a chance for slightly better cargo, pirates and warship get the whole spectrum. ships lower than class 5 dont get the real treasures, better ships get a chance for gold and silver 20% of the time, they are the dream to aim for after all :sail direct sail and map encounters are probably still the juiciest catches, but coast ships should still be valid targets :dance

it doesnt seem to break straight away at least, so attaching the new version, lots of new traces included for testing! :pirate41:
 

Attachments

  • AIFantom.c
    35.7 KB · Views: 176
Great stuff @DeathDaisy , it seems to work as intended. :cheersMy first comment on balancing is I've hardly seen a "war" vessel getting cargo so I think the 80% exception too strong in the long term - indeed for balancing it might be worth commenting out completely whilst we see what goods a warship gets - then cutting down the odds of that later.:flower

I did lead me to wonder about boosting chest contents for warships rather than cargo but that would be a whole extra ball game - perhaps interesting none the less?
 
Last edited:
The original problem was to arrange that unescorted merchants have less valuable cargo, while single merchant with heavy escort should have more valuable cargo - does this deal with that?

Warships were never an issue, so the small amount of random cargo they get doesn't need to be changed.

Chest contents on warships probably don't need changing. Warships start with higher morale, so you're more likely to have to fight your way through several decks, looting lots of weapons as you go. On the other hand, if you grapeshot the ship into submission, chest contents still won't matter because you won't see them. ;)
 
The original problem was to arrange that unescorted merchants have less valuable cargo, while single merchant with heavy escort should have more valuable cargo - does this deal with that?
It should do. :yes
 
The original problem was to arrange that unescorted merchants have less valuable cargo, while single merchant with heavy escort should have more valuable cargo - does this deal with that?
it does! xD should be well worth targetting more dangerous marks now!:pirate41:


Great stuff @DeathDaisy , it seems to work as intended. :cheersMy first comment on balancing is I've hardly seen a "war" vessel getting cargo so I think the 80% exception too strong in the long term - indeed for balancing it might be worth commenting out completely whilst we see what goods a warship gets - then cutting down the odds of that later.:flower

I did lead me to wonder about boosting chest contents for warships rather than cargo but that would be a whole extra ball game - perhaps interesting none the less?
Thanks! xD

about the warships, maybe it is as @Grey Roger said, its fixing something that isnt broken. we'll comment it out for now. I still like the idea tho, it might be worth revisiting at sum point, specially together with the on-deck chests! its probably a whole different beast, but none the less it would be a cool thing to make up for the meagre cargo of warships. a chest full of crew salaries on a navy ship makes sense and is a treasure indeed:treasure:

I encountered the index error again yesterday. cant get to the logs right now, but I think it was when ecnountring an enc type 0 on the map. gotta take a closer look at that math and see how iBooty would end up as larger than 33. my spontaneous guess without looking at the code is that the -1 we removed in the rand(iBootyQuality - iStart) thing somehow causes iBooty to end up as 34 sometimes? gonna try it when I get the chance.
 
readded the -1 and encountered an enc type 0 and did not get array size errors, gonna assume that solved it! attaching what is hopefully a functioning AIFantom.c xD
 

Attachments

  • AIFantom.c
    35.6 KB · Views: 160
I encountered the index error again yesterday. cant get to the logs right now, but I think it was when ecnountring an enc type 0 on the map. gotta take a closer look at that math and see how iBooty would end up as larger than 33. my spontaneous guess without looking at the code is that the -1 we removed in the rand(iBootyQuality - iStart) thing somehow causes iBooty to end up as 34 sometimes? gonna try it when I get the chance.

Yes it's that array size - there are 33 goods but in an array 0-32 so using the 33 causes the array to go out of range when picking a good if the full number 33 is left by the random variable - hence the -1. Sorry I didn't check through the logic when I queried why one was being taken from the 33
 
Yes it's that array size - there are 33 goods but in an array 0-32 so using the 33 causes the array to go out of range when picking a good if the full number 33 is left by the random variable - hence the -1. Sorry I didn't check through the logic when I queried why one was being taken from the 33
no need to be sorry, I could have checked too and not just blindly remove it, so it was a team effort! :p now it seems to work like a charm, so thanks for all the input :cheers
 
I discovered this wasnt in the latest update and just thought Id report that I havent had any issues with it if @Grey Roger wanna include it in the next release xD
 
Would it be worth moving this thread to the Build Testing List ?
Of course some sort of encouragement would still need to be done for people to actually try it.
When we started the "Build Testing List", nobody really went ahead to test stuff, which sort-of defeated the purpose... :unsure
 
I've been playing a pirating game which, among other things, gave me plenty of opportunity to try this. Unfortunately, it doesn't work properly; one group of unescorted merchants which I attacked included a ship stuffed with gold, which isn't supposed to happen.

So I've written a simpler version. It uses the same global variables which @DeathDaisy set up, but only affects cargo on merchant ships, doesn't bother with warships or pure warship encounters at all, and only concerns itself with gold, silver, copra, bricks and leather. (There's little point in making an entire sliding scale of cargo types based on all the encounter and ship types. Export/import/contraband plus random price changes mean that actual prices vary a lot, to the extent that a cargo type may sell for a higher price in the store than another type which is several places higher in the cargo types list.)

At present, all trade ships (apart from those in Spanish treasure convoys) have a 5% chance of being treasure ships stuffed with silver or, if you're lucky, gold. In this version, ships in "Merchant" or "Group of merchants" encounters, i.e. those without escorts, are blocked from being treasure ships. Conversely, those in "Escorted group of merchants" have an 8% chance while "Single merchant with heavy escort" has a 17% chance.

Next, ships get random amounts each of a random number of random cargo types. Unescorted merchants have a reduced chance of getting gold or silver; single merchant with heavy escort has a reduced amounts of copra, bricks or leather, those being the least valuable cargo types, all with base values less than 4 per cwt.

Finally, trade ships have any remaining space in their holds filled with one random cargo type. Unescorted merchants can't be filled with gold or silver; single merchant with heavy escort can't be filled with copra, bricks or leather. I've tested this, too, adding several 'trace' statements to make sure it's properly detecting encounter types and doing the right things to merchant ships, and this one does work. So I'll probably put it into the next update. Meanwhile, if anyone else wants to try it, download this and put it in "PROGRAM\SEA_AI".
 

Attachments

  • AIFantom.c
    32.7 KB · Views: 188
Back
Top