Wow, cool! I'll get right on that...
Edit: it looks like a plain-text file, so I'm using [code][/code] tags. File extension is .patch
Index: lua.cpp
===================================================================
--- lua.cpp (revision 5245)
+++ lua.cpp (working copy)
@@ -11,10 +11,12 @@
#include "graphics/font.h"
#include "globalincs/linklist.h"
#include "globalincs/pstypes.h"
+#include "hud/hudbrackets.h"
#include "iff_defs/iff_defs.h"
#include "io/key.h"
#include "io/mouse.h"
#include "io/timer.h"
+#include "jumpnode/jumpnode.h"
#include "lighting/lighting.h"
#include "mission/missioncampaign.h"
#include "mission/missiongoals.h"
@@ -8053,6 +8055,102 @@
return ADE_RETURN_TRUE;
}
+// Aardwolf's targeting brackets function
+ADE_FUNC(drawTargetingBrackets, l_Graphics, "object Object, [boolean draw=true, int padding=5]",
+ "Gets the edge positions of targeting brackets for the specified object. The brackets will only be drawn if draw is true or the default value of draw is used. Brackets are drawn with the current color. The brackets will have a padding (distance from the actual bounding box); the default value (used elsewhere in FS2) is 5.",
+ "number,number,number,number",
+ "Left, top, right, and bottom positions of the brackets, or nil if invalid")
+{
+ if(!Gr_inited) {
+ return ADE_RETURN_NIL;
+ }
+
+ object_h *objh = NULL;
+ bool draw_box = true;
+ int padding = 5;
+
+ if( !ade_get_args(L, "o|bi", l_Object.GetPtr(&objh), &draw_box, &padding) ) {
+ return ADE_RETURN_NIL;
+ }
+
+ // The following code is mostly copied from
+ // void hud_show_brackets(object *targetp, vertex *projected_v)
+ // in hudtarget.cpp
+
+ if( !objh->IsValid()) {
+ return ADE_RETURN_NIL;
+ }
+
+ object *targetp = objh->objp;
+
+ int x1,x2,y1,y2;
+ int bound_rc;
+
+ int modelnum;
+
+ switch ( targetp->type ) {
+ case OBJ_SHIP:
+ modelnum = Ship_info[Ships[targetp->instance].ship_info_index].model_num;
+ bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
+ if ( bound_rc != 0 ) {
+ return ADE_RETURN_NIL;
+ }
+ break;
+
+ case OBJ_DEBRIS:
+ modelnum = Debris[targetp->instance].model_num;
+ bound_rc = submodel_find_2d_bound_min( modelnum, Debris[targetp->instance].submodel_num, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
+ if ( bound_rc != 0 ) {
+ return ADE_RETURN_NIL;
+ }
+ break;
+
+ case OBJ_WEAPON:
+ Assert(Weapon_info[Weapons[targetp->instance].weapon_info_index].subtype == WP_MISSILE);
+ modelnum = Weapon_info[Weapons[targetp->instance].weapon_info_index].model_num;
+ bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
+ break;
+
+ case OBJ_ASTEROID:
+ {
+ int pof = 0;
+ pof = Asteroids[targetp->instance].asteroid_subtype;
+ modelnum = Asteroid_info[Asteroids[targetp->instance].asteroid_type].model_num[pof];
+ bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
+ }
+ break;
+
+ case OBJ_JUMP_NODE:
+ modelnum = targetp->jnp->get_modelnum();
+ bound_rc = model_find_2d_bound_min( modelnum, &targetp->orient, &targetp->pos,&x1,&y1,&x2,&y2 );
+ break;
+
+ default:
+ // should never happen
+ Int3();
+ return ADE_RETURN_NIL;
+ }
+
+ x1 -= padding;
+ x2 += padding;
+ y1 -= padding;
+ y2 += padding;
+ if ( draw_box ) {
+ if( !(g3_in_frame() > 0) )
+ {
+ g3_start_frame(0);
+ draw_brackets_square(x1, y1, x2, y2, false);
+ g3_end_frame();
+ }
+ else
+ {
+ draw_brackets_square(x1, y1, x2, y2, false);
+ }
+ }
+
+ return ade_set_args(L, "iiii", x1, y1, x2, y2);
+}
+
#define MAX_TEXT_LINES 256
static char *BooleanValues[] = {"False", "True"};
static const int NextDrawStringPosInitial[] = {0, 0};