-
Notifications
You must be signed in to change notification settings - Fork 182
New guard-range sexp #7606
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
New guard-range sexp #7606
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1248,6 +1248,7 @@ bool SexpTreeModel::is_operator_hidden(int op_value) | |
| case OP_SET_DEBRIS_FIELD: | ||
| case OP_NEBULA_TOGGLE_POOF: | ||
| case OP_NEBULA_FADE_POOF: | ||
| case OP_SET_GUARD_RANGE: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be removed now that |
||
| return true; | ||
| default: | ||
| return false; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1162,22 +1162,39 @@ ADE_VIRTVAR(Orders, l_Ship, "shiporders", "Array of ship orders", "shiporders", | |
| return ade_set_args(L, "o", l_ShipOrders.Set(object_h(objh->objp()))); | ||
| } | ||
|
|
||
| ADE_VIRTVAR(MaxGuardRadius, l_Ship, "number", "Sets the max range in meters at which any ships guarding this ship will engage with threats. If the value is <= 0, regular dynamic guard range behavior will resume.", "number", "Max range in meters, or 0 if handle is invalid") | ||
| ADE_VIRTVAR(MaxGuardRadius, | ||
| l_Ship, | ||
| "number", | ||
| "Sets the max range in meters at which any ships guarding this ship will engage with threats. If the value is <= " | ||
| "0, regular dynamic guard range behavior will resume.", nullptr, | ||
| nullptr) | ||
| { | ||
| object_h *objh; | ||
| float new_max_guard_radius = -1; | ||
| if (!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &new_max_guard_radius)) | ||
| return ade_set_error(L, "f", 0.0f); | ||
| return ADE_RETURN_NIL; | ||
|
|
||
| if(!objh->isValid()) | ||
| return ade_set_error(L, "f", 0.0f); | ||
| return ADE_RETURN_NIL; | ||
|
|
||
| ship *shipp = &Ships[objh->objp()->instance]; | ||
| auto ship_entry = ship_registry_get(shipp->ship_name); | ||
| if (!ship_entry) | ||
| return ADE_RETURN_NIL; | ||
| if (ADE_SETTING_VAR) { | ||
| // Apply to every ship on this ship's team, mirroring sexp_set_guard_range's | ||
| // "all potential guardians" behavior. | ||
| for (ship_obj* so = GET_FIRST(&Ship_obj_list); so != END_OF_LIST(&Ship_obj_list); so = GET_NEXT(so)) { | ||
| if (Objects[so->objnum].flags[Object::Object_Flags::Should_be_dead]) | ||
| continue; | ||
|
|
||
| ship* guarding_shipp = &Ships[Objects[so->objnum].instance]; | ||
| if (guarding_shipp->team == shipp->team) | ||
| set_guard_range_ship(new_max_guard_radius, ship_entry, guarding_shipp); | ||
| } | ||
| } | ||
|
|
||
| if (ADE_SETTING_VAR) | ||
| shipp->max_guard_radius = new_max_guard_radius; | ||
|
|
||
| return ade_set_args(L, "f", shipp->max_guard_radius); | ||
| return ADE_RETURN_NIL; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Getting |
||
| } | ||
|
|
||
| ADE_VIRTVAR(WaypointSpeedCap, l_Ship, "number", "Waypoint speed cap", "number", "The limit on the ship's speed for traversing waypoints. -1 indicates no speed cap. 0 will be returned if handle is invalid.") | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,6 @@ class WarpEffect; | |
|
|
||
| // Part of the player died system. | ||
| extern vec3d Original_vec_to_deader; | ||
|
|
||
| // States for player death sequence, stuffed in Player_died_state. | ||
| #define PDS_NONE 1 | ||
| #define PDS_DIED 2 | ||
|
|
@@ -254,7 +253,8 @@ class ArmorType | |
|
|
||
| extern SCP_vector<ArmorType> Armor_types; | ||
|
|
||
| //************************************************************** | ||
| void set_guard_range_ship(float range, const ship_registry_entry* ship_entry, ship* shipp); | ||
| //************************************************************** | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this indent ought to be fixed |
||
| //WMC - Damage type handling code | ||
|
|
||
| typedef struct DamageTypeStruct | ||
|
|
@@ -336,7 +336,11 @@ typedef struct lock_info { | |
| float lock_gauge_time_elapsed; | ||
| float lock_anim_time_elapsed; | ||
| } lock_info; | ||
|
|
||
| struct guard_range_entry { | ||
| float range; | ||
| int shipnum; | ||
| guard_range_entry(float _range, int _shipnum) : range(_range), shipnum(_shipnum) {} | ||
| }; | ||
| // structure definition for a linked list of subsystems for a ship. Each subsystem has a pointer | ||
| // to the static data for the subsystem. The obj_subsystem data is defined and read in the model | ||
| // code. Other dynamic data (such as current_hits) should remain in this structure. | ||
|
|
@@ -623,7 +627,9 @@ class ship | |
| float max_weapon_regen_per_second; // wookieejedi - make this a ship object variable | ||
|
|
||
| int ship_guardian_threshold; // Goober5000 - now also determines whether ship is guardian'd | ||
| float max_guard_radius; // Optional clamp for guard engagement/resume ranges; <= 0 means unused | ||
|
|
||
| SCP_vector<guard_range_entry> | ||
| max_guard_ranges; // Optional clamp for guard engagement/resume ranges; <= 0 means unused | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
|
||
|
|
||
| char ship_name[NAME_LENGTH]; | ||
|
|
@@ -877,7 +883,6 @@ struct ai_target_priority { | |
| flagset<Ship::Info_Flags> sif_flags; | ||
| flagset<Weapon::Info_Flags> wif_flags; | ||
| }; | ||
|
|
||
| extern SCP_vector <ai_target_priority> Ai_tp_list; | ||
|
|
||
| void parse_ai_target_priorities(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at Claude's previous review a bit more closely, it noticed the right symptom but made the wrong recommendation. Since the guard information is only valid for the lifetime of a ship, it is appropriate to use the
shipnumindex intoShips[]as the stored index. The ship registry index adds complexity and extra processing for no benefit.Now, doing this will risk leaving a stale guarded shipnum when the ship is destroyed, so the solution to that is to clean it up in
ai_ship_destroy. You can check for stale guard thresholds in the "wipe out this ship as a target" loop.