Skip to content

Commit 74beab5

Browse files
authored
Merge pull request scp-fs2open#6790 from Goober5000/order_fixes
clean up Target virtvar in order.cpp
2 parents acf367e + 2a62f04 commit 74beab5

1 file changed

Lines changed: 35 additions & 30 deletions

File tree

code/scripting/api/objs/order.cpp

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
227227
case AI_GOAL_IGNORE:
228228
case AI_GOAL_EVADE_SHIP:
229229
case AI_GOAL_STAY_NEAR_SHIP:
230-
case AI_GOAL_KEEP_SAFE_DISTANCE:
231230
case AI_GOAL_FLY_TO_SHIP:
232231
case AI_GOAL_STAY_STILL:
233232
if ((newh->objp()->type == OBJ_SHIP) && stricmp(Ships[newh->objp()->instance].ship_name, ohp->aigp->target_name)) {
@@ -241,6 +240,12 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
241240
}
242241
break;
243242

243+
case AI_GOAL_REARM_REPAIR:
244+
case AI_GOAL_DOCK:
245+
case AI_GOAL_UNDOCK:
246+
// TODO: these are currently not implemented, but could be implemented in the future
247+
break;
248+
244249
case AI_GOAL_CHASE_WEAPON:
245250
if ((newh->objp()->type == OBJ_WEAPON) && (ohp->aigp->target_signature != newh->sig)){
246251
ohp->aigp->target_instance = newh->objp()->instance;
@@ -255,8 +260,20 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
255260
break;
256261

257262
case AI_GOAL_CHASE_SHIP_CLASS:
258-
// a ship class isn't an in-mission object
259-
return ade_set_error(L, "o", l_Object.Set(object_h()));
263+
// we can set the ship class from the class of the target
264+
if (newh->objp()->type == OBJ_SHIP) {
265+
auto class_name = Ship_info[Ships[newh->objp()->instance].ship_info_index].name;
266+
if (stricmp(class_name, ohp->aigp->target_name)) {
267+
ohp->aigp->target_name = ai_get_goal_target_name(class_name, &ohp->aigp->target_name_index);
268+
ohp->aigp->time = (ohp->odx == 0) ? Missiontime : 0;
269+
270+
if (ohp->odx == 0) {
271+
aip->ok_to_target_timestamp = timestamp(0);
272+
set_target_objnum(aip, newh->objnum);
273+
}
274+
}
275+
}
276+
break;
260277

261278
case AI_GOAL_WAYPOINTS:
262279
case AI_GOAL_WAYPOINTS_ONCE:
@@ -274,20 +291,6 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
274291
break;
275292

276293
case AI_GOAL_CHASE_WING:
277-
if ((newh->objp()->type == OBJ_SHIP) && stricmp(Ships[newh->objp()->instance].ship_name, ohp->aigp->target_name)) {
278-
ship *shipp = &Ships[newh->objp()->instance];
279-
if (shipp->wingnum != -1){
280-
ohp->aigp->target_name = ai_get_goal_target_name(Wings[shipp->wingnum].name, &ohp->aigp->target_name_index);
281-
ohp->aigp->time = (ohp->odx == 0) ? Missiontime : 0;
282-
283-
if(ohp->odx == 0) {
284-
aip->ok_to_target_timestamp = timestamp(0);
285-
ai_attack_wing(ohp->objh.objp(),shipp->wingnum);
286-
}
287-
}
288-
}
289-
break;
290-
291294
case AI_GOAL_GUARD_WING:
292295
if ((newh->objp()->type == OBJ_SHIP) && stricmp(Ships[newh->objp()->instance].ship_name, ohp->aigp->target_name)) {
293296
ship *shipp = &Ships[newh->objp()->instance];
@@ -297,11 +300,16 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
297300

298301
if(ohp->odx == 0) {
299302
aip->ok_to_target_timestamp = timestamp(0);
300-
ai_set_guard_wing(ohp->objh.objp(),shipp->wingnum);
303+
304+
if (ohp->aigp->ai_mode == AI_GOAL_CHASE_WING)
305+
ai_attack_wing(ohp->objh.objp(),shipp->wingnum);
306+
else // AI_GOAL_GUARD_WING
307+
ai_set_guard_wing(ohp->objh.objp(), shipp->wingnum);
301308
}
302309
}
303310
}
304311
break;
312+
305313
default:
306314
break;
307315
}
@@ -311,7 +319,6 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
311319
switch(ohp->aigp->ai_mode){
312320
case AI_GOAL_DESTROY_SUBSYSTEM:
313321
case AI_GOAL_CHASE:
314-
case AI_GOAL_DOCK:
315322
case AI_GOAL_FORM_ON_WING:
316323
case AI_GOAL_GUARD:
317324
case AI_GOAL_DISABLE_SHIP:
@@ -322,18 +329,23 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
322329
case AI_GOAL_IGNORE:
323330
case AI_GOAL_EVADE_SHIP:
324331
case AI_GOAL_STAY_NEAR_SHIP:
325-
case AI_GOAL_KEEP_SAFE_DISTANCE:
326-
case AI_GOAL_REARM_REPAIR:
327332
case AI_GOAL_FLY_TO_SHIP:
333+
case AI_GOAL_STAY_STILL:
334+
case AI_GOAL_REARM_REPAIR:
335+
case AI_GOAL_DOCK:
328336
case AI_GOAL_UNDOCK:
329337
shipnum = ship_name_lookup(ohp->aigp->target_name);
330-
objnum = Ships[shipnum].objnum;
338+
objnum = (shipnum >= 0) ? Ships[shipnum].objnum : -1;
331339
break;
332340

333341
case AI_GOAL_CHASE_WEAPON:
334342
objnum = Weapons[ohp->aigp->target_instance].objnum;
335343
break;
336344

345+
case AI_GOAL_CHASE_SHIP_CLASS:
346+
// a ship class isn't an in-mission object
347+
return ade_set_args(L, "o", l_Object.Set(object_h()));
348+
337349
case AI_GOAL_WAYPOINTS:
338350
case AI_GOAL_WAYPOINTS_ONCE:
339351
// check if waypoint order is the current goal (ohp->odx == 0) and if it is valid
@@ -349,14 +361,6 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
349361
}
350362
break;
351363

352-
case AI_GOAL_STAY_STILL:
353-
shipnum = ship_name_lookup(ohp->aigp->target_name);
354-
if (shipnum != -1){
355-
objnum = Ships[shipnum].objnum;
356-
break;
357-
}
358-
break;
359-
360364
case AI_GOAL_CHASE_WING:
361365
case AI_GOAL_GUARD_WING:
362366
wingnum = wing_name_lookup(ohp->aigp->target_name);
@@ -365,6 +369,7 @@ ADE_VIRTVAR(Target, l_Order, "object", "Target of the order. Value may also be a
365369
objnum = Ships[shipnum].objnum;
366370
}
367371
break;
372+
368373
default:
369374
break;
370375
}

0 commit comments

Comments
 (0)