View Issue Details

IDProjectCategoryView StatusLast Update
0002889FSSCPSEXPspublic2013-10-28 05:30
ReporterMjnMixael Assigned Toniffiwan  
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
PlatformPCOSWindowsOS VersionWin7
Product Version3.7.2 
Target Version3.7.2 
Summary0002889: ETS Related SEXPs
DescriptionAs per discussion with Niffiwan on IRC, this ticket is to track the addition of

Get-ETS-value
SET-ETS-value

Should get or set a value as a percentage of the total for any 1 of the 3 gauges.

NOTE: I realized that setting the values could prove interesting because it will need to adjust the other 2 values respectively just like the player controls for ETS. Getting and setting will also need to take into account the lack of shields on some ships.
TagsNo tags attached.

Activities

niffiwan

2013-09-03 09:43

developer   ~0015260

Last edited: 2013-09-03 10:49

What do you think of the following approach?

get-ets-value ( "Alpha 1" "Engine|Shield|Weapon" )
returns integer from 0 - 100 (in discrete steps, i.e. always one of 0, 8, 17, 25, 33, 42, 50, 58, 67, 75, 83, 92, 100)
If the system doesn't exist on the ship, 0 will be returned (this is how FSO internally represents this state)
The values retrieved from all three systems may not sum to 100% due to rounding errors (although it will be close)

set-ets-values ( "Alpha 1" (Engine) 33 (Shield) 33 (Weapon) 33 )
You need to specify all 4 arguments
I thought this would be easier than accepting one value at a time. If I did it that way I'd need to auto balance the levels after each sexp ran, and I don't think you'd be able to set all the values to exactly what was retrieved by get-ets-value.
If the relevant ship is missing any systems (e.g. shields) then any input for that system will be ignored.
If set-ets-values uses the values retrieved by get-ets-value, it'll give you exactly what you asked for. If other values are used, the rounding/adjustments will need to occur in order to fit FSO's internal representation of the energy levels. So far I'm thinking that the highest set value(s) will lose value to fit the max allowed index.

FYI, internally FSO uses the following 13 float values for the ETS. The indexes (0 to 12) store the current energy level, not the percentages. Percentages are used to calculate the actual amount of energy recharged per unit of time.
float Energy_levels[NUM_ENERGY_LEVELS] = {0.0f, 0.0833f, 0.167f, 0.25f, 0.333f, 0.417f, 0.5f, 0.583f, 0.667f, 0.75f, 0.833f, 0.9167f, 1.0f};

=======================================================================

Actually, I just found these existing sexps:
shield-recharge-pct
weapon-recharge-pct
engine-recharge-pct

I think they remove the need to create get-ets-value.

FelixJim

2013-09-03 11:06

reporter   ~0015262

If you have to work in discrete energy levels anyway, why not just accept get and set values on a 0-12 scale and have done with it? I realise it's a less conventional scale than 0-100 but it would give a clearer idea of what's possible to a FREDer\scripter and eliminate any rounding issues.

FUBAR-BDHR

2013-09-03 11:06

developer   ~0015263

Probably a good idea to put the ship last in the list so more then 1 ship/wing/etc can be specified in the sexp.

MjnMixael

2013-09-03 12:46

manager   ~0015265

Huh, look at that.. never saw those recharge-pct sexps before. You live, you learn.

As for setting.. I assume the recharge-pct sexps return 0-100, so setting should be on that same scale.

The rest looks good, including the highest set values losing value to fit.

niffiwan

2013-09-04 03:55

developer   ~0015267

Thanks for all the input.

I'll switch to using indexes instead of percentages
I'll leave *-recharge-pct alone & create get-ets-value to return an index
I'll move the ship to the last arg in both get & set to allow multiple ships to be specified (although it doesn't make sense for the get to work on multiple ships, it's be better to be consistent between the sexps)
I'll adjust the values passed to set if they don't add up to 12 (i.e. 100%), increasing/decreasing as required towards the "middle".

niffiwan

2013-09-09 11:03

developer   ~0015268

I have a patch which I have tested with the attached mission. Seems to work as I expected, the only odd thing I've noticed is that Alpha 3 lacks shields, yet the ETS for that ship starts with power assigned to shields. It's probably a different bug.

