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

Item Trading overhaul

NOTES:
All functions are at the bottom of Items_utilite.c
Don't worry; traders will be automatically assigned everything if you add nothing to their ch defines; you can add as many or as few extra attributes as you like and the functions will do the rest (see trader flags, below, for ways to control this).
You should, however, set ch.itemtrade.tradetype to one of the IT_TYPE defines in BS.h; right now only storekeepers and item traders are automatically detected, and only they, blacksmiths, and GENERAL (a `catch-all` default) have `auto-assign` support. But I provided a ton of IT_TYPE choices, and you can easily write your own cases in IT_AssignTypesToTrader(), using BLACKSMITH as an example.

Traders, items, and towns all share the same structure.
thing.itemtrade is the parent.
Then itemtrade.qty and .price for global scalars.
Traders also have itemtrade.quality. Note that items have itm.quality, not itm.itemtrade.quality!
itemtrade.types is the list of types (t0 through tX for types, i0 through iX for item IDs).

Structure
thing.itemtrade.types.tqty = X, where X is the number of type attributes (they will be t0 through t(`X-1`). iqty is for item IDs.
thing.itemtrade.types.iX or tX: (where X is the number)
*.qty = mult for qty
*.price = mult for price
*.quality = quality of that type of item
*.qualitych = change in quality for that type (i.e. -1 means trader quality -1 is the quality to use for this item type)

Qty of 0 means not traded (if you want the trader not to stock the item but still _buy_ them, set qty to 0.000001 or something).
Qty of < 0 means contraband.

Traders that have been talked to and given items have their IDs placed on an update list { ShipLookupTable.itemtraders.(ch.id) } and this tells the game whom to update each day.
If you remove a trader, make sure you also DeleteAttribute(&ShipLookupTable,"itemtraders."+ch.id);
If you only want the trader to not update for a while, do: string tmpstr = ch.id; ShipLookupTable.(tmpstr) = false;
And set back to true when you want updates to resume.

Item quality of 0 means ignore quality for rareness/qty calcs.

Instead of setting a type for general and qty -1, use itm.skipgeneral = true (for items) or ch.itemtrade.skiptype.general (for traders, see below) to skip general type

For a trader to obey a town's `not-trade`-items list, the trader must _not_ be set to skip town qty!

Traders may have the following flags:
ch.itemtrade.skiptownqty will skip multiplying qty by townqty
.skiptownprice ditto
.skiptownquality will skip adding town quality to trader quality.
{Note that this will skip both town size based effects but also town itemtype based effects}
.skiptype.town will skip adding the Town item type (for items that are sold more or less in certain towns--CCC suggested restricting artifacts this way).
.skiptype.island ditto
.skiptype.nat ditto, for nations
{Note, otherwise town, item, and nation types will be added, with the stats defined by their respective IT_AssignXXXType() functions.}
skiptype.general means trader will not sell items of general type.

Almost everything is tweakable by the IT_ defines in BuildSettings.h
 
<!--`QuoteBegin-NathanKell`+--><div class='quotetop'>QUOTE(NathanKell)</div><div class='quotemain'><!--QuoteEBegin-->The good news is, I finished coding the system. Last night, actually, but too tired to post.
[/quote]
Small wonder after such an achievment <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/onya.gif" style="vertical-align:middle" emoid=":onya" border="0" alt="onya.gif" /> Enjoy a well deserved brake <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
 
How're we gonna divide personal/group wealth, by the way? I mean, where will money come from for each and what can it be spent on? I ask because personal money is almost never used, so it just adds up and the only useful thing is to donate it to your crew.

My thinking is to tie personal wealth in with small carryable items, swords and jewels and such... so you buy them from out of your own wealth and get the money for yourself alone when you sell -- you're most often the one carrying them, after all. Then cargo, crew pay, officer hiring, etc. stays tied to group wealth.

Other good uses for personal wealth: paying to spend the night in taverns (and maybe raise the price a bit if we have a stamina bar and you _need_ the tavern to quickly recover), paying for other pleasures *cough*brothel*cough*, and then I already got the tattoos...

There's no accord on sword mending, though, and some people might vote for sword buying to come out of group wealth as well... so, `toggle-ables`.
 
IMO: I think that whatever is good for the group (swords, potions, other weapons) should be taken out of group funds... I think just about everything you can buy in the game now is stuff that should be purchased from group funds.

The answer to what needs to be done with personal wealth is, well... We need to invent something for it... Because in my mind, the only thing you need personal wealth for NOW is for buying those `un-enhanced` trinkets for the wifey - and she doesn't have a way to accept them!

Of course, Alan, you have a point there with the tavern and the brothel and the tattoos - but aren't the tattoos part of a character enhancement system that raises your crew morale and raises your own rep (or something like that)? Because if it goes to improve the GROUP, IMO it should be group funded... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/yes.gif" style="vertical-align:middle" emoid=":yes" border="0" alt="yes.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" />
 
CCC: Thank you. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/doff.gif" style="vertical-align:middle" emoid=":doff" border="0" alt="doff.gif" /> I meant it for the night previous, but it occurred last night as well. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />
And I have _yet_ to upload the darned thing.

Alan, Cat: I think, in my fevered, `mod-plagued` sleep, I've figured it ought. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />
Which is: You pay for the weapons you buy out of your own personal wealth _but_ every item you place in the chest (assuming there is a crewman to use it) you get wealth back from (but less than if you'd sold it).
That way your crew can reimburse you, and you not be forced to pay for their equppage out of your private wealth.

So basically you undertake to provide them weapons, and they reimburse you; but to keep you honest you only get money if there's crew to use the weapons.

With officers--I think we can use a similar system (since the interface is the same, itemsbox.c). We need to show the officer's money as 0 though so you can't steal it.

Cat: I think we should count on the player's generosity. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile2.gif" style="vertical-align:middle" emoid=":))" border="0" alt="smile2.gif" />
While in SMP _everything_ is out of the party's money, we have to draw the line somewhere I think, and better to use the wealth that way than to leave it, as you say, unused.

Eventually when we add businesses there'll be something to invest in, of course...
 
archive of my program folder upped as itemtrade.zip

Note: no items nor traders have types assigned yet! While it autodetects storekeeps and stall traders (I hope), that doesn't mean much because no items have types!
Also, for now, quality is randomly assigned, rather than based on the trader's level. However, towns with greater pop should have higher quality traders (to some degree).

All I did was set all items that have no set quality, to have a quality assigned based on price. Check the IT_QUAL_AW and AI (that's `auto-weapons` and `auto-items`) defines for how those qualities are assigned.

And like I said, it's slow. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />

Also, traders get more items than they should, probably. But again--you can tweak that too. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/happy.gif" style="vertical-align:middle" emoid="^_^" border="0" alt="happy.gif" />
 
Nathan, will we still be able to give the officers a custom sword? I mean, you want some to have different swords than others, perhaps based upon what you've found and upgraded at the blacksmith... Will you get the money for the upgrade at the blacksmith back, too?

This is, to my mind, overcomplicating matters. Are you sure this is what the game needs?
 
Hey, are you aware that initItems.c has grown by about 1700 lines ? Is all that your code?
Played a while and noticed the harddisk's active a lot. Is that what is slowing it down? And error.log is 839 kb.
Most of the errors are line 3498: missed attribute (quality) and line 1168: float function return integer value.
The first is because it's not assigned yet? The second seems to be stock code.
 
1700? Wow. No, I just took the one from Pieter's modpack, added a few quality assigns, and added a bit to the end of the InitItems() function.
Will check, thanks for the headsup! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/par-ty.gif" style="vertical-align:middle" emoid=":cheers" border="0" alt="par-ty.gif" />

Missed attribute quality--that's weird. On first loop in InitItems() all items are assigned a quality of -1.
 
Can we split that file up the way we split facemaker a long time ago? There're enough weapons to give them all their own file.

I like your solution on personal wealth buying swords... I consider this the same kind of thing as royal naval captains having to buy extra powder to practice, beyond what they were allotted. It's not "fair," but poop on fairness: you gotta put something in to get something out.

Cat, re: tattoos: As it is now you can only get tattoos for yourself, but maybe I ought to see if the answer for tattooing my officers lies in the tailorsmod files... Tatts, even on your own personal ass, don't affect rep or morale yet, just your skill count. So they need to remain a personal expense. Even anything at all that affects your rep should be personal, I think, though I know it affects your whole group indirectly... crew morale is group, though, I agree.
 
Oh, maybe you mean items_utilite.c? That's what the line 1168 reference points to.
Yeah, that's all the new code.

Problems are now (I hope) fixed; also, I found makeint was not doing what I wanted so I added a round() call to utils.c
Thanks!
Same file, same place. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/diomed.gif" style="vertical-align:middle" emoid=":dio" border="0" alt="diomed.gif" />
 
Alan: Hmm, Scheffnow already does this to some extent with separate gun and blade arrays for sorting...
Another thing is we can make `less-than`-average quality swords not buyable, only findable / stealable. I.e. traders will not sell you so bad a sword, but they will _buy_ such a sword (and fix it up). That will speed up paging through the item array by at least 2 (maybe 3).

In regards to optimizing my code, there are some things (now that I know it's so slow) I've thought of, i.e. instead of `re-getting` the town each time from name, passing the town as a ref each time.
That should take some time out, because I have three separate functions, called _at least_ once per item each, that all GetTown...
In addition, I can bake town item multipliers in on town update, so they're not recalculated each time, just read.

Also--I've been thinking that it'd be far better to simply have a `sorted-by`-rarity (but `trader-modified` rarity!) item array, and then rather than paging through the entire array and doing frnd() vs. rare tests, we just do additem(rand(array_size)) X times, and we're done.
It means more calculation at the start, but less each time.

The problem, of course, is that such an array would be trader specific (because traders have their personal multipliers, as well as locations), and would have to be recalculated every time something changes (i.e. townsize changes, thus qty changes).

As it is, I'm already not using the same amount of rigour in the update function (I simply gave up... <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/happy.gif" style="vertical-align:middle" emoid="^_^" border="0" alt="happy.gif" />), and was reduced to some simple Rand() statements.
 
Ah, I recall.
Another reason for the slowdown--specifically the slowdown _loading_ the game, which has nothing to do with this mod--is that I increased by 50% the size of the characters array, and also increased some other arrays (though they shouldn't make a difference speedwise).

In fact, we really need an _int_ CHARACTERS_QUANTITY so we don't have to go through blank slots. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/type_1.gif" style="vertical-align:middle" emoid=":nk" border="0" alt="type_1.gif" />
 
<!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->maybe you mean items_utilite.c<!--QuoteEnd--></div><!--QuoteEEnd-->
right
 
It's still only about 800 lines; the top stuff is (mostly) Scheffnow's. So maybe combined we're 1700 over stock?

Finished adding CHARACTERS_QUANTITY; that should significantly speed up new game starts and reinits (I hope).
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_eek.gif" style="vertical-align:middle" emoid=":shock:" border="0" alt="icon_eek.gif" /> My gosh, you've been busy! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/bow.gif" style="vertical-align:middle" emoid=":bow" border="0" alt="bow.gif" />
 
<img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/oops3.gif" style="vertical-align:middle" emoid=":eek:ops2" border="0" alt="oops3.gif" />
Yeah, but kinda fun. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:" border="0" alt="rolleyes.gif" /> <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/modding.gif" style="vertical-align:middle" emoid=":modding" border="0" alt="modding.gif" />

Wore me out something fierce yesterday though. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/icon_mrgreen1.gif" style="vertical-align:middle" emoid=":cheeky" border="0" alt="icon_mrgreen1.gif" />

To speed things up, I'm removing a few of the attributes. Now there's just one skiptown flag, not skiptown.qty, price, quality as separate.
Also removed the qualitych attribute, and changed the quality attribute to mean that, thus can no longer set absolute quality for traders for certain item types, just relative (+/- x in quality).
 
Good idea, I'd prefer not to see `low-quality` swords in all the shops... it's just more junk to scroll through. I'm glad we can now toggle off picking up crappy swords when we stab a guy to death.

(And that's about the only point in all this I feel qualified to comment on...)
 
Updated again, is much faster now.
Still takes a while to do daily updates, though. I have an idea there, though, which is to make a weighted list of items, and just do a blind rand() x times to add/remove items, rather than going through each item and doing individual item checks.

Note: I also fixed the annoying Reinit() delay on starting a game, and made reinit run behind the Loading... screen. NOTE: you will NOT see reinit text when starting a new game!

Oh, also, added `auto-dection` of blacksmiths, though currently none of them have dialog hooks for item trading. But if they did, they would have the appropriate type multipliers. <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
 
That's great, Nathan! <img src="http://www.piratesahoy.com/forum/style_emoticons/<#EMO_DIR#>/doff.gif" style="vertical-align:middle" emoid=":doff" border="0" alt="doff.gif" />

You WILL, however, see the reinit text when hitting the letter "I", tho, right?
 
Back
Top