Second Hand ship equipment advert for BBS

# Second Hand Advert

![screenshot-20141017-144920](https://cloud.githubusercontent.com/assets/619390/4678924/0b90b4b8-55fc-11e4-8c3c-74e1845b5f83.png)

Trade used equipment on the BBS, to 80-90% of full price. This is the reason I added the sell price / buy price last winter, since if the station buys back to full price (like it used to be), then you should always buy everything offered on the BBS and immediately sell it back to the station. Also, thanks @nozmajner for the cog icon, I ran `optipng -o9` on it.


## Some details

For reasons unknown to myself, I set it so only `Eqipment.misc` and `Eqipment.laser` are used for second hand adverts. This means I'm excluding engines. They can easily be added. It came out like that, and I thought maybe engines are too big/complicated to be traded over BBS.

The advert should not spam the BBS, my goal here was to have, on average, 1 advert per station in a big (10-billion) system like Sol, (11.2 billion people). In smaller system the number of ads per station will be linearly decreasing.

A bit fun is when one of the flavours: "SELLING: Practically unused `{equipment}`" is matching missiles, but I consider it a humorous feature.


## Initiate BBS in equilibrium

This is the reason I stopped working on this last winter, when it was 99% done: I wanted the number of ads created when the BBS is set up to be the same as when a player flies to a station and lands after some days. This is most definitely _not_ the case for ship market adverts for instance, so I thought I'd implement a working solution here, before going on to ship market ads.

It is just a simple ordinary differential equation, so for a system with `N` adverts, they will evolve over time like

    dN/dt = prod - lambda * N,

with some constant production rate `prod`, and a decay rate `lambda`, which we get from the half life `tau = 4*24 h` of the advert. Each `dt` is a call to `onUpdateBB`. From this we can easily calculate what the equilibrium is. Or rather, in my case, I set equilibrium number to be `N_eq=0.1` adverts per BBS and billion people in the system. An advert has a half life of 4 days, and from this I get the production rate `prod`.

Actually, instead of using the decay rate `lambda` for every advert, one could just draw a random number _once_ for each BBS update from a Poisson distribution (centred at `lambda*N`) and get how many adverts to remove. But I felt this was overkill, but might be worth doing if iterating through each advert is expensive (for instance if there are very many of them).


## RESULT: Number of adverts per station

__Note__ how they are initiated in _equilibrium_, no giant leap up or down (on average) from the level of the first day, other than the random fluctuations. I did three runs for each system shown in the figures below, time is in days.

![sol](https://cloud.githubusercontent.com/assets/619390/4678934/22796f4e-55fc-11e4-98f3-eed3b2bfd347.png)

![hope](https://cloud.githubusercontent.com/assets/619390/4679005/e402fb30-55fc-11e4-9198-14a094c90394.png)

_for Bernard's star there are 0 adverts over the same time, thus not worth plotting_.

## Future

If we ever implement wear and tear to individual ship components, then this should obviously be included here, and coupled to a flavour with an appropriate price.

The problem I had last winter was that I had the idea that the `N` in the ODE equation above should be for each _station_, but all adverts in the _system_ are stored in a single list, with no station specification. But now I realize that if we can deal with having the same average number of adverts per station regardless of it being orbital or ground, or on a densely populated planet or not, I don't need that fine resolution. But it would be nice to have. Something for the future.

So for now, this means that in Sol, which is crowded, there will be about 2 second hand adverts per station, regardless if it's London or on Pluto.


## NOT WIP!

I might tweak the ODE equation in the coming days/weeks/months, but I don't want this gathering dust for another year when it's done, so I'm submitting this as it is now, since it is balanced the way I want it, and BBS is spawned in equilibrium, which was my goal.