Also, I haven't added anything to FRED as I can't compile & test it (and I'm not even sure that I need to add anything to FRED, at least according to The E's SEXP guide).

Anyway - please test & provide feedback :)

niffiwan

2013-09-09 11:10

developer  

ets_getset.fs2 (6,702 bytes)

MjnMixael

2013-09-15 01:50

manager   ~0015273

Works as expected!

niffiwan

2013-09-15 22:02

developer   ~0015274

Thanks for testing :)

If anyone thinks it'd be useful to duplicate these sexp in scripting, let me know (or would evaluateSEXP/runSEXP be enough?)

The_E

2013-09-19 14:47

administrator   ~0015277

Approved, but you really should implement a proper scripting interface (as neat as evalSexp is, it's always preferable to do things directly)

Admiral MS

2013-09-19 16:03

developer   ~0015278

As evaluateSEXP can't return anything but booleans, getting the values would be impossible in scripting. Therefore please duplicate them in scripting.

niffiwan

2013-09-19 23:12

developer   ~0015279

OK, scripting access will be added.

niffiwan

2013-09-26 07:48

developer   ~0015292

I've had a look at the scripting code, and I've got the following idea that I'd like to receive feedback on:

Add these to the ship object:
1) add three read-only ADE_VIRTVAR's, EtsEngineIndex, EtsShieldIndex, EtsWeaponIndex
2) add one ADE_FUNC, EtsSetIndexes

Apart from only affecting a single ship object at a time, it'll be the same as the sexp's. Where it makes sense I'll use the same code, and move it to functions in hud/hudets.cpp with the other ETS code.

Admiral MS

2013-09-29 19:55

developer   ~0015304

Sounds fine to me with three read-only virtvars and one setting function that does the calculations.

niffiwan

2013-10-06 04:05

developer  

ets-presets-sct.tbm (2,457 bytes)

niffiwan

2013-10-06 04:11

developer   ~0015307

Scripting is done, see the new patch. The SEXP interface remains unchanged from the previous patch.

See ets-presets-sct.tbm for an example script (parts of which were stolen from the wiki) which provides ETS "presets" functionality (somewhat like what XWing Alliance had). It also some debug related code, all to exercise & get feedback from the new LUA interface.

I've tested with the attached mission & script table. Please let me know if you find any issues, or can see anything wrong with the code or LUA.

niffiwan

2013-10-19 09:08

developer  

mantis2889-now-with-multi-svn.patch (16,271 bytes)   
Index: code/hud/hudets.h
===================================================================
--- code/hud/hudets.h	(revision 9961)
+++ code/hud/hudets.h	(working copy)
@@ -16,6 +16,25 @@
 
 struct object;
 
+#define ENERGY_DIVERT_DELTA				0.2f	// percentage of energy transferred in a shield->weapon or weapon->shield energy transfer
+#define INTIAL_SHIELD_RECHARGE_INDEX	4		// default shield charge rate (index in Energy_levels[])
+#define INTIAL_WEAPON_RECHARGE_INDEX	4		// default weapon charge rate (index in Energy_levels[])
+#define INTIAL_ENGINE_RECHARGE_INDEX	4		// default engine charge rate (index in Energy_levels[])
+
+#define NUM_ENERGY_LEVELS	13
+#define MAX_ENERGY_INDEX	(NUM_ENERGY_LEVELS - 1)
+
+#define AI_MODIFY_ETS_INTERVAL 500	// time between ets modifications for ai's (in milliseconds)
+
+#define ZERO_INDEX			0
+#define ONE_THIRD_INDEX		4
+#define ONE_HALF_INDEX		6
+#define ALL_INDEX			12
+
+#define HAS_ENGINES			(1<<0)
+#define HAS_SHIELDS			(1<<1)
+#define HAS_WEAPONS			(1<<2)
+
 #define	ETS_RECHARGE_RATE	4.0f			//	Recharge this percent of total shields/second
 
 const int num_retail_ets_gauges = 3;
@@ -37,6 +56,8 @@
 void transfer_energy_to_weapons(object* obj);
 
 float ets_get_max_speed(object* objp, float engine_energy);
