Now I was thinking maybe I'd code a market

Need help testing contributed art or code or having trouble getting your newest additions into game compatible format? Confused by changes to data formats? Reading through source and wondering what the developers were thinking when they wrote something? Need "how-to" style guidance for messing with VS internals? This is probably the right forum.
Post Reply
oddeyed
Explorer
Explorer
Posts: 11
Joined: Fri May 29, 2009 12:43 pm

Re: Now I was thinking maybe I'd code a market

Post by oddeyed »

Hi RedAdder. If that post was directed at me (just thought I'd check, you didn't use my name), then thanks very much.

If I understand what you are saying, then it would be difficult to do that as it may have adverse affects on the economy. As such I can understand why you don't want to do that.

I cannot program and I don't have any idea how to edit the XML files, so if you want to do it anyway, go ahead, but I could not do it myself.

It was more of a feature suggestion than an offer to do it. :oops:

All the best, oddeyed.
RedAdder
Bounty Hunter
Bounty Hunter
Posts: 149
Joined: Sat Jan 03, 2009 8:11 pm
Location: Germany, Munich
Contact:

Re: Now I was thinking maybe I'd code a market

Post by RedAdder »

I just wanted to drop in and say I am still around. And though I am not working on the code at the moment, it would be pretty easy for someone else to pick up, the code is not "toxic", it works as intended, and I am there to answer questions.
Cheers
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

This feature is one I've heard a lot about and is linked in other threads. Yet, it has been ~3 years since this thread has been updated. Hence, yesterday evening I downloaded the code and decided to check it out.

It took me a while to get it compiled on my linux system. However, after I used the packaged scew source files and noticed the _main.cpp files included other .Cpp files (as opposed to headers and linking afterward), and removed an superfluous XMLEconomy::, I managed to get it to work.

I'm afraid I had to conclude the CodeBlocks config is a complete mess and does not work under linux well. Primarily because it specifies vc++ commandline options which gcc doesn't recognise (e.g. "/DEBUG"), secondly because it expects 'scew' to be somewhere on "D:\" (note, linux filesystems start at /, there is no drive letters).

Since it is the idea to have this in vegastrike at some point in the future (and the fact codeblocks' configuration didn't work well for me), I decided to port the configuration to CMake. I have also taken the libery to remove the expat files, move documentation into a 'doc' directory, removed codeblocks files and loose binaries (since expat is shipped with vegastrike and scew with this program, I highly doubt any devs would have a pressing need for a binary shipped with this package of scew or expat). Other then that, the program is exactly the same as the 0.1.3 version above. The code can be found at http://motherrabbit.foxserver.be/nido/market013nido.zip. (to compile: "cmake ." followed by "make" (though out-of-tree builds work too for who cares))

Feel free to pick this up and do whatever you want. Personally I'm looking forward to a vegastrike in which the trading aspect is more involved then finding a system with a factory with lots of cheap ai cores and an ice planet which pays ridiculous amounts for it.


