Author Topic: [Patch] Some Scripting Goodies  (Read 1812 times)

0 Members and 1 Guest are viewing this topic.

Offline Axem

  • 211
[Patch] Some Scripting Goodies
Okay, I know I should have probably divided this into multiple patches, but they're all pretty small.

1: Allows beam weapons to work with On Turret Fire hook (by MageKing actually, but I haven't seen him commit it yet!) (aiturret.cpp)
2: Adds applyWhack function to the physics library (lua.cpp)
3: Adds On Afterburner Engage/Stop hooks (scripting.cpp, scripting.h, afterburner.cpp)
4: Adds On Beam Fire Hook (occurs when the beam actually begins to render, after the warm up) (scripting.cpp, scripting.h, beam.cpp)

http://pastebin.com/ukBgUCAj

So if some intrepid coder could look through these and make sure I didn't make any silly mistakes, that would be awesome. :)

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: [Patch] Some Scripting Goodies
1: Allows beam weapons to work with On Turret Fire hook (by MageKing actually, but I haven't seen him commit it yet!) (aiturret.cpp)
I didn't?

Oh right, I didn't. I wanted to make sure it didn't break existing scripts, in case they were relying on hv.Weapon not being a beam.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: [Patch] Some Scripting Goodies
Since Axem mentioned this again recently, I thought I'd explain in more detail why I haven't committed (or, since the move to Git, made a pull request for) the change allowing On Turret Fire to detect beams.

Currently, the "Weapon" hook variable is of the Lua class "weapon", always. Guaranteed. With that change, suddenly it can be either "weapon" or "beam", and the two have different sets of methods and attributes. If there's a script that does things based on hv.Weapon.LifeLeft, for instance, this patch might cause that script (which used to work just fine) to generate errors. Now, it's possible that everyone who wrote a script using On Turret Fire operated under the assumption that hv.Weapon might be a beam, and this assumption just happened to make their script futureproof in this scenariio, but I don't know what every modder that ever used On Turret Fire did.

Does anybody else have any suggestions? I'm all ears.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 

Offline Goober5000

  • HLP Loremaster
  • Moderator
  • 214
    • Goober5000 Productions
Re: [Patch] Some Scripting Goodies
Is 'beam' a subclass of 'weapon' in Lua?  If so, keep the script hook signature as using 'weapon', but provide a 'beam' internally.

This is what happened in the Java Swing API when they moved from Graphics to Graphics2D.  All of the API methods still have a Graphics object for reverse-compatibility, but newer implementations cast it to Graphics2D to take advantage of the extra methods.

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: [Patch] Some Scripting Goodies
Is 'beam' a subclass of 'weapon' in Lua?
No.
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.