Author Topic: Shooting energy endlesly  (Read 1423 times)

Offline Testlund

  • Bot God
  • *****
  • Posts: 1574
    • View Profile
    • Games And Electronica
Shooting energy endlesly
« on: October 03, 2006, 08:01:34 AM »
I'm not sure if this is a bug but I think it's weird. A veggie in my sim is shooting energy without loosing any. It seem to has lost a lot of energy to begin with but it has stopped at 49. Now it doesn't lose any more energy.
"God is an ever receding pocket of scientific ignorence." - Neil DeGrasse Tyson

"God is a kid with an ant farm" - Constantine

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Shooting energy endlesly
« Reply #1 on: October 28, 2006, 01:36:09 AM »
I think they are body shots, not nrg shots.  If I understand the DNA correctly, its basically:

-132 7 store

and the way the mod works on shots, -132 is equivalent to -6.

So the veggy is shooting body, not nrg and since CostX is 0, there is no nrg cost for the shot.  Thus, no nrg drop.
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Shooting energy endlesly
« Reply #2 on: October 28, 2006, 06:05:21 AM »
Are you sure it's -132 7 store?

Looking at it I see it as doing 2 7 store, which would be shooting out nrg shots.  But it's also late at night for me and I can be off here.

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Shooting energy endlesly
« Reply #3 on: October 28, 2006, 10:36:05 AM »
I think *-n is ignored and doesn't affect the stack. So this would be a '-2 .shoot store', an energy shot. If the bot has 0 in .shootval, the shot carries 0 energy.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Shooting energy endlesly
« Reply #4 on: October 28, 2006, 11:36:40 AM »
I'm sure your right.  I'm been afraid to crack open and try to understand the DNA parsing and execution code.  I hated my compilers class...
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Shooting energy endlesly
« Reply #5 on: October 28, 2006, 03:47:30 PM »
Ironically I haven't taken one

I think it's actually doing 2 7 store, which would be an empty info shot to sysvar #2.  Since there are no costs, nothing gets charged.

Incedentally, doing -2 .shoot store wwill produce an nrg shot with positive nrg even if you don't specify a .shootval.  I think it's something like 100 nrg.
« Last Edit: October 28, 2006, 04:09:13 PM by Numsgil »

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Shooting energy endlesly
« Reply #6 on: October 28, 2006, 05:30:14 PM »
Quote from: Numsgil
Incedentally, doing -2 .shoot store wwill produce an nrg shot with positive nrg even if you don't specify a .shootval.  I think it's something like 100 nrg.

The default nrg shot when .shootval is 0 is .nrg / 100, so you must be right and it can't be -2 7 store but I don't understand why the sub doesn't make it -2 and not 2.
« Last Edit: October 28, 2006, 05:35:13 PM by EricL »
Many beers....

Offline Sprotiel

  • Bot Destroyer
  • ***
  • Posts: 135
    • View Profile
Shooting energy endlesly
« Reply #7 on: October 28, 2006, 06:32:14 PM »
Quote from: EricL
The default nrg shot when .shootval is 0 is .nrg / 100, so you must be right and it can't be -2 7 store but I don't understand why the sub doesn't make it -2 and not 2.
Then we have it! VB does integer divisions in a very peculiar way: it performs the division as there were floats and rounds the result. Which means that 51 / 100 = 1 but 49/100 = 0. So either there's an integer division, or the result of the division is rounded. Whatever the case is, the energy of the shot becomes 0 when the bot's energy falls below some level (49.5 or 50, I suppose).

And '2 sub' really makes -2, because it's equivalent to '0 2 sub'.

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Shooting energy endlesly
« Reply #8 on: October 28, 2006, 10:42:24 PM »
Are you sure it's 2 sub?

Does *-12 return 0 or nothing?  I thought it returned 0, but if it returns nothing then it would indeed be a negative 2 shot.

Sprotiel, that seems like a good explanation.

Offline EricL

  • Administrator
  • Bot God
  • *****
  • Posts: 2266
    • View Profile
Shooting energy endlesly
« Reply #9 on: October 29, 2006, 03:42:36 PM »
Sprotiel is completely correct (almost) w.r.t. why there is no nrg loss.  I've stepped through the code to verify what is happening.  VB is indeed rounding the result to 0, but not becuase of integer division.  Internally, .nrg is maintained on the bot structure as a Single, not an Integer.  VB is correctly coercing the '100' to a Single when performing the division.  But the result is then assigned to a temporary varable which is declared as a Long.  This is where the rouding occurs.

I've fixed this for the next drop by using a Sinlge vauled temp varible.  Note that this one change addresses similar rounding bugs w.r.t. venom shots, waste shots and even nrg request shots....

Additionally, I think Sprotiel is correct that *-12 does nothing.

Code: [Select]
Case 1 '*number
        If CurrentFlow <> CLEAR And .DNA(a).value <= 1000 And .DNA(a).value > 0 Then
          PushIntStack .mem(.DNA(a).value)
          If .DNA(a).value > EyeStart And .DNA(a).value < EyeEnd Then
            rob(n).View = True
          End If
        End If
Many beers....

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7714
    • View Profile
Shooting energy endlesly
« Reply #10 on: October 29, 2006, 07:30:42 PM »
Good to know.

While I'm thinking about it, the C++ fork is cyclic for values > 1000 (1001 = 1, 29001 = 1, etc.).  I don't know how applicable this is to the current code base, but it's an easy enough add.
« Last Edit: October 29, 2006, 07:32:19 PM by Numsgil »