So, I wanted to port over a couple of the SEXPs that WCSaga added to their fork of FSO, so I've looked at The E's tutorial for writing SEXPs, and after a couple of hours, I came up with this.
Index: code/autopilot/autopilot.cpp
===================================================================
--- code/autopilot/autopilot.cpp (revision 9223)
+++ code/autopilot/autopilot.cpp (working copy)
@@ -1344,6 +1344,17 @@
}
// ********************************************************************************************
+// Selects a navpoint by name.
+void SelectNav(char *Nav)
+{
+ for (int i = 0; i < MAX_NAVPOINTS; i++)
+ {
+ if (!stricmp(Navs[i].m_NavName, Nav))
+ CurrentNav = i; //Talon1024: What I've wanted to do here is check to see if a navpoint was hidden or restricted, then select it if it was not. However, I don't know how to do that, as I've never worked with flags in C++ before, so can someone kindly help me?
+ }
+}
+
+// ********************************************************************************************
// Set A Nav point to "ZERO"
void ZeroNav(int i)
{
Index: code/autopilot/autopilot.h
===================================================================
--- code/autopilot/autopilot.h (revision 9223)
+++ code/autopilot/autopilot.h (working copy)
@@ -112,6 +112,9 @@
// Finds a Nav point by name
int FindNav(char *Nav);
+// Selects a Nav point by name
+void SelectNav(char *Nav);
+
// Set A Nav point to "ZERO"
void ZeroNav(int i);
Index: code/parse/sexp.cpp
===================================================================
--- code/parse/sexp.cpp (revision 9223)
+++ code/parse/sexp.cpp (working copy)
@@ -583,6 +583,7 @@
{ "is-nav-linked", OP_NAV_ISLINKED, 1, 1 }, //kazan
{ "use-nav-cinematics", OP_NAV_USECINEMATICS, 1, 1 }, //kazan
{ "use-autopilot", OP_NAV_USEAP, 1, 1 }, //kazan
+ { "select-nav", OP_NAV_SELECT, 1, 1 }, //Talon1024
//Cutscene Sub-Category
{ "set-cutscene-bars", OP_CUTSCENES_SET_CUTSCENE_BARS, 0, 1, },
@@ -17951,7 +17952,13 @@
return DistanceTo(nav_name);
}
+void select_nav(int node)
+{
+ char *nav_name = CTEXT(node);
+ SelectNav(nav_name);
+}
+
//*************************************************************************************************
@@ -22613,6 +22620,11 @@
sexp_val = SEXP_TRUE;
set_use_ap_cinematics(node);
break;
+
+ case OP_NAV_SELECT:
+ sexp_val = SEXP_TRUE;
+ select_nav(node);
+ break;
case OP_SCRAMBLE_MESSAGES:
case OP_UNSCRAMBLE_MESSAGES:
@@ -23660,6 +23672,7 @@
case OP_NAV_UNSET_NEEDSLINK:
case OP_NAV_USECINEMATICS:
case OP_NAV_USEAP:
+ case OP_NAV_SELECT:
case OP_HUD_SET_TEXT:
case OP_HUD_SET_TEXT_NUM:
case OP_HUD_SET_MESSAGE:
@@ -25482,6 +25495,7 @@
case OP_NAV_UNRESTRICT: //kazan
case OP_NAV_SET_VISITED: //kazan
case OP_NAV_UNSET_VISITED: //kazan
+ case OP_NAV_SELECT: //Talon1024
return OPF_STRING;
case OP_NAV_SET_CARRY: //kazan
@@ -27223,6 +27237,7 @@
case OP_NAV_UNSET_NEEDSLINK:
case OP_NAV_USECINEMATICS:
case OP_NAV_USEAP:
+ case OP_NAV_SELECT:
return CHANGE_SUBCATEGORY_NAV;
@@ -27496,6 +27511,8 @@
{ OP_NAV_USEAP, "Takes 1 boolean argument.\r\n"
"Set to true to enable autopilot, set to false to disable autopilot." },
+
+ { OP_NAV_SELECT, "Takes 1 argument: NavPoint Name, and then selects it\r\n" },
// -------------------------- -------------------------- --------------------------
Index: code/parse/sexp.h
===================================================================
--- code/parse/sexp.h (revision 9223)
+++ code/parse/sexp.h (working copy)
@@ -701,8 +701,8 @@
#define OP_DESTROY_SUBSYS_INSTANTLY (0x0016 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Admiral MS
#define OP_DEBUG (0x0017 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Karajorma
#define OP_SET_MISSION_MOOD (0x0018 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Karajorma
+#define OP_NAV_SELECT (0x0019 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Talon1024
-
// defined for AI goals
#define OP_AI_CHASE (0x0000 | OP_CATEGORY_AI | OP_NONCAMPAIGN_FLAG)
#define OP_AI_DOCK (0x0001 | OP_CATEGORY_AI | OP_NONCAMPAIGN_FLAG)
Obviously, I'm a newbie who hasn't written much C++ code before, so I wasn't able to do what I wanted to do (check to see if the navpoint was hidden or restricted before selecting it), so can someone please help me here?