Skip to content

Commit 279182e

Browse files
committed
Preliminary cleanup of goal code. Remove AI_GOAL_PLACEHOLDER_1 since it is not needed; goals higher than AI_GOAL_NONE do not need to be a specific value.
1 parent 8102feb commit 279182e

5 files changed

Lines changed: 22 additions & 37 deletions

File tree

code/ai/aigoals.cpp

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ struct ship_registry_entry;
5353
// PURGE_GOALS_ONE_SHIP for goals which should only purge other goals in the one ship.
5454
// Goober5000 - note that the new disable and disarm goals (AI_GOAL_DISABLE_SHIP_TACTICAL and
5555
// AI_GOAL_DISARM_SHIP_TACTICAL) do not purge ANY goals, not even the ones in the one ship
56-
inline bool purge_goals_all_ships(ai_goal_mode ai_mode)
56+
[[nodiscard]] bool purge_goals_all_ships(ai_goal_mode ai_mode)
5757
{
5858
return ai_mode == AI_GOAL_IGNORE || ai_mode == AI_GOAL_DISABLE_SHIP || ai_mode == AI_GOAL_DISARM_SHIP;
5959
}
60-
inline bool purge_goals_one_ship(ai_goal_mode ai_mode)
60+
[[nodiscard]] bool purge_goals_one_ship(ai_goal_mode ai_mode)
6161
{
6262
return ai_mode == AI_GOAL_IGNORE_NEW;
6363
}
@@ -195,12 +195,10 @@ void ai_maybe_add_form_goal(wing* wingp)
195195
return;
196196
}
197197