regarding valgrind, on my system, factory_main takes 125ms to execute when redirecting output (so it won't take time to print the output to the screen), 3 seconds without output redirection. Running under valgrind takes 10 seconds with output redirection and 22 seconds without.

To summerise the output (main complaint is that stuff is not deleted):
==25101== in use at exit: 61,540 bytes in 691 blocks
==25101== total heap usage: 12,353 allocs, 11,662 frees, 371,302 bytes allocated
==25101== definitely lost: 3,760 bytes in 26 blocks
==25101== indirectly lost: 57,780 bytes in 665 blocks


I do have a few questions regarding this project though:
- What is the next step? Is this economy system good (enough to compete with the current economy?)
- How will players interact with this system?
- Can (/should) players (be able to) destroy an economy by "investing" in the right way (e.g. buy all the food, workers die because of food shortage)?
- I guess every world (planet/station/outpost) would be running their own private economy separate from the rest of the world around them, would this be correct?
pheonixstorm
Elite
Elite
Posts: 1567
Joined: Tue Jan 26, 2010 2:03 am

Re: Now I was thinking maybe I'd code a market

Post by pheonixstorm »

At the moment it hasn't been a high priority. Then again just about everything isn't high priority unless klauss or myself can get to it but neither of us have a lot of free time (and my coding isn't as good as his). Ideas and discussions are always welcome and putting together a nice econ model would be nice.

An extended idea I had on the econ side was *if* we can get a real MMO setup (that works) we could expand the game to include a VS traders app for Android that someone could log in to their account and do stock trades, commodities, or just higher freighters to buy and sell in different parts of the universe. Either way whatever we end up doiing it should be able to run flat file (xml) as well as SQL for the data. Single player would not need to track nearly as much so it could be far more abstract

As for your questions.
1. Find the correct working model that can handle single and multi play. So far though, anything is better that what we have running now.
2. We could wish for something like EVE, but thats a tall order. Just being able to have planets know what they can buy/sell and have AI controlled shipping to fufill these orders would be nice. The player could pick up the slack and have smaller freight contract as well.
3. Not directly. The player would not have the credits to do it for one, though this might get interesting for smaller colonies or mining bases. This might be more of running a blockade to get supplies somewhere. Don't do it fast enough and people die. But again it depends on how well we can eventually simulate the whole galaxy (and what kind of comp would this require).
4. Pretty much. They all produce some of what they need but not always, so its the basic import/export model.
Because of YOU Arbiter, MY kids? can't get enough gas. OR NIPPLE! How does that mkae you feeeel? ~ Halo
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

At the moment it hasn't been a high priority...
If there's a piece which you would think required higher priority feel free to suggest it. This seems to be a big job even if only because it depends partly on a very outdated version of scew (tried new library version, couldn't quickfix it).
An extended...Either way whatever we end up doiing it should be able to run flat file (xml) as well as SQL for the data. Single player would not need to track nearly as much so it could be far more abstract
Actually, I guess that such an app should not communicate with the economy directly, but rather have an interface within the vs interface itself. For example, you want to make sure an investment of 1M to _wherever_ would actually be deducted from the player's money in the same transaction or fail on both sides, right? you can't if a client can communicate with the economy directly.

Also, for sending ships around, I would suggest this would be an assignment to a ship, rather then the economy; the ship, in turn, must do it's own bargaining via the same interface as the player would. Think instructions as 'go to serenity, buy up to 100 gold for at most 130c each.'
1. Find the correct working model that can handle single and multi play. So far though, anything is better that what we have running now.
Okay, where can I find documentation about how single and multiplayer differ? I would've assumed it comes down to putting user input into a network packet at some point and waiting for the server to acknowledge, and possibly act like it didn't happen if the server refuses. In that case the server sould be responsible for the canonical economy and the client side would have no need to bother about it since it only interacts with the economy by buying/selling goods.
EVE
I'm an almost religious freetard, do you know some place that describes its system?
Just being able to have planets know what they can buy/sell and have AI controlled shipping to fufill these orders would be nice. The player could pick up the slack and have smaller freight contract as well.
This is actually a good idea. In how far does the AI already have the ability to bring specific "stuff" from point a to point b? Assuming it can, entities that participate in the global (or should i say universal) economy can just "order" the nearest producer to bring however much required to the destination.


Another major pain will probably be to save the state of the universe into the savegame. This would be necesary for the economy to have some significance, other then creating a certain begin state. You'll risk seeing just spawning loads of cargoships transferring whatever is needed first to wherever it's needed, or some poor fighter barracks can't get its food because you happen to explode and load the game again and again, erasing his requests for food whilst the in-game economy marches on.

One problem I have with the current vegastrike trading model is that a good is the always the same price at the same location regardless of other circumstances. secondly, the amount of resources around seems very scarce, even if you imagine they just offer you the 'excess' resources, i think there should always some food for sale somewhere, for example. Eventually, a player will probably incorporate save-quit-load into gameplay to reset the economy so some more trading can be done.

I think that in relation to this problem, after the economy is saved inside the game state, the volume of tradeable resources available to the player should be massively increased. This will make initial life for traders far easier since you'll have a lot more ore in serenity to bring to atlantis, but on the flipside, you can only do it _once_. It will make it more profitable in the long run to actually buy low and sell high, rather then to find the shortest distance between something with ai cores and something that'll buy them.

The economy in turn can dictate the prices at which stuff is bought/sold. Possibly one wants to lower the price at which one sells in relation to the buying price to encourage players to seek out places with significant price differences and explain it away as a form of VAT.
But again it depends on how well we can eventually simulate the whole galaxy (and what kind of comp would this require).
How many bases/planets/factories/whatevers are there in a regular vegastrike universe? We can make a guesstimation and see if we can create a benchmark for the market code included in this thread.
pheonixstorm
Elite
Elite
Posts: 1567
Joined: Tue Jan 26, 2010 2:03 am

Re: Now I was thinking maybe I'd code a market

Post by pheonixstorm »

nido wrote: If there's a piece which you would think required higher priority feel free to suggest it. This seems to be a big job even if only because it depends partly on a very outdated version of scew (tried new library version, couldn't quickfix it).
Bug fixing is high on that list. So is getting the new audio lib (klauss's SUCCS) into the game. Refactoring UNIT or whatever the massive mishmash is that runs most of the game.
Actually, I guess that such an app should not communicate with the economy directly, but rather have an interface within the vs interface itself. For example, you want to make sure an investment of 1M to _wherever_ would actually be deducted from the player's money in the same transaction or fail on both sides, right? you can't if a client can communicate with the economy directly.

Also, for sending ships around, I would suggest this would be an assignment to a ship, rather then the economy; the ship, in turn, must do it's own bargaining via the same interface as the player would. Think instructions as 'go to serenity, buy up to 100 gold for at most 130c each.'
The app would just be an extension of the economy, just on a larger scale. More like buying and selling enough goods to fill a fleet of freighters. This would only be for the MMO version as SP would not have a persistent econ. Same with some type of stock exchange. Its just another aspect of the game I had been toying with. I don't think it has been tried. The closest to it would be the web interface for the World of Warcraft auction house (though I have never used it).
Okay, where can I find documentation about how single and multiplayer differ?
They don't. Then again there are alot of issues with mmo play such as if you buy a new ship you can't launch w/o exploding. Another is the fact that there are no other ships around.
I would've assumed it comes down to putting user input into a network packet at some point and waiting for the server to acknowledge, and possibly act like it didn't happen if the server refuses. In that case the server sould be responsible for the canonical economy and the client side would have no need to bother about it since it only interacts with the economy by buying/selling goods.
In either case there really isn't an economy for the server OR client to interact with. For the most part (my thinking anyway) is that TCP should only be used for inside stations were resending packets is more practical. Most high action fps games (and some/all mmos) use mostly UDP and just cram as many packets down the pipe and try to reorder them when they get to the server (or worst case don't process the late arrivals). TCP is slower since it must have an acknowledgement that the packet arrive in good condition before sending the next one.
I'm an almost religious freetard, do you know some place that describes its system?
You really should have a go at the 15-day trial if you are on windows, or have a windows machine. The entire economy is player based, but you can access nearly every aspect of the games markets via the multitude of server apis. With eve you can mine, manufacture, research or just destroy and buy stuff off the market. Every aspect of the economy is generated by something the player does. The dev blog at eveonline.com has a treasure trove of information on how the game is setup (majority is python).

