Author Topic: Tweaking the hud gauge activation sexps  (Read 1527 times)

0 Members and 1 Guest are viewing this topic.

Offline Axem

  • 211
Tweaking the hud gauge activation sexps
I've always found the current sexps to turn on and off hud gauges a little hard to use. It only allowed 1 argument per sexp because of how it was set up (gauge name, then the boolean). So I wrote a simple patch that basically swaps the argument order, and gives them much clearer names. Instead of the sort of confusing hud-gauge-set-active and hud-activate-gauge-type, there is now hud-set-custom-gauge-active and hud-set-retail-gauge-active.

For the dudes that have campaigns that use these sexps already, not to worry! The old sexps are still there (just hidden on the menus), and FRED won't try to automatically upgrade them. Such work is beyond my simple abilities and I personally don't like FRED doing things without my knowledge.

Code: [Select]
Index: code/fred2/sexp_tree.cpp
===================================================================
--- code/fred2/sexp_tree.cpp (revision 9258)
+++ code/fred2/sexp_tree.cpp (working copy)
@@ -827,6 +827,8 @@
  // unlike the above operators, these are deprecated
  case OP_HITS_LEFT_SUBSYSTEM:
  case OP_CUTSCENES_SHOW_SUBTITLE:
+ case OP_HUD_GAUGE_SET_ACTIVE:
+ case OP_HUD_ACTIVATE_GAUGE_TYPE:
  j = Num_op_menus; // don't allow these operators to be visible
  break;
  }
@@ -865,6 +867,8 @@
  // unlike the above operators, these are deprecated
  case OP_HITS_LEFT_SUBSYSTEM:
  case OP_CUTSCENES_SHOW_SUBTITLE:
+ case OP_HUD_GAUGE_SET_ACTIVE:
+ case OP_HUD_ACTIVATE_GAUGE_TYPE:
  j = Num_submenus; // don't allow these operators to be visible
  break;
  }
Index: code/parse/sexp.cpp
===================================================================
--- code/parse/sexp.cpp (revision 9258)
+++ code/parse/sexp.cpp (working copy)
@@ -554,6 +554,8 @@
  //HUD Sub-Category
  { "hud-disable", OP_HUD_DISABLE, 1, 1 }, // Goober5000
  { "hud-disable-except-messages", OP_HUD_DISABLE_EXCEPT_MESSAGES, 1, 1 }, // Goober5000
+ { "hud-set-custom-gauge-active", OP_HUD_SET_CUSTOM_GAUGE_ACTIVE, 2, INT_MAX },
+ { "hud-set-retail-gauge-active", OP_HUD_SET_RETAIL_GAUGE_ACTIVE, 2, INT_MAX},
  { "hud-set-text", OP_HUD_SET_TEXT, 2, 2 }, //WMCoolmon
  { "hud-set-text-num", OP_HUD_SET_TEXT_NUM, 2, 2 }, //WMCoolmon
  { "hud-set-message", OP_HUD_SET_MESSAGE, 2, 2 }, //The E
@@ -561,9 +563,9 @@
  { "hud-set-frame", OP_HUD_SET_FRAME, 2, 2 }, //WMCoolmon
  { "hud-set-coords", OP_HUD_SET_COORDS, 3, 3 }, //WMCoolmon
  { "hud-set-color", OP_HUD_SET_COLOR, 4, 4 }, //WMCoolmon
- { "hud-display-gauge", OP_HUD_DISPLAY_GAUGE, 2, 2 },
- { "hud-gauge-set-active", OP_HUD_GAUGE_SET_ACTIVE, 2, 2 },
- { "hud-activate-gauge-type", OP_HUD_ACTIVATE_GAUGE_TYPE, 2, 2},
+ { "hud-display-gauge", OP_HUD_DISPLAY_GAUGE, 2, 2 },
+ { "hud-gauge-set-active", OP_HUD_GAUGE_SET_ACTIVE, 2, 2 }, //Deprecated
+ { "hud-activate-gauge-type", OP_HUD_ACTIVATE_GAUGE_TYPE, 2, 2}, //Deprecated
  { "hud-clear-messages", OP_HUD_CLEAR_MESSAGES, 0, 0}, // swifty
  { "hud-set-max-targeting-range", OP_HUD_SET_MAX_TARGETING_RANGE, 1, 1 }, // Goober5000
 
@@ -9710,6 +9712,23 @@
  }
 }
 