198-
int j;
199-
200198
// iterate through the ship_index list of this wing and check for orders. We will do
201199
// this for all ships in the wing instead of on a wing only basis in case some ships
202200
// in the wing actually have different orders than others
203-
for (j = 0; j < wingp->current_count; j++) {
201+
for (int j = 0; j < wingp->current_count; j++) {
204202
ai_info* aip;
205203

206204
Assert(wingp->ship_index[j] != -1); // get Allender
@@ -938,11 +936,9 @@ void ai_add_goal_sub_sexp( int sexp, ai_goal_type type, ai_info *aip, ai_goal *a
938936
// for achievability.
939937
aigp->target_name = ai_get_goal_target_name(CTEXT(CDR(node)), &aigp->target_name_index); // waypoint path name;
940938

941-
942939
aigp->priority = eval_num(CDDR(node), priority_is_nan, priority_is_nan_forever);
943-
aigp->ai_mode = AI_GOAL_WAYPOINTS;
944-
if ( op == OP_AI_WAYPOINTS_ONCE )
945-
aigp->ai_mode = AI_GOAL_WAYPOINTS_ONCE;
940+
aigp->ai_mode = (op == OP_AI_WAYPOINTS_ONCE) ? AI_GOAL_WAYPOINTS_ONCE : AI_GOAL_WAYPOINTS;
941+
946942
if (CDDDDR(node) < 0)
947943
aigp->int_data = 0; // handle optional node separately because we don't subtract 1 here
948944
else
@@ -1042,13 +1038,9 @@ void ai_add_goal_sub_sexp( int sexp, ai_goal_type type, ai_info *aip, ai_goal *a
10421038
break;
10431039

10441040
case OP_AI_PLAY_DEAD:
1045-
aigp->priority = eval_num(CDR(node), priority_is_nan, priority_is_nan_forever);
1046-
aigp->ai_mode = AI_GOAL_PLAY_DEAD;
1047-
break;
1048-
10491041
case OP_AI_PLAY_DEAD_PERSISTENT:
10501042
aigp->priority = eval_num(CDR(node), priority_is_nan, priority_is_nan_forever);
1051-
aigp->ai_mode = AI_GOAL_PLAY_DEAD_PERSISTENT;
1043+
aigp->ai_mode = (op == OP_AI_PLAY_DEAD) ? AI_GOAL_PLAY_DEAD : AI_GOAL_PLAY_DEAD_PERSISTENT;
10521044
break;
10531045

10541046
case OP_AI_KEEP_SAFE_DISTANCE:
@@ -1295,12 +1287,9 @@ int ai_remove_goal_sexp_sub( int sexp, ai_goal* aigp, bool &remove_more )
12951287
/* We now need to determine what the mode and submode values are*/
12961288
switch( op )
12971289
{
1298-
case OP_AI_WAYPOINTS_ONCE:
1299-
goalmode = AI_GOAL_WAYPOINTS_ONCE;
1300-
priority = eval_priority_et_seq(CDDR(node));
1301-
break;
13021290
case OP_AI_WAYPOINTS:
1303-
goalmode = AI_GOAL_WAYPOINTS;
1291+
case OP_AI_WAYPOINTS_ONCE:
1292+
goalmode = (op == OP_AI_WAYPOINTS_ONCE) ? AI_GOAL_WAYPOINTS_ONCE : AI_GOAL_WAYPOINTS;
13041293
priority = eval_priority_et_seq(CDDR(node));
13051294
break;
13061295
case OP_AI_DESTROY_SUBSYS:
@@ -2548,16 +2537,14 @@ void ai_process_mission_orders( int objnum, ai_info *aip )
25482537
break;
25492538

25502539
case AI_GOAL_PLAY_DEAD:
2551-
// if a ship is playing dead, MWA says that it shouldn't try to do anything else.
2552-
// clearing out goals is okay here since we are now what mode to set this AI object to.
2553-
ai_clear_ship_goals( aip );
2554-
aip->mode = AIM_PLAY_DEAD;
2555-
aip->submode = -1;
2556-
aip->submode_start_time = Missiontime;
2557-
break;
2558-
25592540
case AI_GOAL_PLAY_DEAD_PERSISTENT:
2560-
// same as above, but we don't clear out ship goals
2541+
// we don't clear out ship goals for the "persistent" goal variant
2542+
if (current_goal->ai_mode == AI_GOAL_PLAY_DEAD)
2543+
{
2544+
// if a ship is playing dead, MWA says that it shouldn't try to do anything else.
2545+
// clearing out goals is okay here since we are now what mode to set this AI object to.
2546+
ai_clear_ship_goals(aip);
2547+
}
25612548
aip->mode = AIM_PLAY_DEAD;
25622549
aip->submode = -1;
25632550
aip->submode_start_time = Missiontime;

code/ai/aigoals.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ enum class ai_goal_type
4747
enum ai_goal_mode : uint8_t
4848
{
4949
AI_GOAL_NONE = 0,
50-
AI_GOAL_PLACEHOLDER_1,
5150

52-
AI_GOAL_CHASE, // per the original #define list, AI_GOAL_CHASE started at 2 (1<<1)
51+
AI_GOAL_CHASE,
5352
AI_GOAL_DOCK, // used for undocking as well
5453
AI_GOAL_WAYPOINTS,
5554
AI_GOAL_WAYPOINTS_ONCE,

code/parse/sexp.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39811,9 +39811,9 @@ SCP_vector<sexp_help_struct> Sexp_help = {
3981139811
"\t1:\tName of target to ignore.\r\n"
3981239812
"\t2:\tGoal priority (number between 0 and 89) - note, this does not imply any ranking of ignored targets." },
3981339813

39814-
{ OP_AI_STAY_STILL, "Ai-stay still (Ship goal)\r\n"
39814+
{ OP_AI_STAY_STILL, "Ai-stay-still (Ship goal)\r\n"
3981539815
"\tCauses the specified ship to stay still. The ship will do nothing until attacked at "
39816-
"which time the ship will come to life and defend itself.\r\n\r\n"
39816+
"which time the ship will come to life and defend itself. All other goals specified for the ship will be cleared.\r\n\r\n"
3981739817
"Takes 2 arguments...\r\n"
3981839818
"\t1:\tShip or waypoint the ship staying still will directly face (currently not implemented)\r\n"
3981939819
"\t2:\tGoal priority (number between 0 and 89)." },
@@ -39841,7 +39841,7 @@ SCP_vector<sexp_help_struct> Sexp_help = {
3984139841

3984239842
{ OP_AI_FORM_ON_WING, "Ai-form-on-wing (Ship Goal)\r\n"
3984339843
"\tCauses the ship to form on the specified ship's wing. This works analogous to the "
39844-
"player order, and will cause all other goals specified for the ship to be purged.\r\n\r\n"
39844+
"player order, and will cause all other goals specified for the ship to be cleared.\r\n\r\n"
3984539845
"Takes 1 argument...\r\n"
3984639846
"\t1:\tShip to form on." },
3984739847

code/scripting/api/objs/order.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ ADE_FUNC(getType, l_Order, NULL, "Gets the type of the order.", "enumeration", "
9191

9292
switch(ohp->aigp->ai_mode){
9393
case AI_GOAL_NONE:
94-
case AI_GOAL_PLACEHOLDER_1:
9594
case AI_GOAL_NUM_VALUES:
9695
break;
9796
case AI_GOAL_DESTROY_SUBSYSTEM:
@@ -223,8 +222,8 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
223222
case AI_GOAL_DISABLE_SHIP_TACTICAL:
224223
case AI_GOAL_DISARM_SHIP:
225224
case AI_GOAL_DISARM_SHIP_TACTICAL:
226-
case AI_GOAL_IGNORE_NEW:
227225
case AI_GOAL_IGNORE:
226+
case AI_GOAL_IGNORE_NEW:
228227
case AI_GOAL_EVADE_SHIP:
229228
case AI_GOAL_STAY_NEAR_SHIP:
230229
case AI_GOAL_KEEP_SAFE_DISTANCE:
@@ -318,8 +317,8 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
318317
case AI_GOAL_DISABLE_SHIP_TACTICAL:
319318
case AI_GOAL_DISARM_SHIP:
320319
case AI_GOAL_DISARM_SHIP_TACTICAL:
321-
case AI_GOAL_IGNORE_NEW:
322320
case AI_GOAL_IGNORE:
321+
case AI_GOAL_IGNORE_NEW:
323322
case AI_GOAL_EVADE_SHIP:
324323
case AI_GOAL_STAY_NEAR_SHIP:
325324
case AI_GOAL_KEEP_SAFE_DISTANCE:

code/scripting/api/objs/ship.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ ADE_FUNC(giveOrder, l_Ship, "enumeration Order, [object Target=nil, subsystem Ta
16411641
{
16421642
if(tgh_valid && tgh->objp()->type == OBJ_WAYPOINT)
16431643
{
1644-
ai_mode = eh->index == LE_ORDER_WAYPOINTS_ONCE ? AI_GOAL_WAYPOINTS_ONCE : AI_GOAL_WAYPOINTS;
1644+
ai_mode = (eh->index == LE_ORDER_WAYPOINTS_ONCE) ? AI_GOAL_WAYPOINTS_ONCE : AI_GOAL_WAYPOINTS;
16451645
int wp_list_index, wp_index;
16461646
calc_waypoint_indexes(tgh->objp()->instance, wp_list_index, wp_index);
16471647
if (wp_list_index >= 0 && wp_index >= 0)

0 commit comments

Comments
 (0)