+void sanity_check_ets_inputs(int (&ets_indexes)[num_retail_ets_gauges]);
+bool validate_ship_ets_indxes(const int &ship_idx, int (&ets_indexes)[num_retail_ets_gauges]);
 
 class HudGaugeEts: public HudGauge // HUD_ETS_GAUGE
 {
Index: code/hud/hudets.cpp
===================================================================
--- code/hud/hudets.cpp	(revision 9961)
+++ code/hud/hudets.cpp	(working copy)
@@ -23,33 +23,10 @@
 #include "object/object.h"
 #include "object/objectshield.h"
 #include "ship/subsysdamage.h"
-	
 
-#define ENERGY_DIVERT_DELTA				0.2f	// percentage of energy transferred in a shield->weapon or weapon->shield energy transfer
-#define INTIAL_SHIELD_RECHARGE_INDEX	4		// default shield charge rate (index in Energy_levels[])
-#define INTIAL_WEAPON_RECHARGE_INDEX	4		// default weapon charge rate (index in Energy_levels[])
-#define INTIAL_ENGINE_RECHARGE_INDEX	4		// default engine charge rate (index in Energy_levels[])
-
-//#define MAX_SHIELD_REGEN_PER_SECOND		0.02f	// max percent/100 of shield energy regenerated per second
-//#define MAX_WEAPON_REGEN_PER_SECOND		0.04f	// max percent/100 of weapon energy regenerated per second
-
-#define NUM_ENERGY_LEVELS	13		
-#define MAX_ENERGY_INDEX	(NUM_ENERGY_LEVELS - 1)
 float Energy_levels[NUM_ENERGY_LEVELS] = {0.0f,  0.0833f, 0.167f, 0.25f, 0.333f, 0.417f, 0.5f, 0.583f, 0.667f, 0.75f, 0.833f, 0.9167f, 1.0f};
-
-#define AI_MODIFY_ETS_INTERVAL 500	// time between ets modifications for ai's (in milliseconds)
-
 int Weapon_energy_cheat = 0;
 
-#define ZERO_INDEX			0
-#define ONE_THIRD_INDEX		4
-#define ONE_HALF_INDEX		6
-#define ALL_INDEX				12
-
-#define HAS_ENGINES			(1<<0)
-#define HAS_SHIELDS			(1<<1)
-#define HAS_WEAPONS			(1<<2)
-
 // -------------------------------------------------------------------------------------------------
 // ets_init_ship() is called by a ship when it is created (effectively, for every ship at the start
 // of a mission).  This will set the default charge rates for the different systems and initialize
@@ -669,6 +646,138 @@
 	transfer_energy_weapon_common(obj, shield_get_strength(obj), ship_p->weapon_energy, &ship_p->target_shields_delta, &ship_p->target_weapon_energy_delta, sinfo_p->max_weapon_reserve, 1.0f);
 }
 