+void sexp_hud_set_custom_gauge_active(int node) {
+ HudGauge* hg;
+ bool activate = (is_sexp_true(node) > 0);
+ node = CDR(node);
+ for(; node >= 0; node = CDR(node)) {
+
+ char* name = CTEXT(node);
+ hg = hud_get_gauge(name);
+
+ if (hg != NULL) {
+ hg->updateActive(activate);
+ }
+
+ }
+
+}
+
 int hud_gauge_type_lookup(char* name) {
  for(int i = 0; i < Num_hud_gauge_types; i++) {
  if(!stricmp(name, Hud_gauge_types[i].name))
@@ -9741,6 +9760,37 @@
  }
 }
 
+void sexp_hud_set_retail_gauge_active(int node) {
+
+ bool activate = (is_sexp_true(node) > 0);
+ node = CDR(node);
+
+ for(; node >= 0; node = CDR(node)) {
+
+ int config_type = hud_gauge_type_lookup(CTEXT(node));
+
+ if (config_type != -1) {
+ if(Ship_info[Player_ship->ship_info_index].hud_gauges.size() > 0) {
+ size_t num_gauges = Ship_info[Player_ship->ship_info_index].hud_gauges.size();
+
+ for(size_t i = 0; i < num_gauges; i++) {
+ if (Ship_info[Player_ship->ship_info_index].hud_gauges[i]->getObjectType() == config_type)
+ Ship_info[Player_ship->ship_info_index].hud_gauges[i]->updateSexpOverride(!activate);
+ }
+ } else {
+ size_t num_gauges = default_hud_gauges.size();
+
+ for(size_t i = 0; i < num_gauges; i++) {
+ if (default_hud_gauges[i]->getObjectType() == config_type)
+ default_hud_gauges[i]->updateSexpOverride(!activate);
+ }
+ }
+ }
+
+ }
+
+}
+
 void multi_sexp_hud_display_gauge()
 {
  int show_for;
@@ -22986,6 +23036,11 @@
  sexp_hud_gauge_set_active(node);
  break;
 
+ case OP_HUD_SET_CUSTOM_GAUGE_ACTIVE:
+ sexp_val = SEXP_TRUE;
+ sexp_hud_set_custom_gauge_active(node);
+ break;
+
  case OP_HUD_CLEAR_MESSAGES:
  sexp_val = SEXP_TRUE;
  sexp_hud_clear_messages();
@@ -22996,6 +23051,11 @@
  sexp_hud_activate_gauge_type(node);
  break;
 
+ case OP_HUD_SET_RETAIL_GAUGE_ACTIVE:
+ sexp_val = SEXP_TRUE;
+ sexp_hud_set_retail_gauge_active(node);
+ break;
+
  case OP_ADD_TO_COLGROUP:
  sexp_val = SEXP_TRUE;
  sexp_manipulate_colgroup(node, true);
@@ -23982,6 +24042,8 @@
  case OP_SET_THRUSTERS:
  case OP_SET_PLAYER_THROTTLE_SPEED:
  case OP_DEBUG:
+ case OP_HUD_SET_CUSTOM_GAUGE_ACTIVE:
+ case OP_HUD_SET_RETAIL_GAUGE_ACTIVE:
  return OPR_NULL;
 
  case OP_AI_CHASE:
@@ -25944,6 +26006,18 @@
  else
  return OPF_BOOL;
 
+ case OP_HUD_SET_CUSTOM_GAUGE_ACTIVE:
+ if (argnum == 0)
+ return OPF_BOOL;
+ else
+ return OPF_HUD_GAUGE;
+
+ case OP_HUD_SET_RETAIL_GAUGE_ACTIVE:
+ if (argnum == 0)
+ return OPF_BOOL;
+ else
+ return OPF_HUD_GAUGE;
+
  case OP_GET_COLGROUP_ID:
  return OPF_SHIP;
 
@@ -27426,6 +27500,8 @@
 
  case OP_HUD_DISABLE:
  case OP_HUD_DISABLE_EXCEPT_MESSAGES:
+ case OP_HUD_SET_CUSTOM_GAUGE_ACTIVE:
+ case OP_HUD_SET_RETAIL_GAUGE_ACTIVE:
  case OP_HUD_SET_TEXT:
  case OP_HUD_SET_TEXT_NUM:
  case OP_HUD_SET_MESSAGE:
@@ -31031,7 +31107,7 @@
  "\t2:\tText that will be displayed. This text will be treated as directive text, meaning that references to mapped keys will be replaced with the user's preferences.\r\n"
  },
 
