Author Topic: Glest XML - attack strength speed  (Read 2705 times)

Mr War

  • Guest
Glest XML - attack strength speed
« on: 12 March 2011, 07:38:00 »
Two units, one has attack strength of 400 and attack speed (Rate of fire?) of 90. The other has an attack strength of 130 at speed 50. All other things are equal.

Which inflicts the most damage over a given period of time and what's the formula to calculate that?

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest XML - attack strength speed
« Reply #1 on: 12 March 2011, 08:11:25 »
Skill Speed:
frames per skill cycle = ceiling( 1 / (speed / 4000) )

Attack A cycle length = ceil(1 / (90 / 4000)) = 45 frames.
Attack B cycle length = ceil(1 / (50 / 4000)) = 80 frames.


Damage:
Damage dealt = (attack_strength + rand(-var, +var) - armour) * damage_multiplier
Assuming attack variance = 0 and damge multiplier = 1 and target has armour = 0 then,
Damage dealt = (attack_strength + rand(-0, +0) - 0) * 1 = attack_strength

Therefore:
Attack A does 400 points damage per 45 frames, for an average of 8.888... hp / frame.
Attack B does 150 points damage per 80 frames, for an average of 1.875... hp / frame.


Attack A is 4.74 times more powerful than Attack B.
Glest Advanced Engine - Code Monkey

Timeline | Downloads

Mr War

  • Guest
Re: Glest XML - attack strength speed
« Reply #2 on: 12 March 2011, 09:19:50 »
thanks man that's REALLY helpful!

Zoythrus

  • Guest
Re: Glest XML - attack strength speed
« Reply #3 on: 14 March 2011, 01:29:42 »
Skill Speed:
frames per skill cycle = ceiling( 1 / (speed / 4000) )

Attack A cycle length = ceil(1 / (90 / 4000)) = 45 frames.
Attack B cycle length = ceil(1 / (50 / 4000)) = 80 frames.


Damage:
Damage dealt = (attack_strength + rand(-var, +var) - armour) * damage_multiplier
Assuming attack variance = 0 and damge multiplier = 1 and target has armour = 0 then,
Damage dealt = (attack_strength + rand(-0, +0) - 0) * 1 = attack_strength

Therefore:
Attack A does 400 points damage per 45 frames, for an average of 8.888... hp / frame.
Attack B does 150 points damage per 80 frames, for an average of 1.875... hp / frame.


Attack A is 4.74 times more powerful than Attack B.


hmmm....if only there was a program that did this for you....

John.d.h

  • Moderator
  • Airship
  • ********
  • Posts: 3,757
  • I have to go now. My planet needs me.
    • View Profile
Re: Glest XML - attack strength speed
« Reply #4 on: 14 March 2011, 01:41:00 »
hmmm....if only there was a program that did this for you....
Aren't you in a programming class?  This would be about one step beyond "hello world". :P

Zoythrus

  • Guest
Re: Glest XML - attack strength speed
« Reply #5 on: 14 March 2011, 16:41:25 »
hmmm....if only there was a program that did this for you....
Aren't you in a programming class?  This would be about one step beyond "hello world". :P
im thinking about it......

John.d.h

  • Moderator
  • Airship
  • ********
  • Posts: 3,757
  • I have to go now. My planet needs me.
    • View Profile
Re: Glest XML - attack strength speed
« Reply #6 on: 14 March 2011, 17:37:05 »
Just scanf the user input into a couple variables, plug them into a formula, then printf the output.  If you wanted to get fancy, you could even do an fscanf to read it from the XML file, if you've learned that yet.  I'd do it myself if I remembered the syntax. :look:

Zoythrus

  • Guest
Re: Glest XML - attack strength speed
« Reply #7 on: 14 March 2011, 20:54:14 »
k guys, i'll try to write up a program today....sorry if im not very good at it, im just learning...

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Glest XML - attack strength speed
« Reply #8 on: 15 March 2011, 04:20:33 »
You're too slow. I had a lot of fun with this, even though most of the time was wasted on the graphics, and I never bothered to impliment anything but firefox unique code.

http://glestguide.co.cc/sandbox/damage.html
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

Zoythrus

  • Guest
Re: Glest XML - attack strength speed
« Reply #9 on: 15 March 2011, 06:22:09 »
dang it! i only had a bug that stopped me.....i was that close!

good job, omega, it's better than i could do.....

 :thumbup:

silnarm

  • GAE Team
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Glest XML - attack strength speed
« Reply #10 on: 15 March 2011, 06:47:36 »
http://glestguide.co.cc/sandbox/damage.html

Nice one :thumbup:

The damage calculation has its fractional part truncated though, so change your round() calls to floor().

And a small correction for the skill cycle length calc, if (speed / 4000) divides 1 evenly then the formula I gave reports one less than it should, use this instead,
floor(1 / (speed / 4000) + 1)

Edit: You can make it work easily enough in any browser by using something like this
Code: [Select]
// get DOM Object by id
function getObjById( id ) {
   var res = null;
   if (document.getElementById) {
      res = document.getElementById(id);
   } else if (document.all) {
      res = document.all[id];
   } else if (document.layers) {
      res = document.layers[id];
   } else {
      alert("no way to get DOM Elements :~(");
   }
   return res;
}
instead of just document.getElementById().

But history.go(-1); appears to be not Chrome friendly  :look:
« Last Edit: 15 March 2011, 08:18:12 by silnarm »
Glest Advanced Engine - Code Monkey

Timeline | Downloads

Omega

  • MegaGlest Team
  • Dragon
  • ********
  • Posts: 6,167
  • Professional bug writer
    • View Profile
    • Personal site
Re: Glest XML - attack strength speed
« Reply #11 on: 17 March 2011, 04:48:47 »
Nice catch Silnarm. Not sure how necessary the object selector code is, as all major browsers that I know of support document.getElementById, though I added it just for fun anyway. I also changed how it rendered graphics so it is now webkit (safari and chrome) compatible, as well as replaced the document.write method (which is what breaks it for Chrome, as calling document.write after a page load completely replaces the page, and firefox allows the back button to work on this "new" page, whereas chrome does not. history.go(-1) DOES work in chrome, but only if there is a page to go to, which chrome does not believe exists (and technically, it doesn't)) with a cleaner and simpler DOM method. I fixed the speed formula as per your new formula, and added in the attack-var field (calculations are still performed with base damage, but that a sample damage is shown as well.
Edit the MegaGlest wiki: http://docs.megaglest.org/

My personal projects: http://github.com/KatrinaHoffert

 

anything