+/**
+ * decrease one ets index to zero & adjust others up
+ */
+void zero_one_ets (int *reduce, int *add1, int *add2)
+{
+	int *tmp;
+	// add to the smallest index 1st
+	if (*add1 > *add2) {
+		tmp = add1;
+		add1 = add2;
+		add2 = tmp;
+	}
+	while (*reduce > ZERO_INDEX) {
+		if (*add1 < ALL_INDEX) {
+			++*add1;
+			--*reduce;
+		}
+
+		if (*reduce <= ZERO_INDEX) {
+			break;
+		}
+
+		if (*add2 < ALL_INDEX) {
+			++*add2;
+			--*reduce;
+		}
+	}
+}
+
+/**
+ * ensure input ETS indexs are valid.
+ * If not, "fix" them by moving outliers towards the middle index
+ */
+ void sanity_check_ets_inputs(int (&ets_indexes)[num_retail_ets_gauges])
+ {
+	int i;
+	int ets_delta = MAX_ENERGY_INDEX - ets_indexes[ENGINES] - ets_indexes[SHIELDS] - ets_indexes[WEAPONS];
+	if ( ets_delta != 0 ) {
+		if ( ets_delta > 0) { // add to lowest indexes
+			while ( ets_delta != 0 ) {
+				int lowest_val = MAX_ENERGY_INDEX;
+				int lowest_idx = 0;
+
+				for (i = 0; i < num_retail_ets_gauges; ++i) {
+					if (ets_indexes[i] <= lowest_val ) {
+						lowest_val = ets_indexes[i];
+						lowest_idx = i;
+					}
+				}
+				++ets_indexes[lowest_idx];
+				--ets_delta;
+			}
+		} else { // remove from highest indexes
+			while ( ets_delta != 0 ) {
+				int highest_val = 0;
+				int highest_idx = 0;
+
+				for (i = 0; i < num_retail_ets_gauges; ++i) {
+					if (ets_indexes[i] >= highest_val ) {
+						highest_val = ets_indexes[i];
+						highest_idx = i;
+					}
+				}
+				--ets_indexes[highest_idx];
+				++ets_delta;
+			}
+		}
+	}
+ }
+
+ /**
+  * adjust input ETS indexes to handle missing systems on the target ship
+  * return true if indexes are valid to be set
+  */
+bool validate_ship_ets_indxes(const int &ship_idx, int (&ets_indexes)[num_retail_ets_gauges])
+{
+	if (ship_idx < 0) {
+		return false;
+	}
+	if (Ships[ship_idx].objnum < 0) {
+		return false;
+	}
+	ship *ship_p = &Ships[ship_idx];
+
+	if (ship_p->flags2 & SF2_NO_ETS)
+		return false;
+
+	// handle ships that are missing parts of the ETS
+	int ship_properties = 0;
+	if (ship_has_energy_weapons(ship_p)) {
+		ship_properties |= HAS_WEAPONS;
+	}
+
+	if (!(Objects[ship_p->objnum].flags & OF_NO_SHIELDS)) {
+		ship_properties |= HAS_SHIELDS;
+	}
+
+	if (ship_has_engine_power(ship_p)) {
+		ship_properties |= HAS_ENGINES;
+	}
+
+	switch ( ship_properties ) {
+		case HAS_ENGINES | HAS_WEAPONS | HAS_SHIELDS:
+			// all present, don't change ets indexes
+			break;
+
+		case HAS_ENGINES | HAS_SHIELDS:
+			zero_one_ets(&ets_indexes[WEAPONS], &ets_indexes[ENGINES], &ets_indexes[SHIELDS]);
+			break;
+
+		case HAS_WEAPONS | HAS_SHIELDS:
+			zero_one_ets(&ets_indexes[ENGINES], &ets_indexes[SHIELDS], &ets_indexes[WEAPONS]);
+			break;
+
+		case HAS_ENGINES | HAS_WEAPONS:
+			zero_one_ets(&ets_indexes[SHIELDS], &ets_indexes[ENGINES], &ets_indexes[WEAPONS]);
+			break;
+
+		case HAS_ENGINES:
+		case HAS_SHIELDS:
+		case HAS_WEAPONS:
+			// can't change anything if only one is active on this ship
+			return false;
+			break;
+
+		default:
+			Error(LOCATION, "Encountered a ship (%s) with a broken ETS", ship_p->ship_name);
+			break;
+	}
+	return true;
+}
+
 HudGaugeEts::HudGaugeEts():
 HudGauge(HUD_OBJECT_ETS_ENGINES, HUD_ETS_GAUGE, false, false, (VM_EXTERNAL | VM_DEAD_VIEW | VM_WARP_CHASE | VM_PADLOCK_ANY | VM_OTHER_SHIP), 255, 255, 255),
 System_type(0)
Index: code/parse/sexp.cpp
===================================================================
--- code/parse/sexp.cpp	(revision 9961)
+++ code/parse/sexp.cpp	(working copy)
@@ -421,6 +421,8 @@
 	{ "never-warp",						OP_WARP_NEVER,							1,	INT_MAX,	SEXP_ACTION_OPERATOR,	},
 	{ "allow-warp",						OP_WARP_ALLOWED,						1,	INT_MAX,	SEXP_ACTION_OPERATOR,	},
 	{ "special-warpout-name",			OP_SET_SPECIAL_WARPOUT_NAME,			2,	2,			SEXP_ACTION_OPERATOR,	},
+	{ "get-ets-value",					OP_GET_ETS_VALUE,						2,	2,			SEXP_ACTION_OPERATOR,	},	// niffiwan
+	{ "set-ets-values",					OP_SET_ETS_VALUES,						4,	INT_MAX,	SEXP_ACTION_OPERATOR,	},	// niffiwan
 
 	//Subsystems and Health Sub-Category
 	{ "ship-invulnerable",				OP_SHIP_INVULNERABLE,					1,	INT_MAX,	SEXP_ACTION_OPERATOR,	},
