Recharge System

So I am a big fan of EVE Online, I am working on my own little 2D top down space shooter that takes quite a few elements from that, at the moment it is simple and nothing like it. So far all I have is a way to create basic ships, then mount weapons on them, of which I have 2 that yet again, don’t do anything. It is not an MMO or multiplayer, just imagine a fun little top down action game with some depth and thought put into what you are using to blast the bad guys.

I am going to be building the Ship class up to have at least the basics down.

So I want to implement a “Ship Capacitor” that can be used to activate weapons and such, however I am not quite sure how to implement it.

For anyone who has never played EVE Online…

  • Every ship has a capacitor, it is needed to use the majority of modules available to you.
  • Capacitors have a recharge time in seconds that it takes to get from 0 to max
  • They charge faster the lower they get

So my problem is, how on earth would I go about getting the time it would take to get a ships capacitor from 0 to max?

I was thinking at creation of the object, I simply simulate this in the constructor and then save the time in seconds to a field? Terrible idea

Is there a better way to do this?

EDIT:

Here is my code snippet, it recharges every 1 second and it takes the current - the max / 15 to simulate the lower it gets the faster it increases, later I will probably change the 15 variable so that it can be altered.

		if(TimeUtils.nanoTime() - lastRecharge > TimeCoversion.secondToNanos(1)){
			current = current + (max - current) / 15;
			lastRecharge = TimeUtils.nanoTime();
		}

If my math serves me right, you would use a logarithmic function for that no?

something like this graph here where the x is the Capacitor value, and the y is the time it takes to charge. As the Capacitor value increases, it takes more time to charge up to a certain threshold…

In JAVA, you would implement that by doing something like

Time it takes to charge = Math.log(Capacitor value);

and you could use

Math.floor()

and

Math.ceil()

to limit the values.

This may not be what you’re looking for, but it’s what immediately came to mind

Thanks for your reply, that graph make sense however the pseudo you wrote is a bit eh, well no idea what that really does? lol

I just implemented a cheat way of doing it but it really sucks, that is to basically run a while loop in the constructor of the capacitor, since I only ever regen capacitor every 1 second, I basically done:

while current value < max value
  do the thing
  increase an integer

integer is how many loop iterations that it took to generate cap from 0 to max, however this is crap…lol

EDIT:

I think I might have misunderstood your post, that will increase my cap over time the way I want it.

What I really want is the time it takes from 0 to max. If that is what you are trying to show me, sorry but yeah, I don’t get it lol.

They are static values. I.e you would do something like

  • Get the current recharge%
  • Apply the Math.log() using the recharge% (so Math.log(recharge%))
  • That will return the current pace at which the recharge would increase, relative to the other recharge%
  • Use Math.floor() and Math.ceil() to limit the pace value, so it doesn’t increase too slowly, or too quickly.

I have no idea what your game code looks like so I can’t really implement it to your actual values for you, just saying it could be done using Math.log()

Since you have different Capacitors you could use different Multipliers for the pace values. Sorry if I’m not understanding your problem correctly.