Hey y'all! I have been toiling near-silently, producing my little Pirate Role Playing Game. But I have come across a philosophical query that my brain alone cannot solve. On each island there is a market, and players can build a fortune by trading between them.
I.e. Player Jimmy goes to Southsea and purchases 100 Wood for 100 Gold (for there is a forest on Southsea) then sails to Maenisle and sells the 100 Wood for 400 Gold (for there are few trees on Maenisle)
So far prices on islands are calculated as a Constant (foor the type of resource) multiplied by the fraction of the total amount of said resource that each island has. So if Southsea had 40% of all the Wood in the world, its price would be very low.
My question is this; how can I simulate the background production of Wood/Gold/whatever-resource into the merchants stock? Surely an infinate-loop is not the way to go, as they are the bane of all programming? How can I get my program to constantly add 1 Wood every three minutes to a Merchant's stock? If there are 20 Merchants in the world, each with 10 different resources, the overtime for lots of loops would build up horrifically would they not?
Also - any suggests with additions to my merchants system would be greatly appreciated, as I am no master (or even novice) in economics. *points to the ElecEng degree* =P
Many thanks,
~Ease~
ID:152103
Feb 18 2008, 10:48 am
|
|
Feb 18 2008, 10:58 am
|
|
Infinite loops aren't always bad. Isn't that why they were invented?
|
In response to Kaiochao
|
|
Aren't they a bi-product of the useful 'loop' ability. I've been out of the loop in regards to programming for a while, so I could be very wrong about the infinate loop subject.
|
var/const/updaterate = 600 You will need to call update() every time you need to check resources. However, over these time frames, an infinite loop is going to end up being more efficient. If you had to update resources every, say, 10 seconds, then this would be the better method. |
Ease wrote:
My question is this; how can I simulate the background production of Wood/Gold/whatever-resource into the merchants stock? Surely an infinate-loop is not the way to go, as they are the bane of all programming? How can I get my program to constantly add 1 Wood every three minutes to a Merchant's stock? If there are 20 Merchants in the world, each with 10 different resources, the overtime for lots of loops would build up horrifically would they not? Rather than using infinite loops, why don't you use a proc that still spawn a version of itself every 3 minutes? mob/NPC/storekeeper While it would still have the same concept as an infinite loop, it wont have any sleeps that still have the original proc stay in effect over a long period of time. Though that is still called for every storekeeper you place in the world. Another way is if you have the items in a list in each storekeeper, you could make it so that in the storekeepers New(), you add them to a list of storekeepers in the world, and then make a global proc on the world New(), and have that spawn it self every 3 minutes. What that would do it cycle through every mob in the shopkeeper list, have a look at the list inventory, and increase the amount for each value in the list, though that would work if you work with associative lists in a particular way. |
In response to Hassifa
|
|
Unless if you have a DAMN good reason (you don't), you should not use spawn() for infinite loops. It just creates MORE overhead. And it's still an infinite loop.
|
Ease wrote:
How can I get my program to constantly add 1 Wood every three minutes to a Merchant's stock? Just keep track of the amount of stock the merchant had at last purchase, and the time of last purchase. The next time someone checks to see how much stock the merchant has, then just check the current time against the time of last purchase to see how many "3 minutes" have elapsed since then. I think that's essentially what Garthor said, though. |
In response to Foomer
|
|
Yer, I think that's what Garthor said pretty much. Thanks very much all of you, especially Garthor and Foomer! Now to get programming!
~Ease~ |
As others have mentioned, only updating the island the next time it's visited is good enough.
As far as adjusting prices and such, I think your best bet here is to consider the larger world beyond just what the player does. For example, if you can buy 100 wood for 100 gold on one island and sell it for 400 gold on another, several things have happened:
|