@@ -15101,6 +15103,90 @@
 	return (int)(100.0f * Energy_levels[Ships[sindex].weapon_recharge_index]);
 }
 
+/**
+ * retrieve one ETS index from a ship
+ */
+int sexp_get_ets_value(int node)
+{
+	int sindex;
+	SCP_string ets_type;
+
+	ets_type = CTEXT(node);
+	node = CDR(node);
+
+	sindex = ship_name_lookup(CTEXT(node));
+	if (sindex < 0) {
+		return SEXP_FALSE;
+	}
+	if (Ships[sindex].objnum < 0) {
+		return SEXP_FALSE;
+	}
+
+	if (!stricmp(ets_type.c_str(), "engine")) {
+		return Ships[sindex].engine_recharge_index;
+	} else if (!stricmp(ets_type.c_str(), "shield")) {
+		return Ships[sindex].shield_recharge_index;
+	} else if (!stricmp(ets_type.c_str(), "weapon")) {
+		return Ships[sindex].weapon_recharge_index;
+	} else {
+		return SEXP_FALSE;
+	}
+}
+
+/**
+ * set all ETS indexes for one or more ships
+ */
+void sexp_set_ets_values(int node)
+{
+	int sindex;
+	int ets_idx[num_retail_ets_gauges];
+
+	ets_idx[ENGINES] = eval_num(node);
+	node = CDR(node);
+	ets_idx[SHIELDS] = eval_num(node);
+	node = CDR(node);
+	ets_idx[WEAPONS] = eval_num(node);
+	node = CDR(node);
+
+	// sanity check inputs
+	sanity_check_ets_inputs(ets_idx);
+
+	multi_start_callback();
+
+	// apply ETS settings to specified ships
+	for ( ; node != -1; node = CDR(node)) {
+		sindex = ship_name_lookup(CTEXT(node));
+
+		if (sindex >= 0 && validate_ship_ets_indxes(sindex, ets_idx)) {
+			Ships[sindex].engine_recharge_index = ets_idx[ENGINES];
+			Ships[sindex].shield_recharge_index = ets_idx[SHIELDS];
+			Ships[sindex].weapon_recharge_index = ets_idx[WEAPONS];
+
+			multi_send_ship(sindex);
+			multi_send_int(ets_idx[ENGINES]);
+			multi_send_int(ets_idx[SHIELDS]);
+			multi_send_int(ets_idx[WEAPONS]);
+		}
+	}
+	multi_end_callback();
+}
+
+void multi_sexp_set_ets_values()
+{
+	int sindex;
+	int ets_idx[num_retail_ets_gauges];
+
+	while (multi_get_ship(sindex)) {
+		multi_get_int(ets_idx[ENGINES]);
+		multi_get_int(ets_idx[SHIELDS]);
+		multi_get_int(ets_idx[WEAPONS]);
+
+		Ships[sindex].engine_recharge_index = ets_idx[ENGINES];
+		Ships[sindex].shield_recharge_index = ets_idx[SHIELDS];
+		Ships[sindex].weapon_recharge_index = ets_idx[WEAPONS];
+	}
+}
+
 int sexp_shield_quad_low(int node)
 {
 	int sindex, idx;	
@@ -23188,6 +23274,15 @@
 				sexp_val = sexp_weapon_recharge_pct(node);
 				break;
 
+			case OP_GET_ETS_VALUE:
+				sexp_val = sexp_get_ets_value(node);
+				break;
+
+			case OP_SET_ETS_VALUES:
+				sexp_val = SEXP_TRUE;
+				sexp_set_ets_values(node);
+				break;
+
 			case OP_SHIELD_QUAD_LOW:
 				sexp_val = sexp_shield_quad_low(node);
 				break;
@@ -24045,6 +24140,10 @@
 				sexp_reset_time_compression();
 				break;
 
+			case OP_SET_ETS_VALUES:
+				multi_sexp_set_ets_values();
+				break;
+
 			// bad sexp in the packet
 			default: 
 				// probably just a version error where the host supports a SEXP but a client does not
@@ -24377,6 +24476,7 @@
 		case OP_CUTSCENES_GET_FOV:
 		case OP_NUM_VALID_ARGUMENTS:
 		case OP_STRING_GET_LENGTH:
+		case OP_GET_ETS_VALUE:
 			return OPR_POSITIVE;
 
 		case OP_COND:
@@ -24690,6 +24790,7 @@
 		case OP_NEBULA_CHANGE_PATTERN:
 		case OP_COPY_VARIABLE_FROM_INDEX:
 		case OP_COPY_VARIABLE_BETWEEN_INDEXES:
+		case OP_SET_ETS_VALUES:
 			return OPR_NULL;
 
 		case OP_AI_CHASE:
@@ -26213,6 +26314,20 @@
 		case OP_ENGINE_RECHARGE_PCT:
 			return OPF_SHIP;			
 
+		case OP_GET_ETS_VALUE:
+			if (argnum == 0) {
+				return OPF_STRING;
+			} else {
+				return OPF_SHIP;
+			}
+
+		case OP_SET_ETS_VALUES:
+			if (argnum < 3) {
+				return OPF_POSITIVE;
+			} else {
+				return OPF_SHIP;
+			}
+
 		case OP_SHIELD_QUAD_LOW:
 			if(argnum == 0){
 				return OPF_SHIP;
@@ -28453,6 +28568,8 @@
 		case OP_SECONDARY_FIRED_SINCE:
 		case OP_HAS_PRIMARY_WEAPON:
 		case OP_HAS_SECONDARY_WEAPON:
+		case OP_GET_ETS_VALUE:
+		case OP_SET_ETS_VALUES:
 			return STATUS_SUBCATEGORY_SHIELDS_ENGINES_AND_WEAPONS;
 			
 		case OP_CARGO_KNOWN_DELAY:
@@ -31024,6 +31141,20 @@
 		"\tReturns a percentage from 0 to 100\r\n"
 		"\t1: Ship name\r\n" },
 
+	{ OP_GET_ETS_VALUE, "get-ets-values\r\n"
+		"\tGets one ETS index for a ship\r\n"
+		"\t1: ETS index to get, Engine|Shield|Weapon\r\n"
+		"\t2: Ship name\r\n"},
+
+	{ OP_SET_ETS_VALUES, "set-ets-values\r\n"
+		"\tSets ETS indexes for a ship\r\n"
+		"\tUse values retrieved with get-ets-value\r\n"
+		"\tIf you use your own values, make sure the add up to 12\r\n"
+		"\t1: Engine percent\r\n"
+		"\t2: Shields percent\r\n"
+		"\t3: Weapons percent\r\n"
+		"\t4: Ship name\r\n"},
+
 	{ OP_CARGO_NO_DEPLETE, "cargo-no-deplete\r\n"
 		"\tCauses the named ship to have unlimited cargo.\r\n"
 		"\tNote:  only applies to BIG or HUGE ships\r\n"
Index: code/parse/lua.cpp
===================================================================
--- code/parse/lua.cpp	(revision 9961)
+++ code/parse/lua.cpp	(working copy)
@@ -15,6 +15,7 @@
 #include "hud/hudbrackets.h"
 #include "hud/hudescort.h"
 #include "hud/hudconfig.h"
+#include "hud/hudets.h"
 #include "hud/hudgauges.h"
 #include "hud/hudets.h"
 #include "iff_defs/iff_defs.h"
@@ -8512,6 +8513,57 @@
 		return ADE_RETURN_FALSE;
 }
 
+ADE_VIRTVAR(EtsEngineIndex, l_Ship, "number", "(not implemented)", "number", "Ships ETS Engine index value, 0 to MAX_ENERGY_INDEX")
+{
+	object_h *objh=NULL;
+	int ets_idx = 0;
+
+	if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &ets_idx))
+		return ade_set_error(L, "i", 0);
+
+	if (!objh->IsValid())
+		return ade_set_error(L, "i", 0);
+
+	if(ADE_SETTING_VAR)
+		LuaError(L, "Attempted to set incomplete feature: ETS Engine Index (see EtsSetIndexes)");
+
+	return ade_set_args(L, "i", Ships[objh->objp->instance].engine_recharge_index);
+}
+
+ADE_VIRTVAR(EtsShieldIndex, l_Ship, "number", "(not implemented)", "number", "Ships ETS Shield index value, 0 to MAX_ENERGY_INDEX")
+{
+	object_h *objh=NULL;
+	int ets_idx = 0;
+
+	if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &ets_idx))
+		return ade_set_error(L, "i", 0);
+
+	if (!objh->IsValid())
+		return ade_set_error(L, "i", 0);
+
+	if(ADE_SETTING_VAR)
+		LuaError(L, "Attempted to set incomplete feature: ETS Shield Index (see EtsSetIndexes)");
+
+	return ade_set_args(L, "i", Ships[objh->objp->instance].shield_recharge_index);
+}
+
+ADE_VIRTVAR(EtsWeaponIndex, l_Ship, "number", "(not implemented)", "number", "Ships ETS Weapon index value, 0 to MAX_ENERGY_INDEX")
+{
+	object_h *objh=NULL;
+	int ets_idx = 0;
+
+	if (!ade_get_args(L, "o|i", l_Ship.GetPtr(&objh), &ets_idx))
+		return ade_set_error(L, "i", 0);
+
+	if (!objh->IsValid())
+		return ade_set_error(L, "i", 0);
+
+	if(ADE_SETTING_VAR)
+		LuaError(L, "Attempted to set incomplete feature: ETS Weapon Index (see EtsSetIndexes)");
+
+	return ade_set_args(L, "i", Ships[objh->objp->instance].weapon_recharge_index);
+}
+
 ADE_FUNC(kill, l_Ship, "[object Killer]", "Kills the ship. Set \"Killer\" to the ship you are killing to self-destruct", "boolean", "True if successful, false or nil otherwise")
 {
 	object_h *victim,*killer=NULL;
@@ -9162,6 +9214,33 @@
 	}
 }
 
