2022-01-26 06:42 EST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002529FSSCPAIpublic2012-11-12 01:22
Assigned ToCommanderDJ 
Product Version3.6.12 
Target Version3.6.16Fixed in Version 
Summary0002529: AI guards leader of player's wing when ordered to guard player
DescriptionThis was originally reported as 0002299, but I was an uber-n00b back then and didn't know how to report or test stuff properly. If the player isn't number 1 in their wing and a ship is ordered to guard the player's ship, it will guard the leader of the player's wing regardless of whether that's the player or not. Whilst I've tested in 3.6.12 and various 3.6.13 builds up to rev 7933, Karajorma reckons the bug goes all the way back to retail.

Easily reproducible in the test mission attached. You're Alpha 2, press U in mission to give Beta 1 an order to guard Alpha 2. He will fly over to Alpha 1 and start guarding him whilst his order text will claim he is guarding Alpha 2
TagsNo tags attached.
Attached Files
  • ? file icon mantis2529_fixed.fs2 (5,210 bytes) 2011-10-28 09:22
  • patch file icon mantis_2529.patch (1,827 bytes) 2012-10-31 09:14 -
    Index: code/ai/ai_profiles.cpp
    --- code/ai/ai_profiles.cpp	(revision 9286)
    +++ code/ai/ai_profiles.cpp	(working copy)
    @@ -449,6 +449,8 @@
     			set_flag(profile, "$countermeasures affect aspect seekers:", AIPF2_ASPECT_LOCK_COUNTERMEASURE, AIP_FLAG2);
    +			set_flag(profile, "$ai guards specific ship in wing:", AIPF2_AI_GUARDS_SPECIFIC_SHIP_IN_WING, AIP_FLAG2);
     			profile->ai_path_mode = AI_PATH_MODE_NORMAL;
     			if(optional_string("$ai path mode:"))
    Index: code/ai/ai_profiles.h
    --- code/ai/ai_profiles.h	(revision 9286)
    +++ code/ai/ai_profiles.h	(working copy)
    @@ -63,6 +63,7 @@
     #define AIPF2_PLAYER_WEAPON_SCALE_FIX								(1 << 9)
     #define AIPF2_NO_WARP_CAMERA										(1 << 10)
     #define AIPF2_ASPECT_LOCK_COUNTERMEASURE							(1 << 11)
    +#define AIPF2_AI_GUARDS_SPECIFIC_SHIP_IN_WING						(1 << 12)
     // AI Path types
     #define	AI_PATH_MODE_NORMAL 0
    Index: code/ai/aicode.cpp
    --- code/ai/aicode.cpp	(revision 9286)
    +++ code/ai/aicode.cpp	(working copy)
    @@ -7366,9 +7366,9 @@
     	aip = &Ai_info[shipp->ai_index];
     	aip->avoid_check_timestamp = timestamp(1);
    -	//	If ship to guard is in a wing, guard that whole wing.
    +	//	If ship to guard is in a wing, guard that whole wing, unless the appropriate flag has been set
     	ai_info	*other_aip = &Ai_info[Ships[other_objp->instance].ai_index];
    -	if ((other_aip->wing != -1) && (other_aip->wing != aip->wing)) {
    +	if ((other_aip->wing != -1) && (other_aip->wing != aip->wing) && !(The_mission.ai_profile->flags2 & AIPF2_AI_GUARDS_SPECIFIC_SHIP_IN_WING)) {
     		ai_set_guard_wing(objp, Ai_info[Ships[other_objp->instance].ai_index].wing);
     	} else {
    patch file icon mantis_2529.patch (1,827 bytes) 2012-10-31 09:14 +




CommanderDJ (developer)

Urgh, silly me. The first test mission is borked. Please use the new file.


Goober5000 (administrator)

This is also a good bug to assign to CommanderDJ, despite the fact that he was the one who reported it. :p

It ought to be straightforward to investigate. Let me know if you need a hint as to where to start looking.


CommanderDJ (developer)

Well I'm going to start with the code for the add-goal SEXP and see what happens there. Failing that, I'm guessing the relevant code files will be somewhere in the AI folder. :D


CommanderDJ (developer)

Note to self: next time I'm on here and am not having my ass kicked by RL, I should ask Goober for that hint.


CommanderDJ (developer)

Relevant code that appears to be causing the "bug" is in ai_set_guard_object: AI automatically guards the whole wing if the ship they're supposed to guard is in a wing, and I assume default guarding behaviour for a wing is to form on the leader. If this is correct, I am unsure how to proceed as changing this behaviour may present a balance issue. Opinions? Perhaps add a special overriding case to ignore this behaviour when the ship to guard is a player?


CommanderDJ (developer)

Patch attached with the proposed fix. Tested and it works. If this is acceptable, could someone please commit it?


z64555 (developer)

Discussed earlier on #SCP with CommanderDJ, I found it to be most likely that this "bug, for all intents and purposes, works "as intended" by :v:.

Now, as you might have guessed, this behavior does not seem to be applicable/useful for craft that are not in the player's wing, nor if the player is not in the wing leader's position (i.g., the player is not Alpha 1).

CommanderDJ's patch, at the time of this writing, alters the behavior so that if a guard command is issued, and the craft to be guarded is the player's craft, then the AI(s) ordered to guard the player's craft will do so (instead of guarding the wing leader as per default behavior). This would solve the issue as he reported it, but the problem/feature will still be the same for all non-player craft (i.g., if you order an AI to guard Alpha 3, and the AI will guard Alpha 1 or whoever is the wing leader instead)


CommanderDJ (developer)

Last edited: 2012-10-31 07:52

View 2 revisions

z64555 is correct. Changing the behaviour so that this never occurs (ie the AI always guards the ship it is ordered to, even if that ship is in a wing) would be trivial also, but the question remains of whether this could affect balance and/or break missions that (intentionally or unintentionally) rely on the current behaviour.

EDIT: The_E pointed out that the obvious solution would be to make this an ai_profiles.tbl flag. Unless there are objections, that is how I will be going forward. The default setting will leave it as it is currently, and the flag will change it to the AI always guarding the ship it is ordered to.


CommanderDJ (developer)

Aaand here's the patch. Tested and verified. Once this is committed I will add the appropriate info to the wiki.


Goober5000 (administrator)

Fixed in revision 9341.

-Issue History
Date Modified Username Field Change
2011-10-28 09:15 CommanderDJ New Issue
2011-10-28 09:15 CommanderDJ Status new => assigned
2011-10-28 09:15 CommanderDJ Assigned To => Sushi_CW
2011-10-28 09:16 CommanderDJ File Added: mantis2529.fs2
2011-10-28 09:22 CommanderDJ File Added: mantis2529_fixed.fs2
2011-10-28 09:22 CommanderDJ Note Added: 0012903
2011-10-29 06:15 niffiwan File Deleted: mantis2529.fs2
2012-02-09 02:05 Goober5000 Note Added: 0013268
2012-02-09 02:05 Goober5000 Assigned To Sushi_CW => CommanderDJ
2012-02-10 22:43 CommanderDJ Note Added: 0013277
2012-04-24 03:06 CommanderDJ Note Added: 0013480
2012-10-29 01:47 CommanderDJ Note Added: 0014000
2012-10-29 01:59 CommanderDJ File Added: mantis_2529.patch
2012-10-29 01:59 CommanderDJ Note Added: 0014001
2012-10-29 02:00 CommanderDJ Status assigned => code review
2012-10-30 22:25 z64555 Note Added: 0014005
2012-10-31 07:42 CommanderDJ Note Added: 0014006
2012-10-31 07:52 CommanderDJ Note Edited: 0014006 View Revisions
2012-10-31 09:13 CommanderDJ File Deleted: mantis_2529.patch
2012-10-31 09:14 CommanderDJ File Added: mantis_2529.patch
2012-10-31 09:14 CommanderDJ Note Added: 0014007
2012-11-05 13:50 Goober5000 Target Version => 3.6.16
2012-11-12 01:22 Goober5000 Note Added: 0014034
2012-11-12 01:22 Goober5000 Status code review => resolved
2012-11-12 01:22 Goober5000 Resolution open => fixed
+Issue History