Check out http://www.eve-markets.net/ http://eve-central.com/ or http://www.battleclinic.com/ for some information on various topics.
This is actually a good idea. In how far does the AI already have the ability to bring specific "stuff" from point a to point b? Assuming it can, entities that participate in the global (or should i say universal) economy can just "order" the nearest producer to bring however much required to the destination.
I had thought about setting up something that would mark each planet type with a certain number of goods. Alas, I am falling asleep at the computer so I will have to finish this in the morning.
Because of YOU Arbiter, MY kids? can't get enough gas. OR NIPPLE! How does that mkae you feeeel? ~ Halo
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

Bug fixing is high on that list. So is getting the new audio lib (klauss's SUCCS) into the game. Refactoring UNIT or whatever the massive mishmash is that runs most of the game.
Yes, Unit seems to be _the_ master class of vegastrike. I've taken the liberty to generate documentation out of the svn source using doxygen. Check the unit class collaboration diagram on http://motherrabbit.foxserver.be/nido/v ... sUnit.html as evidence for your claim.

http://motherrabbit.foxserver.be/nido/vegadox/html/ is the documentation root filesystem. motherrabbit may go down quite soon, so check it out this week if you're interested. I may serve the files again it once motherrabbit is relocated.
The app would just be an extension of the economy, just on a larger scale. More like buying and selling enough goods to fill a fleet of freighters.
I argue this would _still_ be something done through the regular (programming) interface. The rest of the vegastrike universe can do it's thing whether or not the player interacts or not. The player may be(come able to) influence the economy by buying and selling certain items at certain quantities, but it would not be like being part of the economy itself. (rather, the 'real' economy would be the collection of the calculated economy and the player(s) actions.
This would only be for the MMO version as SP would not have a persistent econ.
Why, save unrealistic system requirements, not? Why shouldn't offline single-player players have a complete economy running around them? Why would we want to maintain a separate single-player economy and how would they be different?
In either case there really isn't an economy for the server OR client to interact with.
not yet, but aren't we more or less designing it here now? regarding the actual protocol used, isn't something in place right now? I though the server-client part of vegastrike was already reality.

I don't personally have much interrest in the actual networking protocols that will be used, though if you must know, I think there may be use for a tcp-only mode for situations where udp is unworkable. An example would be wireless ISP's who have their own NAT before it even reaches the client, where you won't be able to set up a bidirectional direction with udp easily.
Another suggestion if you are looking into the network aspect would be enet. Apparently it is a network protocol especially designed for games communication. It may be a workable solution that allows us to not cook up out own.
I had thought about setting up something that would mark each planet type with a certain number of goods. Alas, I am falling asleep at the computer so I will have to finish this in the morning.
I was waiting for the rest of your reply but in absence, let me extend on my own idea: A 'base' (a planet, star station, pretty much anything dockable that is not a capship) would be a unit within the economy. It would have a number of factories turning resources into different resources.

For example, any given base has a 'population factory' which consumes food to maintain a population. too much food and the population grows, too little, and it shrinks. population is needed to operate the other factories. Even in the futute we would need at least some people monitoring the production process and fixing what breaks, right?

Bases would also have 'factories'. Factories produce goods provided enough people are available and, depending on the factory, whether input goods are available.

Some would produce goods for 'free'. For example, farms and ore mines would not need anything to grow or mine the goods. Some bases may be better then others in generating output. For example, oceanic, bio-diverse planets and agrocultural stations may be most efficient in generating (human) food. Astroid mines are great for mining ore. Fighter bases, Shipyards, Diplomatic stations, on the other hand, not so much.

Then there are factories that take goods from other factories and use them to make other goods. Ore may be transformed into alloys and metals; those may in turn be turned into other goods by other factories, etcetera, etcetera.

If this is implemented and every base has their own infrastructure (which will still be severely broken since for example fighter bases will not get their base goods of which to make their fighters), we can link them together in a cooperative setup. I see no reason why a faction's bases wouldn't supply other bases. If, for example, a rlaan factory (as in, the spacestation) would want to have ore (which, as a block of metal in space, it couldn't logically produce) in order to create hull patches, it could send out that request to the global rlaan economy, which would work pretty much as the code redadder so graciously donated. A ship would then be dispatched from the cheapest source and bring the required cargo on its merry way. Or maybe the source planet keeps it back for a while, keeping a mission open for potential players who happen to go in that direction or some other orders with the same destination hoping to full an ox to go that way. Eventually, some way or another the cargo gets transported to its destination, and the factory can do it's producing.

Players would not have complete access to all cargo available on a base. No farmer would be stupid enough to sell his all his food if he knows he can't harvest new or get inported food before he would need to eat. Also, if I hate you, no way am I gonna sell you a cloaking device. Maybe some food after i spat on it. And no discount either. If you're friendly with my faction, however, that may do wonders for the sales price; and I may sell you some of my reserves as well.

For the sake of argument, let us say 10% of the local economy's products are available to the player at first (be it the player in his ship, a fleet of oxen sent via a webapp on her behalf, whatever). If you are 100% friends with a faction, they may be willing to sell up to 50% of their resources. Regardless of this, the base should keep a supply to keep their factories running until the next shipment comes in. So even if a factorybase has ten ore around, no matter how friendly you are, they aren't selling because they need them to turn them into more expensive hull plates. The price is as dictated by redadder's algorithm, plus/minus (depending on buying/selling) an amount for, say, space-VAT, and some modification depending how much you are liked. Perhaps some discount for larger volumes is in order. Let us worry about the programmer and graphical interface specifics later.

In order to make an effective blockade, you just need to make sure you make sure you block incomming traffic long enough for the draught of resources to drain a base. When that happens, it will no longer be producing new output and to the faction controlling faction it becomes a sink of goods and ships; even worse then just destroying a base. This also means one can use ones financial strength to influence the position of factions in relation to eachother. Turn economies to dust by flooding markets at the right times and making sure certain ships cargo never arrive.
Deus Siddis
Elite
Elite
Posts: 1363
Joined: Sat Aug 04, 2007 3:42 pm

Re: Now I was thinking maybe I'd code a market

Post by Deus Siddis »

nido wrote:
pheonixstorm wrote: This would only be for the MMO version as SP would not have a persistent econ.
Why, save unrealistic system requirements, not? Why shouldn't offline single-player players have a complete economy running around them? Why would we want to maintain a separate single-player economy and how would they be different?
In MMO parlance, "persistent" means that when you quit the program and turn off your computer, the simulation still continues on a server somewhere, 24 hours a day 7 days a week. It is a step further from the save game storing the state of the economy when you quit and loading it when you next run that save game (which of course is a must-have). But honestly, somehow turning vega strike into an MMO is an imaginative pipe-dream unlikely to ever happen, in the first place.

What we want and need most is a dynamic economy that works for single player. If it is compatible with multiplayer that is just icing.
I was waiting for the rest of your reply but in absence, let me extend on my own idea:
...
...
Your proposal seems to me to be in line with what many others have suggested and the general consensus on how the dynamic economy should work.

An additional consideration, which you might already have covered, is the loss of production and transport infrastructure. If a planet gets captured, an agriculture base gets destroyed or the local Ox fleet is sacked by pirates, the economy has to be affected. Both by short term changes like rerouting transports and militia and increasing price differentials and by the long term process of producing replacement infrastructure (new Ox transports built and deployed, a new agriculture base slowly constructed, more combat units produced and deployed to tighten local security).

Basically, dynamic warfare and the serious destruction and shifts it causes is a major part of the world of VS, so the dynamic economy has to interact with it in a deep way.
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

In MMO parlance, "persistent" means that when you quit the program and turn off your computer, the simulation still continues on a server somewhere, 24 hours a day 7 days a week.
If you wish to have this feature in single player, one can emulate it by having the game loading algorithm step through the economy to simulate having ran whilst the program was off. A more faithful version would be to have it run on your own server idly regardless whether you are logged in or not.

Regardless, the percistency I was referring to was save-game percistency. At the moment the amount of available goods are calculated when the game is started. It would be nice to see the results of your trading after you restarted your computer, even if it is just because you took a hundred trips to move all the food to atlantis' fighter base. I believe the problem with save game percistency at the moment is that of the save game size, hundreds of bases times tens of factories on them means thousands of lines and is gonna fill up the savegame considerably; and thats only assuming hundreds of bases. Still, that doesn't negate the possibility.
new Ox transports built
Actually building ships/weapons would be step three. In the beginning I think we'd still automatically spawn ships when needed. Another thing I was considering, what kind of input/output should the factories have? Is there already some ideas on this?
Deus Siddis
Elite
Elite
Posts: 1363
Joined: Sat Aug 04, 2007 3:42 pm

Re: Now I was thinking maybe I'd code a market

Post by Deus Siddis »

nido wrote: It would be nice to see the results of your trading after you restarted your computer, even if it is just because you took a hundred trips to move all the food to atlantis' fighter base. I believe the problem with save game percistency at the moment is that of the save game size, hundreds of bases times tens of factories on them means thousands of lines and is gonna fill up the savegame considerably; and thats only assuming hundreds of bases. Still, that doesn't negate the possibility.
It is certainly worth the cost. If the economy resets whenever the player quits then this isn't any better than a static or purely random economy.
Actually building ships/weapons would be step three. In the beginning I think we'd still automatically spawn ships when needed.
Phased development is a good approach for a task this large.
Another thing I was considering, what kind of input/output should the factories have? Is there already some ideas on this?
What do you mean exactly?
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Re: Now I was thinking maybe I'd code a market

Post by loki1950 »

As in economic inputs(raw materials)and outputs(finished goods) each type of base will have differing inputs and outputs and a role within the economy.In other words each component the system has to play role in the overall economic model.

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

Loki is correct. However, I Think we'd want to go deeper then a per-base setup and define a per-factory economy. A base can have multiple factories of different types, and a factory has only a single output. This will make it easier to have bases grow in production more easily (just add a factory of the good you wish to create more of). In the long run, it may even allow the possibility of starving bases or production processes by destroying the right factories on the right bases in the future.
Deus Siddis
Elite
Elite
Posts: 1363
Joined: Sat Aug 04, 2007 3:42 pm

Re: Now I was thinking maybe I'd code a market

Post by Deus Siddis »

Ah, well in that case I would say don't worry about it; the economic simulation should be agnostic to those kinds of details. That stuff is just data, which will need to be defined in pure-data files such as XML or CSV or at least in python, for easy editing without recompiling. You should just throw in whatever data you need to test your system.

Just getting the system working in game is a major task. This may be especially true when it comes to integration, which can be a noteworthy stumbling block due to the messy and undocumented state of the engine, as well as the python modules that appear to be home to most of the dynamic universe. So IMHO, you are best off focusing on the design of your economic simulation at an abstract level and then getting it fully integrated as soon as possible.
loki1950
The Shepherd
Posts: 5841
Joined: Fri May 13, 2005 8:37 pm
Location: Ottawa
Contact:

Re: Now I was thinking maybe I'd code a market

Post by loki1950 »

Ah, well in that case I would say don't worry about it; the economic simulation should be agnostic to those kinds of details.
Sorry Deus but that is not the way to do it period with out those definitions it just will not work as that is what an economy is.And if you you want to simulate one that is what you define first besides they are already there as what each base will buy and sell in the units.csv nido there is a utility for editing units.csv it used to be in the tools and utilities sub-forum but pheonixstorm trimmed that sub-forum so PM me and I will send it to you :wink: windows or Linux.

Enjoy the Choice :)
my box::HP Envy i5-6400 @2Q70GHzx4 8 Gb ram/1 Tb(Win10 64)/3 Tb Mint 19.2/GTX745 4Gb acer S243HL K222HQL
Q8200/Asus P5QDLX/8 Gb ram/WD 2Tb 2-500 G HD/GF GT640 2Gb Mint 17.3 64 bit Win 10 32 bit acer and Lenovo ideapad 320-15ARB Win 10/Mint 19.2
Deus Siddis
Elite
Elite
Posts: 1363
Joined: Sat Aug 04, 2007 3:42 pm

Re: Now I was thinking maybe I'd code a market

Post by Deus Siddis »

loki1950 wrote: Sorry Deus but that is not the way to do it period with out those definitions it just will not work as that is what an economy is.
You are thinking far too literally about this. The code that simulates a dynamic economy is not an economy. It is an abstract system to simulate a factory that takes commodity(s) A and converts it into commodity(s) B in ratio R at rate T (this is an example, the actual code would be more complex). It then determines the prices to buy/sell commodities A and B for based on the local supply of them.

Then in the data you define the names of the factories and their A's, B's, R's and T's, and you assign those factories to the units that house them. You could define a factory called "ore refinery" that consumes "nickel-iron ore" (A) and produces both "nickel" and "iron" (B) at a ratio of 10-to-1 (R) at a rate of 10 cubic meters per minute (T).

Defining the initial data is trivial, though it may have to be balanced over many versions so it should be in a format that is easy to change. But the code, the framework for a dynamic economy, does not yet exist in the vega strike engine and integrating the former into the latter could easily be a big job that all of this depends on. So that is why I would suggest making the code and its integration the first objective.
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

So that is why I would suggest making the code and its integration the first objective.
Do I have good news for you, Deus. Code which creates such an economy already exists, which is redadder's code. We've got the factories and a way of having them interact with each other. I think the quickest way to integration is to first make each base its own economy, and have it generate the amount/price of goods available.

Whilst redadder's examples run a default simulation with food and population, creating a vegastrike with only those resources would take away a lot from the experience in my opinion. Rather, I think we put some effort into thinking up an economy which we can run using redadders code, so when we get the code to work within vegastrike, we could actually have a vegastrikarian economy.

The task of thinking up a believable number of iron ore one needs to create a hull patch is a completely different one from making the economy simulation itself work with vegastrike. To me personally, the latter seems easier then the former, but I am sure there are people who think otherwise. I would like to invite them to post their suggestion of what resources will create which others, and what kind of modifications the different types of bases should have. If we could create each of http://wiki.vega-strike.org/Cargo from others within the collection, that would be great!
besides they are already there as what each base will buy and sell in the units.csv
Does vegastrike reload that file every time the buy screen is accessed? In that case this tool may be of use. May I suggest you host it somewhere and post a link to it on this thread instead of linking it only to me via pm? There may be other people interested in looking into the problem should I not be up to the job or unavailable.

Ignoring indirect concequences, the way the player ultimately/initially interacts with the economy is via the buy screen, so I believe that after implementing the economy, units.csv is bypassed by the new code in regards to item prices. Nevertheless, that leaves the task of locating the buy/sell screen, understanding how it works, and how to feed it the new information.


After this is done, the player is immediately capable of changing the state on a planet by buying/selling goods. If I observe correctly, at the moment, single player just has random and preprogrammed ships with random or preprogrammed cargo, which after reaching their destination, go somewhere else, having no influence whatsoever on other entity's cargo, unless they destroy it alongside the vessel it is in. The next step would be to dispatch ships from one place to another; and improving the economy to take into account that ships take time to arrive and may not reach their destination.
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

Looking at the doxygen documentation in regard to where one might interface with the buy screen; and it seems Unit::SellCargo and Unit::BuyCargo should be the functions affected. Mind you I came to this hypothesis by evaluating call graphs and caller graphs, guessing function names would describe accurately what they do. Taking a closer look at the call graph to Unit::SellCargo ( http://motherrabbit.foxserver.be/nido/v ... cgraph.png ) gives me the distinct impression this 'sells' cargo from the perspective of the base, mostly because it references CanAddCargo, whereas BuyCargo does not contain this function. This guess is from experience it seems that bases can store a virtually unlimited (perhaps INTEGER_MAXVALUE or another system imposed limit) number of cargo wheareas the player's hold is space-limited. Also there seem to be multiple instances of the Unit::Buy/SellCargo functions, and some, including the one I linked seem to be unused at first glance. If anyone has experience with said functions, I'd appreciate any information.

Pheonixstorm already mentioned an overhaul of Unit would be prudent and considered a higher priority as implementing the economy itself. This doesn't mean though that both actions cannot coincide. The best way forward in regards to implementing this function may be to proceed with the unit refactoring with as goal to have a sane buy/sell interface. Tangently related is the issue of transporting your own weaponery. A Llama can carry about 4 FOF torpedo's in it's launcher. When I'm flying around with the objective of blowing everything i can find into oblivion, I'd like to take a 'few' missles in my cargo bay and deploy them into the missle tubes 'myself', rather then to sell the cargo to the base, and buying it back in the upgrades screen (aside from the fact i am not sure 'cargo' munition and 'upgrade' munition are actually from the same munition pile).

Nevertheless, this is not directly related to the economy upgarde. Ship upgrades can stay untouched with regards to implementing the economy in its next incarnation and be fixed into the economy later. Nevertheless, I wonder how much of this is all used by mods and how important it is to keep the old (api) interface working. Any information about the UNIT refactoring in general would be apprecicated. IS there already a thread around somewhere discussing this endavour?
Deus Siddis
Elite
Elite
Posts: 1363
Joined: Sat Aug 04, 2007 3:42 pm

Re: Now I was thinking maybe I'd code a market

Post by Deus Siddis »

nido wrote: Any information about the UNIT refactoring in general would be appreciated. IS there already a thread around somewhere discussing this endeavor?
There's been some discussion: 1 2
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

I've taken the liberty to remove the different classes into their own files for clarity. I have also included a Doxyfile which will generate extensive svg graphs for people so inclined. You can find the result at http://wardenscat.foxserver.be/nido/market014.zip

Nevertheless, there is an issue with this economy of which I am uncertain of how to address this. Apparently, after running the example economy from factory_main for a bit, it will eventually crash because an assertion fails. I have reverted to the original version from redadder, but this left me with exactly the same results. Though this boosts my confidence in my ability to split big files into smaller ones, this still leaves an undesirable state in the economy. This assertion has to do with a certain population having positive money.

Unfortunately, I do not truly understand the the model on which this simulation is based. This is probably more related to my lack of knowledge of economic models rather then an error on redadder's part; yet this leaves trial and error to extract the errors in the economies and hope our N test runs are enough. This becomes an even more pressing problem when the player can interact with the economy. Unwillingly or intentionally, with the current code they can propel themselves into situations which inevitably lead to an insane economy segfault.

Disabling the checks is easy enough. One insane economy may not be a problem, but interacting with eachother, they may infect each other creating insane economies everywhere for everyone, leaving seemingly random unrelated price fluctuations everywhere. The real solution to the problem, in my opinion, is to build in safeguards which makes such a situation impossible.

Another quirk I noticed is that there seems to be no record of goods. One particular example is "unused lands". Whilst one can imagine its relation to "lands", the simulation is not fed with a direct relation, nor seems to have a concept of a relation between "unused $x" and "$x". Yet, "unused lands" have a price. This, on its own, is no problem though, and one can imagine wanting to pay at most X for an unattainable product.

However, it seems that the market operates without reserves of their own. Whilst factories (rather, economic sectors) have reserves of their own, the market seems to be completely devoid of products on its own. A solution perhaps would be to have 'trader' factory which interacts with the player, but i think this would need not fit within the current structure very well.

At the current state, I think this is an interesting economy simulation, but it may be too big for inclusion within vegastrike. This code simulates a complete economy, but vegastrike players never interact with a complete economy itself. Because the player interacts with the economies underpinnings, the state of the global economy can never be guaranteed. Perhaps this code can simulate the economy on a single base. In this case, economies need to be able to interact with each other. Perhaps a market with 'fees' for transportation of goods. But would that be a flat rate? in system flat rate? Regardless of our choice, I do not know how to implement such in the current code/model.


If someone more literate in economy would like to step up and explain the current code i would be most grateful. If you are such a person, but do not know much of computer code, I would still like to talk to you through mumble/skype/irc and discuss the subject. This simulation may still be very interesting to vegastrike. Alternatively, a simplification may make additional features easier to implement, and still give the experience to the player.

For example. Say we reduce factories to a class which can produce a bunch and amount of goods X Y and Z (or howevermany), given goods A B C... (you get the point).
Now, lets have a base, which is a collection of these factories. Perhaps different factories for different bases, or bases having inherent modifiers for types of goods produced. Using the latter, one can create many slightly different 'economies' on bases by adding/removing efficiency for certain factory types according to different factors (e.g. type of base, owner faction, proximity to a star). These 'economies' have no sense of money though. Still, leave these running forever and you'll have bases with infinite of goods they produce faster then they can consume it, we need an upper limit. Conceivably, bases are ruled by governors who think there is really no need for a hundred million trillion astral gases on an oceanic planet, (even if said governors aren't individual persons for some factions). Said governers are not part of redadder's code but could initially be coded as dumb as hardcoding a maximum number of goods available on-planet.

As a sidestep, bases or individual factories could perhaps also be equipped with upkeeps, the ability to place more factories of the same kind, creating optimal and suboptimal development possibilities; even leaving open an option for an enterprising coder to have players take actual control of player's own bases/planets economy for those who want to.

All in all, even leaving out the sidestep, this would lead to economies which would work, assuming some of the factories produce input goods out of thin air for the others. Even then, all this really generates is a number of goods on a base. However, we have a supply (available input goods) and a demand (how much to consume); I'm sure there is a function which outputs a reasonable output price, even if given an 'inherent' or 'base' price from units.xml.

Also, I suggest a trader is placed in between the player and the economy. The player only deals with a portion of the goods available on the planet. Even in reality some is bound to be cought up in prearranged businessdeals and some people just don't like you enough to sell theirs. Nevertheless, this trader can take the derived prices, and whatever is defined as 'excess' goods (whatever someone would trade with another i think is a discussion worth having. I have no idea for an initial answer at this time), and give the player a variable price. Another advantage to this approach is that current players get to keep prices within the established price range. Perhaps a better algorithm for a product's inherent price could be divined by someone later.

Part two, bases get their own cash reserve and may interact with eachother each economic turn, filling their input reserves at their preferred buy price, selling at their preferred selling price, adding a transport fee to the costs. Part three, ships deliver the goods. Part four, those ships need to be made out of parts first.
Deus Siddis
Elite
Elite
Posts: 1363
Joined: Sat Aug 04, 2007 3:42 pm

Re: Now I was thinking maybe I'd code a market

Post by Deus Siddis »

Sometime ago star citizen released a summary for how their dynamic economy will operate. Such might be a good complexity level to shoot for, i.e. not too complex at all.

For example their solution to overproduction, much like yours, is to have a storage capacity at a factory and once it is filled with unsold products, production halts. And probably the price for said products is then set close to production cost until capacity is freed and production resumes.
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

In my humble opinion, the description in the link you supplied basically describes the factory in pretty much the same way we have already defined it, and the video describes the idea we mentioned to missions and ai flights. Whilst the second part isn't implemented yet, the factories provided by redadder already do as described in said video. At this point we have the economy simulation which redadders factories are a part of; which in comparison to the star citizen description is abstracting the actual happenings in regard to transport. The part undescribed in by star citizen is how the prices are calculated the products produced
Deus Siddis
Elite
Elite
Posts: 1363
Joined: Sat Aug 04, 2007 3:42 pm

Re: Now I was thinking maybe I'd code a market

Post by Deus Siddis »

nido wrote:In my humble opinion, the description in the link you supplied basically describes the factory in pretty much the same way we have already defined it,
Ah, so then the simulation is straightforward on a small scale, but when run with no upper limits little imbalances lead to runaway growth? And so eventually the simulation is trying to track a billion trillionaire market participants?

It is not a terrible thing for the simulation to have hard upper limits. The game essentially already has these in many areas, like a fixed number of star systems and probably a maximum number of ships and flight groups allowed to be at one time. So there is no reason the economy should be potentially unlimited.

You will probably also need some clever soft controls to keep the market from hitting a hard limit and staying there indefinitely. The farther something gets away from a fixed ideal value, the stronger a corrective force needs to be.

And localized economics through transportation costs should be important. What happens in one solar system should have almost no influence on a solar system X jumps away. (Where X may be determined largely by play testing, so it could be 2 systems away or 10.) When you have enough localization you can get away with much wider market variation, in fact it is desirable.
The part undescribed by star citizen is how the prices are calculated the products produced
I imagine the central factor in determining price is the percentage filled of a factory's local storage capacity by the product. A lower limit on price would be determined by current raw material costs. So when the factory is at full capacity, production stops and the product is sold at cost. What is less clear is how to set high prices when operating at a small percentage of capacity.

You could have a hard upper limit, whose in-game explanation would be government economic regulation. Eventually each faction might have its own enforced upper limits on pricing, like the andolians might allow up to double the production cost whereas highborn allow up to ten fold.

Another option is to have a normal or target percentage of storage capacity the factory tries to fill, maybe half capacity. Each simulation step, the sale price is raised when the stock is below half capacity and lowered when it is above it. The rate of price change is also proportional to how far away the stock is from half capacity. With this method, you still have a hard lower price limit due to production costs, but no hard upper price limit.
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

Now I've been playing around with reimplementing the simplified version and at the moment I have an Economy which consists of Bases with Factories which can produce Cargo, and something which can create economies of random bases with random cargo using the master part list from vegastrike.

It is still a long way from being useful as at the moment this creates random factories, and no government over what is produced and what isn't is implemented and no trade happens. Also, comming from a more C background I've messed up class and function design a tad turning it into a sieve, but I believe this is fixable. Nevertheless; I wanted interested parties to behold the result. This package compiles a file named 'bigtest', which can run a number of turns of the economy. it basically works like this:
./bigtest $number_of_turns $number_of_factories_per_base $number_of_bases
# bear in mind, factories_per_base is randomised so averages out to about half.

on a i3 2.27ghz core doign 100 turns with 100 factories per base, and 10000 bases takes about a minute. 12 seconds of these are building up the economy, and the total memory usage is about 1GB. Some of these figures can probably be optimised out refactoring but even so i believe that aside from the memory usage this is pretty workable as I believe an economy update should take several minutes. I would need to know actual universe size to do more proper measurements but at this stage i believe it looks rather promising.

http://wardenscat.foxserver.be/nido/market015.zip
nido
Merchant
Merchant
Posts: 43
Joined: Tue Sep 03, 2013 2:35 pm

Re: Now I was thinking maybe I'd code a market

Post by nido »

http://wardenscat.foxserver.be/nido/market016.zip

This version is largely the last version with the memory problems fixed, added xml support for Cargo, completed Doxygen documentation, more unit tests, bla bla bla.

to try it out, download the zip; run 'cmake .', followed by 'make'; and you will get bigtest and cppunittest; bigtest can simulate economies of various sizes, cppunittest runs cppunit tests

Speaking of Doxygen; http://wardenscat.foxserver.be/nido/market016
Even external links work save the buildbot link since that runs on a different system.

some gruntwork still to do is implementing xml support for the rest of the classes. Perhaps i should spend more time investigating the VegaStrike XML interface and provide it with commentary rather then to continue my builtin solution, any ideas on this welcome.

After that, it becomes an excersize of defining an economy and define limits, define trading (checking implementations will be easier with a sensible production chain ready), and check implications on memory footprint and runtime on those points.

the .zip also contains a file called doc/reqeng.md. This contains lines in the format of
Title
*Rationale*:
*Fit Criterion*:
*Dependencies*:
suggestions to other requirements for this list are more then welcome as this file should ultimately define what we want from this economy system. I've written down some things based on what i was currently implementing and I should make another pass though this thread looking for additional requirements. Yet, I request you take the time to formulate requests if you think of them as well.
ezee
Intrepid Venturer
Intrepid Venturer
Posts: 703
Joined: Tue Feb 11, 2014 12:47 am
Location: FRANCE
Contact:

Re: Now I was thinking maybe I'd code a market

Post by ezee »

Hi nido , if you come back here one of these days .
:wink:

I am trying to port your code in a visualstudio9 solution .
I had to download a dependency :
cppunit -> http://gaiacrtn.free.fr/cppunit/#Download

I also make some changes :
_ in XMLNode.cpp :
#ifdef WIN32
#include <stdlib.h> //ezee for windows for atof() instead of strtof()
#endif
std::string cargoName = this->attributes["name"];
std::string cargoDescription = this->attributes["category"];
#ifdef WIN32
float cargoMass = atof(this->attributes["mass"].c_str());
float cargoVolume = atof(this->attributes["volume"].c_str());
float cargoPrice = atof(this->attributes["price"].c_str());

#else
float cargoMass = strtof(this->attributes["mass"].c_str(), NULL);
float cargoVolume = strtof(this->attributes["volume"].c_str(), NULL);
float cargoPrice = strtof(this->attributes["price"].c_str(), NULL);
#endif

CargoType *cargo = new CargoType(cargoName, cargoDescription, cargoMass,
cargoVolume, cargoPrice);
I still have errors :
1>------ Build started: Project: VSmarket, Configuration: Release Win32 ------
1>Compiling...
1>common.cpp
1>ProductionOption.cpp
1>MPLParse.cpp
1>..\..\src\MPLParse.cpp(9) : error C3861: 'getdatadir': identifier not found
1>Economy.cpp
1>CargoType.cpp
1>Cargo.cpp
1>..\..\src\Cargo.cpp(76) : error C2039: 'at' : is not a member of 'std::map<_Kty,_Ty>'
1> with
1> [
1> _Kty=CargoType,
1> _Ty=unsigned int
1> ]
1>Base.cpp
1>Factory.cpp
1>VSmarket.cpp
1>stdafx.cpp
1>Build log was saved at "file://d:\program\market016\NidoMarket\VSmarket\Release\BuildLog.htm"
1>VSmarket - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
but i think that will fixed easyly .
So man , thank you for that work , and his beautiful doc !
:wink:

edit : fixed the error 1 , caused by ( in common/common.h ) :
#ifdef _WIN32
#include <string>

//Returns where the data directory is. Returns the cwd if it can't find the data dir.
//Note: When it returns it has already changed dir to where the data directory is
std::string getdatadir();

#endif
Visualstudio create and define WIN32 and not _WIN32 as preprocessor arg .
So the fix is :
#ifdef WIN32
#include <string>
other dependency :
1>------ Build started: Project: VSmarket, Configuration: Release Win32 ------
1>Compiling...
1>common.cpp
1>Linking...
1>XMLNode.obj : error LNK2001: unresolved external symbol _XML_ParserCreate
1>XMLNode.obj : error LNK2001: unresolved external symbol _XML_SetElementHandler
1>XMLNode.obj : error LNK2001: unresolved external symbol _XML_ParserFree
1>XMLNode.obj : error LNK2001: unresolved external symbol _XML_Parse
1>XMLNode.obj : error LNK2001: unresolved external symbol _XML_SetCharacterDataHandler
1>XMLNode.obj : error LNK2001: unresolved external symbol _XML_SetUserData
1>D:\program\market016\NidoMarket\Release\VSmarket.exe : fatal error LNK1120: 6 unresolved externals
1>Build log was saved at "file://d:\program\market016\NidoMarket\VSmarket\Release\BuildLog.htm"
1>VSmarket - 7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
So i downloaded expat api , and now link is ok :
1>------ Build started: Project: VSmarket, Configuration: Release Win32 ------
1>Compiling...
1>common.cpp
1>Linking...
1>Generating code
1>Finished generating code
1>Embedding manifest...
1>Build log was saved at "file://d:\program\market016\NidoMarket\VSmarket\Release\BuildLog.htm"
1>VSmarket - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
I will try it soon .
Eye~R and i are planning to use it for a MMO test with vegastrike :
http://forums.vega-strike.org/viewtopic ... 25#p137125

i'll also will provide here a link to my nido's market visualstudio9 solution for windows coders : http://spacetechs.free.fr/VEGASTRIKEDEV ... ket016.rar
( be advised that the project options need to be updated to your local paths , and that
only the release version was configured . Also , the VC9 solution is located in market016\NidoMarket )

FInally , a quick tutorial about the market API would be useful .
I will try to use it and i'll report my opinion later ( and snippet of code if i am lucky )
:wink:

Code: Select all

 if (!track.HasWeapons())
            {
                // So what are you going to threaten me with? Exhaustion gas?
                return ThreatLevel::None;
            }
Vegastrike evolved
DEV YOUTUBE CHANNEL
Vegastrike evolved wiki
Post Reply