+ADE_FUNC(EtsSetIndexes, l_Ship, "number Engine Index, number Shield Index, number Weapon Index",
+		"Sets ships ETS systems to specified values",
+		"boolean",
+		"True if successful, false if target ships ETS was missing, or only has one system")
+{
+	object_h *objh=NULL;
+	int ets_idx[num_retail_ets_gauges] = {0};
+
+	if (!ade_get_args(L, "oiii", l_Ship.GetPtr(&objh), &ets_idx[ENGINES], &ets_idx[SHIELDS], &ets_idx[WEAPONS]))
+		return ADE_RETURN_FALSE;
+
+	if (!objh->IsValid())
+		return ADE_RETURN_FALSE;
+
+	sanity_check_ets_inputs(ets_idx);
+
+	int sindex = objh->objp->instance;
+	if (validate_ship_ets_indxes(sindex, ets_idx)) {
+		Ships[sindex].engine_recharge_index = ets_idx[ENGINES];
+		Ships[sindex].shield_recharge_index = ets_idx[SHIELDS];
+		Ships[sindex].weapon_recharge_index = ets_idx[WEAPONS];
+		return ADE_RETURN_TRUE;
+	} else {
+		return ADE_RETURN_FALSE;
+	}
+}
+
 //**********HANDLE: Weapon
 ade_obj<object_h> l_Weapon("weapon", "Weapon handle", &l_Object);
 