- {OP_HUD_GAUGE_SET_ACTIVE, "hud-gauge-set-active\r\n"
+ {OP_HUD_GAUGE_SET_ACTIVE, "hud-gauge-set-active (deprecated)\r\n"
  "\tActivates or deactivates a given custom gauge."
  "Takes 2 Arguments...\r\n"
  "\t1:\tHUD Gauge name\r\n"
@@ -31043,13 +31119,27 @@
  "Takes no arguments\r\n"
  },
 
- {OP_HUD_ACTIVATE_GAUGE_TYPE, "hud-activate-gauge-type\r\n"
+ {OP_HUD_ACTIVATE_GAUGE_TYPE, "hud-activate-gauge-type (deprecated)\r\n"
  "\tActivates or deactivates all hud gauges of a given type."
  "Takes 2 Arguments...\r\n"
  "\t1:\tGauge Type\r\n"
  "\t2:\tBoolean, whether or not to display this gauge\r\n"
  },
 
+ {OP_HUD_SET_CUSTOM_GAUGE_ACTIVE, "hud-set-custom-gauge-active\r\n"
+ "\tActivates or deactivates a custom hud gauge defined in hud_gauges.tbl."
+ "Takes 2 Arguments...\r\n"
+ "\t1:\tBoolean, whether or not to display this gauge\r\n"
+ "\tRest:\tHUD Gauge name\r\n"
+ },
+
+ {OP_HUD_SET_RETAIL_GAUGE_ACTIVE, "hud-set-custom-gauge-active\r\n"
+ "\tActivates or deactivates a retail hud gauge grouping."
+ "Takes 2 Arguments...\r\n"
+ "\t1:\tBoolean, whether or not to display this gauge\r\n"
+ "\tRest:\tHUD Gauge Group name\r\n"
+ },
+
  {OP_ADD_TO_COLGROUP, "add-to-collision-group\r\n"
  "\tAdds a ship to the specified collision group(s). Note that there are 32 collision groups,\r"
  "\tand that an object may be in several collision groups at the same time\r\n"
Index: code/parse/sexp.h
===================================================================
--- code/parse/sexp.h (revision 9258)
+++ code/parse/sexp.h (working copy)
@@ -643,8 +643,8 @@
 #define OP_SHIP_SUBSYS_VANISHED (0x00e1 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // FUBAR
 #define OP_SHIP_SUBSYS_IGNORE_IF_DEAD (0x00e2 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // FUBAR
 #define OP_HUD_SET_DIRECTIVE (0x00e3 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // The E
-#define OP_HUD_GAUGE_SET_ACTIVE (0x00e4 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // The E
-#define OP_HUD_ACTIVATE_GAUGE_TYPE (0x00e5 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // The E
+#define OP_HUD_GAUGE_SET_ACTIVE (0x00e4 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // The E - slightly deprecated
+#define OP_HUD_ACTIVATE_GAUGE_TYPE (0x00e5 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // The E - slightly deprecated
 #define OP_SET_OBJECT_ORIENTATION (0x00e6 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // Goober5000
 #define OP_STRING_CONCATENATE (0x00e7 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // Goober5000
 #define OP_INT_TO_STRING (0x00e8 | OP_CATEGORY_CHANGE | OP_NONCAMPAIGN_FLAG) // Goober5000
@@ -702,7 +702,9 @@
 #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
-#define OP_NAV_DESELECT (0x0020 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Talon1024
+#define OP_NAV_DESELECT (0x001A | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Talon1024
+#define OP_HUD_SET_CUSTOM_GAUGE_ACTIVE (0x001B | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // The E, just revamped a bit by Axem
+#define OP_HUD_SET_RETAIL_GAUGE_ACTIVE (0x001C | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // The E, just revamped a bit by Axem
 
 // defined for AI goals
 #define OP_AI_CHASE (0x0000 | OP_CATEGORY_AI | OP_NONCAMPAIGN_FLAG)
« Last Edit: October 13, 2012, 04:57:01 pm by Axem »

 

Offline Valathil

  • ...And I would have had a custom title if it wasn't for you meddling kids!
  • 29
  • Custom Title? Wizards need no Custom Title!
Re: Tweaking the hud gauge activation sexps
Looks like Axem smelled cthulhu blood.
┏┓╋┏┓╋╋╋╋╋╋╋╋╋┏┓
┃┃╋┃┃╋╋╋╋╋╋╋╋╋┃┃
┃┃┏┫┃┏┳━━┓┏━━┓┃┗━┳━━┳━━┳━━┓
┃┃┣┫┗┛┫┃━┫┃┏┓┃┃┏┓┃┏┓┃━━┫━━┫
┃┗┫┃┏┓┫┃━┫┃┏┓┃┃┗┛┃┗┛┣━━┣━━┃
┗━┻┻┛┗┻━━┛┗┛┗┛┗━━┻━━┻━━┻━━┛

  

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: Tweaking the hud gauge activation sexps
And he's out for more
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them