@@ -703,6 +703,8 @@ SCP_vector<sexp_oper> Operators = {
703703 { "hud-force-sensor-static", OP_HUD_FORCE_SENSOR_STATIC, 1, 1, SEXP_ACTION_OPERATOR, }, // MjnMixael
704704 { "hud-force-emp-effect", OP_HUD_FORCE_EMP_EFFECT, 2, 3, SEXP_ACTION_OPERATOR, }, // MjnMixael
705705 { "set-squadron-wings", OP_SET_SQUADRON_WINGS, 1, MAX_SQUADRON_WINGS, SEXP_ACTION_OPERATOR, }, // Goober5000
706+ { "set-player-target", OP_SET_PLAYER_TARGET, 1, 2, SEXP_ACTION_OPERATOR, }, // LuytenKy
707+ { "clear-player-target", OP_CLEAR_PLAYER_TARGET, 0, 0, SEXP_ACTION_OPERATOR, }, // LuytenKy
706708
707709 //Nav Sub-Category
708710 { "add-nav-waypoint", OP_NAV_ADD_WAYPOINT, 3, 4, SEXP_ACTION_OPERATOR, }, //kazan
@@ -13923,6 +13925,44 @@ void sexp_set_friendly_damage_caps(int n) {
1392313925 }
1392413926}
1392513927
13928+ // Luytenky
13929+ /*
13930+ * Sets the player's target to the specified, either ship, and or the subsystem on said ship.
13931+ */
13932+ void sexp_set_player_target(int node)
13933+ {
13934+ int shipnum = ship_name_lookup(CTEXT(node), 1);
13935+ if (shipnum < 0)
13936+ return;
13937+ ship* shipp = &Ships[shipnum];
13938+ int objnum = shipp->objnum;
13939+ int n = CDR(node);
13940+ if (n >= 0) {
13941+ const char* subsys_name = CTEXT(n);
13942+ if (stricmp(subsys_name, SEXP_NONE_STRING) != 0) {
13943+ ship_subsys* ss = ship_get_subsys(shipp, subsys_name);
13944+ // target ship regardless of whether subsystem is destroyed
13945+ shipp->last_targeted_subobject[Player_num] = ss;
13946+ } else {
13947+ shipp->last_targeted_subobject[Player_num] = nullptr;
13948+ }
13949+ } else {
13950+ shipp->last_targeted_subobject[Player_num] = nullptr;
13951+ }
13952+ // set_target_objnum will call hud_restore_subsystem_target which reads last_targeted_subobject
13953+ set_target_objnum(Player_ai, objnum);
13954+ }
13955+
13956+ // Luytenky
13957+ /*
13958+ * Clears the player's targeting.
13959+ */
13960+ void sexp_clear_player_target()
13961+ {
13962+ set_target_objnum(Player_ai, -1);
13963+ set_targeted_subsys(Player_ai, nullptr, -1);
13964+ }
13965+
1392613966// Karajorma
1392713967void sexp_allow_treason (int n)
1392813968{
@@ -29109,6 +29149,16 @@ int eval_sexp(int cur_node, int referenced_node)
2910929149 sexp_val = SEXP_TRUE;
2911029150 break;
2911129151
29152+ // LuytenKy
29153+ case OP_SET_PLAYER_TARGET:
29154+ sexp_set_player_target(node);
29155+ sexp_val = SEXP_TRUE;
29156+ break;
29157+ case OP_CLEAR_PLAYER_TARGET:
29158+ sexp_clear_player_target();
29159+ sexp_val = SEXP_TRUE;
29160+ break;
29161+
2911229162 // Kestrellius
2911329163 case OP_SET_FRIENDLY_DAMAGE_CAPS:
2911429164 sexp_set_friendly_damage_caps(node);
@@ -31737,6 +31787,8 @@ int query_operator_return_type(int op)
3173731787 case OP_TRIGGER_SUBMODEL_ANIMATION:
3173831788 case OP_PLAYER_USE_AI:
3173931789 case OP_PLAYER_NOT_USE_AI:
31790+ case OP_SET_PLAYER_TARGET:
31791+ case OP_CLEAR_PLAYER_TARGET:
3174031792 case OP_SET_FRIENDLY_DAMAGE_CAPS:
3174131793 case OP_ALLOW_TREASON:
3174231794 case OP_SET_PLAYER_ORDERS:
@@ -33207,6 +33259,12 @@ int query_operator_argument_type(int op, int argnum)
3320733259 case OP_PLAYER_NOT_USE_AI:
3320833260 return OPF_NONE;
3320933261
33262+ case OP_SET_PLAYER_TARGET:
33263+ if (argnum == 0)
33264+ return OPF_SHIP;
33265+ else
33266+ return OPF_SUBSYSTEM_OR_NONE;
33267+
3321033268 case OP_CREATE_BOLT:
3321133269 if (argnum == 0)
3321233270 return OPF_BOLT_TYPE;
@@ -36870,6 +36928,8 @@ int get_category(int op_id)
3687036928 case OP_ROTATING_SUBSYS_SET_TURN_TIME:
3687136929 case OP_PLAYER_USE_AI:
3687236930 case OP_PLAYER_NOT_USE_AI:
36931+ case OP_SET_PLAYER_TARGET:
36932+ case OP_CLEAR_PLAYER_TARGET:
3687336933 case OP_HUD_DISABLE_EXCEPT_MESSAGES:
3687436934 case OP_FORCE_JUMP:
3687536935 case OP_HUD_SET_TEXT:
@@ -37257,6 +37317,8 @@ int get_subcategory(int op_id)
3725737317 case OP_CHANGE_AI_CLASS:
3725837318 case OP_PLAYER_USE_AI:
3725937319 case OP_PLAYER_NOT_USE_AI:
37320+ case OP_SET_PLAYER_TARGET:
37321+ case OP_CLEAR_PLAYER_TARGET:
3726037322 case OP_SET_PLAYER_ORDERS:
3726137323 case OP_CAP_WAYPOINT_SPEED:
3726237324 case OP_SET_WING_FORMATION:
@@ -41800,6 +41862,17 @@ SCP_vector<sexp_help_struct> Sexp_help = {
4180041862 "\tCauses the player's ship to not be controlled by the FreeSpace AI. Takes 0 arguments.\r\n"
4180141863 },
4180241864
41865+ // LuytenKy
41866+ { OP_SET_PLAYER_TARGET, "set-player-target\r\n"
41867+ "\tSets the player's current target to the specified ship, and optionally a subsystem on that ship.\r\n"
41868+ "\tIf the subsystem is destroyed, the ship will still be targeted. Takes 1 to 2 arguments.\r\n"
41869+ "\t1:\tThe ship to target.\r\n"
41870+ "\t2:\t(Optional) The subsystem to target. Use <none> to target no subsystem.\r\n"
41871+ },
41872+ { OP_CLEAR_PLAYER_TARGET, "clear-player-target\r\n"
41873+ "\tClears the player's current target and subsystem target. Takes 0 arguments.\r\n"
41874+ },
41875+
4180341876 // Kestrellius
4180441877 { OP_SET_FRIENDLY_DAMAGE_CAPS, "set-friendly-damage-caps\r\n"
4180541878 "\tSets limits on damage weapons and beams can do to friendly targets on the current difficulty level.\r\n"
0 commit comments