Index: code/parse/sexp.h
===================================================================
--- code/parse/sexp.h	(revision 9961)
+++ code/parse/sexp.h	(working copy)
@@ -715,6 +715,8 @@
 
 #define OP_COPY_VARIABLE_FROM_INDEX			(0x0020 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Goober5000
 #define OP_COPY_VARIABLE_BETWEEN_INDEXES	(0x0021 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG) // Goober5000
+#define OP_GET_ETS_VALUE					(0x0022 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG)	// niffiwan
+#define OP_SET_ETS_VALUES					(0x0023 | OP_CATEGORY_CHANGE2 | OP_NONCAMPAIGN_FLAG)	// niffiwan
 
 // defined for AI goals
 #define OP_AI_CHASE							(0x0000 | OP_CATEGORY_AI | OP_NONCAMPAIGN_FLAG)

niffiwan

2013-10-19 09:11

developer   ~0015336

Karajorma - can you please have a look at the multi sexps to see if I've done the right thing here? The "set" sexp seems to work fine when I tested it with multiplayer. The "get" doesn't, but from some reading I presume that's because the variables are not marked as Network Variables?

karajorma

2013-10-27 17:57

administrator   ~0015359

The multi stuff looks fine but I did notice this minor typo

+ "\tIf you use your own values, make sure the add up to 12\r\n"


Should be "they" not "the"

niffiwan

2013-10-27 19:46

developer   ~0015360

Thanks for the review, I'll fix that up & commit this tonight or tomorrow.

niffiwan

2013-10-28 05:30

developer   ~0015367

Fix committed to trunk@9986.

Related Changesets

fs2open: trunk r9986

2013-10-28 01:54

niffiwan


Ported: N/A

Details Diff
Fix mantis 2889: add sexps's ets-get-value & ets-set-values Affected Issues
0002889
mod - /trunk/fs2_open/code/hud/hudets.cpp Diff File
mod - /trunk/fs2_open/code/hud/hudets.h Diff File
mod - /trunk/fs2_open/code/parse/lua.cpp Diff File
mod - /trunk/fs2_open/code/parse/sexp.cpp Diff File
mod - /trunk/fs2_open/code/parse/sexp.h Diff File

Issue History

Date Modified Username Field Change
2013-06-04 03:14 MjnMixael New Issue
2013-06-04 03:14 MjnMixael Status new => assigned
2013-06-04 03:14 MjnMixael Assigned To => niffiwan
2013-09-03 09:43 niffiwan Note Added: 0015260
2013-09-03 10:14 niffiwan Note Edited: 0015260
2013-09-03 10:14 niffiwan Note Edited: 0015260
2013-09-03 10:42 niffiwan Note Edited: 0015260
2013-09-03 10:49 niffiwan Note Edited: 0015260
2013-09-03 11:06 FelixJim Note Added: 0015262
2013-09-03 11:06 FUBAR-BDHR Note Added: 0015263
2013-09-03 12:46 MjnMixael Note Added: 0015265
2013-09-04 03:55 niffiwan Note Added: 0015267
2013-09-09 10:56 niffiwan File Added: mantis2889-svn.patch
2013-09-09 10:57 niffiwan File Added: ets_getset.fs2
2013-09-09 11:03 niffiwan Note Added: 0015268
2013-09-09 11:03 niffiwan Status assigned => feedback
2013-09-09 11:10 niffiwan File Deleted: ets_getset.fs2
2013-09-09 11:10 niffiwan File Added: ets_getset.fs2
2013-09-15 01:50 MjnMixael Note Added: 0015273
2013-09-15 01:50 MjnMixael Status feedback => assigned
2013-09-15 22:02 niffiwan Note Added: 0015274
2013-09-15 22:02 niffiwan Status assigned => code review
2013-09-19 14:47 The_E Note Added: 0015277
2013-09-19 16:03 Admiral MS Note Added: 0015278
2013-09-19 23:12 niffiwan Note Added: 0015279
2013-09-19 23:12 niffiwan Status code review => assigned
2013-09-26 07:48 niffiwan Note Added: 0015292
2013-09-29 19:55 Admiral MS Note Added: 0015304
2013-10-06 04:05 niffiwan File Deleted: mantis2889-svn.patch
2013-10-06 04:05 niffiwan File Added: mantis2889-svn.patch
2013-10-06 04:05 niffiwan File Added: ets-presets-sct.tbm
2013-10-06 04:11 niffiwan Note Added: 0015307
2013-10-06 04:11 niffiwan Status assigned => code review
2013-10-19 09:08 niffiwan File Deleted: mantis2889-svn.patch
2013-10-19 09:08 niffiwan File Added: mantis2889-now-with-multi-svn.patch
2013-10-19 09:11 niffiwan Note Added: 0015336
2013-10-27 17:57 karajorma Note Added: 0015359
2013-10-27 19:46 niffiwan Note Added: 0015360
2013-10-28 05:30 niffiwan Changeset attached => fs2open trunk r9986
2013-10-28 05:30 niffiwan Note Added: 0015367
2013-10-28 05:30 niffiwan Status code review => resolved
2013-10-28 05:30 niffiwan Resolution open => fixed