Page 1 of 1

Baffled about problem with attack code

Posted: Mon Jul 11, 2011 2:28 am
by UK_Eliter
Hi everyone

In trying to fix some rather broken stuff in the bounty hunter versions of my Fer-de-Lance 3G models, I've ended up with the following situation.

My NPCs attack when attacked, but only for a few seconds at a time. Moreover, when attacked, they tend - as well as firing, briefly - to either twitch their noses up and down a lot or just fly, slowly, in a straight-ish line away from me. Debugging-via-script shows they have me (the player) as their target and that they are in the right AI and right AI state (and it is a custom AI) and right behaviour (the behaviour being performAttack). My custom AI doesn't issue performAttack more than it should, the log shows all the right moves through AI states, the script isn't the problem (if I disable my script I still have the problems); I've tried changing my ship, and where I encounter the NPC - all to no avail.

Anyone seen this behaviour before? Or is there some way I can get more info on what the NPC is doing? I have the 'basic debug' oxp, but I can't get it to give me much info. I do have the logging option on (via my script) which shows all the directional lines - and these do bob around strangely for the NPC.

I'm on Windows, using Oolite 1.75.3 beta. Any help would be really appreciated.
PS: I hope I don't post this twice. I seemed to have a problem the first time I tried to post.

Re: Baffled about problem with attack code

Posted: Mon Jul 11, 2011 5:07 am
by Switeck
I've seen police Vipers come in for an attack run...and not fire.

Re: Baffled about problem with attack code

Posted: Mon Jul 11, 2011 6:17 am
by CommonSenseOTB
Could you post the AI.plist that you are currently using so we can all have a look see. It's hard to know what's really happening in AI from a description and 20 eyes are better than 2. :wink:

Re: Baffled about problem with attack code

Posted: Mon Jul 11, 2011 8:07 am
by Eric Walch
UK_Eliter wrote:
My NPCs attack when attacked, but only for a few seconds at a time. Moreover, when attacked, they tend - as well as firing, briefly - to either twitch their noses up and down a lot or just fly, slowly, in a straight-ish line away from me.
Internally there are two different attack behaviours. One is more aggressive than the other. The choice is based on having an odd or even ship ID. Try spawning two ships in one command. Than you have a ship with even and odd ID. When only one of those two gives the problems, than that will be the cause.

Re: Baffled about problem with attack code

Posted: Mon Jul 11, 2011 3:20 pm
by UK_Eliter
Dear all

Thanks for the replies.

I tried spawning two ships with the same command, but it made no difference. So here's the AI - or, rather, the two main AIs.

Code: Select all

	// ferdelance3-hunterAI

	GLOBAL =
	{
		ENTER = ("setStateTo: HEAD_FOR_WITCHPOINT");
	};

	HEAD_FOR_PLANET =
	{
		ENTER = ();
		UPDATE = 
		(
			"sendScriptMessage: scanForTargets",
			setCourseToPlanet, "setDesiredRangeTo: 50000.0", checkCourseToDestination,
			"pauseAI: 3"
		);
		COURSE_OK = (setSpeedToCruiseSpeed, performFlyToRangeFromDestination);
		WAYPOINT_SET = ("setAITo: gotoWaypointAI.plist");
		AEGIS_CLOSE_TO_MAIN_PLANET = ("setStateTo: HEAD_FOR_WITCHPOINT");
		DESIRED_RANGE_ACHIEVED = ("setStateTo: DECIDE_AT_WITCHPOINT");
		ACCEPT_DISTRESS_CALL =
		(
			setTargetToFoundTarget,
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-attackAI.plist"
		);
		OFFENCE_COMMITTED = 
		(
			setTargetToFoundTarget,
			"sendScriptMessage: considerAttackingOnOffence"
		);
		SUITABLE_TARGET_FOUND = 
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-interceptAI.plist"
		);
		NO_SUITABLE_TARGET_FOUND =
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-checkForLootAI.plist"
		);
		NORMAL_RESPONSE_TO_MISSILE =
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED,SUITABLE_TARGET_FOUND",
			fightOrFleeMissile, setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
		HAVE_CLOAKED_V_MISSILE = (performIdle);
		ATTACKED =
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED,SUITABLE_TARGET_FOUND", 
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist" 
		);
		HOLD_FULL = ("setStateTo: DECIDE_HOLDFULL");
		UPDATE = ();
		RESTARTED = (checkAegis);
	};

	HEAD_FOR_WITCHPOINT =
	{
		ENTER = ();
		COURSE_OK = (setSpeedToCruiseSpeed, performFlyToRangeFromDestination);
		WAYPOINT_SET = ("setAITo: gotoWaypointAI.plist");
		DESIRED_RANGE_ACHIEVED = ("setStateTo: HEAD_FOR_PLANET");
		UPDATE = 
		(
			"sendScriptMessage: scanForTargets",
			setCourseToWitchpoint, checkCourseToDestination,
			"pauseAI: 3"
		);
		ACCEPT_DISTRESS_CALL =
		(
			setTargetToFoundTarget,
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-attackAI.plist"
		);
		OFFENCE_COMMITTED = 
		(
			setTargetToFoundTarget, "sendScriptMessage: considerAttackingOnOffence"
		);
		SUITABLE_TARGET_FOUND = 
		(
			"dropMessages: COURSE_OK", "dropMessages: WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-interceptAI.plist"
		);
		NO_SUITABLE_TARGET_FOUND = 
		(
			"dropMessages: COURSE_OK", "dropMessages: WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-checkForLootAI.plist"
		);
		NORMAL_RESPONSE_TO_MISSILE =
		(
			"dropMessages: COURSE_OK", "dropMessages: WAYPOINT_SET", "dropMessages: DESIRED_RANGE_ACHIEVED,SUITABLE_TARGET_FOUND",
			fightOrFleeMissile,
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
		HAVE_CLOAKED_V_MISSILE = (performIdle);
		ATTACKED =
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED,SUITABLE_TARGET_FOUND", 
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
		HOLD_FULL = ("setStateTo: DECIDE_HOLDFULL");
	};

	DECIDE_AT_WITCHPOINT = 
	{
		ENTER = ("rollD: 10", "randomPauseAI: 1.5 5");
		ROLL_1 = ("setStateTo: HEAD_FOR_PLANET");
		ROLL_2 = ("setStateTo: HEAD_FOR_PLANET");
		ROLL_3 = ("setStateTo: EXIT_SYSTEM");
		ROLL_4 = ("setStateTo: LURK");
		ACCEPT_DISTRESS_CALL =
		(
			setTargetToFoundTarget,
			"setAITo: ferdelance3-attackAI.plist"
		);
		NORMAL_RESPONSE_TO_MISSILE =
		(
			fightOrFleeMissile,
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
		HAVE_CLOAKED_V_MISSILE = (performIdle);
		ATTACKED =
		(
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
	};

	DECIDE_AT_PLANET = 
	{
		ENTER = ("rollD: 10", "randomPauseAI: 1.5 5");
		ROLL_1 = ("setStateTo: HEAD_FOR_WITCHPOINT");
		ROLL_2 = ("setStateTo: HEAD_FOR_WITCHPOINT");
		ROLL_3 = ("setStateTo: EXIT_SYSTEM");
		ROLL_4 = ("setStateTo: LURK");
		ROLL_5 = ("setAITo: ferdelance3-dockingAI.plist");
		ROLL_6 = ("setAITo: ferdelance3-dockingAI.plist");
		ACCEPT_DISTRESS_CALL =
		(
			setTargetToFoundTarget,
			"setAITo: ferdelance3-attackAI.plist"
		);
		NORMAL_RESPONSE_TO_MISSILE =
		(
			fightOrFleeMissile,
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
		HAVE_CLOAKED_V_MISSILE = (performIdle);
		ATTACKED =
		(
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
	};

	DECIDE_HOLDFULL =
	{
		ENTER = ("rollD: 10", "pauseAI: 2");
		ROLL_1 = ("setStateTo: EXIT_SYSTEM");
		UPDATE = (exitAI);
	};

	EXIT_SYSTEM =
	{
		ENTER = (performHyperSpaceExit);
		UPDATE = (performHyperSpaceExit, "pauseAI: 1");
		"WITCHSPACE OKAY" = (wormholeEscorts, wormholeGroup);
		"WITCHSPACE BLOCKED" =
		(
			setTargetToFoundTarget, setDestinationWithinTarget, "setDesiredRangeTo: 10000.0", performFlyToRangeFromDestination
		);
		"WITCHSPACE UNAVAILABLE" = (exitAI);
		NORMAL_RESPONSE_TO_MISSILE =
		(
			fightOrFleeMissile, setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
		HAVE_CLOAKED_V_MISSILE = (performIdle);
		ATTACKED =
		(
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist" 
		);
	};

	LURK =
	{
	 	ENTER = ("setSpeedTo: 0.0", performIdle); 
		UPDATE =
		(
			"rollD: 10",
			"sendScriptMessage: scanForTargets",
			"pauseAI: 5.0"
		);
		ROLL_1 = ("setStateTo: HEAD_FOR_PLANET");
		ACCEPT_DISTRESS_CALL =
		(
			setTargetToFoundTarget,
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-attackAI.plist"
		);
		OFFENCE_COMMITTED = 
		(
			setTargetToFoundTarget,
			"sendScriptMessage: considerAttackingOnOffence"
		);
		SUITABLE_TARGET_FOUND = 
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-interceptAI.plist"
		);
		NO_SUITABLE_TARGET_FOUND =
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED",
			"setAITo: ferdelance3-checkForLootAI.plist"
		);
		NORMAL_RESPONSE_TO_MISSILE =
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED,SUITABLE_TARGET_FOUND",
			fightOrFleeMissile, setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist"
		);
		HAVE_CLOAKED_V_MISSILE = (performIdle);
		ATTACKED =
		(
			"dropMessages: COURSE_OK,WAYPOINT_SET,DESIRED_RANGE_ACHIEVED,SUITABLE_TARGET_FOUND", 
			setTargetToPrimaryAggressor,
			"setAITo: ferdelance3-attackAI.plist" 
		);	
	};


}

Code: Select all

{
	// ferdelance3-attackAI - used by pirates and bounty hunters
	
	GLOBAL = 
	{
		ENTER = 
		(
			"setStateTo: ATTACK_SHIP"
		);
		RESTARTED =
		(
			"setStateTo: ATTACK_SHIP"
		);
	};

	ATTACK_SHIP =
	{
        		ENTER =
        		(
			"sendScriptMessage: cloakOff",
			"sendScriptMessage: startTimerForConsideringCloakedAttacks",
			groupAttackTarget,
        			performAttack
        		);
		ATTACKED_BY_CLOAKED = ("setStateTo:  SPECIAL_LURK"); 
		DO_CLOAKED_ATTACK = ("setAITo: ferdelance3-cloakedAttackAI.plist");
		ENERGY_LOW = ("setStateTo: FLEE");
		FLEE_FROM_MINE = ("setStateTo: FLEE_FROM_MINE", "pauseAI: 0.5");
		FRUSTRATED = (performAttack);
		HAVE_CLOAKED_V_MISSILE = (performIdle);
		HAVE_CLOAKED_V_MISSILE_STAGE2 = 
		(
			setTargetToPrimaryAggressor,
			performAttack,
			groupAttackTarget
		);
		NORMAL_RESPONSE_TO_MISSILE = 
		(
			fightOrFleeMissile,
			setTargetToPrimaryAggressor,
			performAttack,
			groupAttackTarget
		);
		TARGET_CLOAKED = ("setStateTo: SPECIAL_LURK");
		TARGET_LOST = ("exitAIWithMessage: TARGET_LOST");
		TARGET_DESTROYED = ("exitAIWithMessage: TARGET_LOST");
		EXIT = ("sendScriptMessage: stopTimerForConsideringCloakedAttacks");
   	};

	SPECIAL_LURK = 
	{
		ENTER =
		(
			"sendScriptMessage: stopTimerForConsideringCloakedAttacks",
			"sendScriptMessage: cloakOn",
			performFlee,
			"pauseAI: 1"
		);
		UPDATE =
		(
			"pauseAI: 3",
			"rollD: 10"
		);
		ROLL_1 = 
		(
			"setSpeedTo: 0.0",
			performIdle,
			exitAI
		);
		ROLL_2 = 
		(
			"setStateTo: FLEE"
		);
		ROLL_3 = 
		(
			"setStateTo: FLEE"
		);
		TARGET_DECLOAKED = ("setStateTo: ATTACK_SHIP"); // script sets target
		FLEE_FROM_MINE = ("setStateTo: FLEE_FROM_MINE", "pauseAI: 0.5");
		ENERGY_LOW = ("setStateTo: FLEE");
		HAVE_CLOAKED_V_MISSILE = ();
		HAVE_CLOAKED_V_MISSILE_STAGE2 =
		(
			setTargetToPrimaryAggressor,
			"setStateTo: ATTACK_SHIP"
		);
		NORMAL_RESPONSE_TO_MISSILE =
		(
			fightOrFleeMissile,
			setTargetToPrimaryAggressor,
			"setStateTo: ATTACK_SHIP"
		);
		ATTACKED =
		(
			setTargetToPrimaryAggressor,
			"setStateTo: ATTACK_SHIP"
		);
		TARGET_DESTROYED = ("exitAIWithMessage: TARGET_LOST");
	};

	FLEE =
	{
	 	ENTER = ("sendScriptMessage: IfLowEnergyConsiderBeginningWitchspace", "setDesiredRangeTo: 25600", performFlee);
		UPDATE = (); // I think that 'performFlee' does checkEnergy automatically 
		
		 ATTACKED = (setTargetToPrimaryAggressor, "rollD: 10");
			ROLL_1 = (fightOrFleeHostiles);
			ROLL_2 = ("sendScriptMessage: ifLowEnergyConsiderBeginningWitchspace");
			FIGHTING = (setTargetToPrimaryAggressor, "setStateTo: ATTACK_SHIP");
		DESIRED_RANGE_ACHIEVED = ("setStateTo: RECOVER"); 
		HAVE_CLOAKED_V_MISSILE = (performIdle, "rollD: 10");
	 	ENERGY_FULL = ("setStateTo: LURK"); 
	 	NORMAL_RESPONSE_TO_MISSILE = (fightOrFleeMissile, "rollD: 10");
	 	REACHED_SAFETY = ("setStateTo: RECOVER"); 
		TARGET_LOST = ("setStateTo: RECOVER"); 
		EXIT_SYSTEM = ("setStateTo: EXIT_SYSTEM");
		FLEE_FROM_MINE = ("setStateTo: FLEE_FROM_MINE", "pauseAI: 0.5");
		HAVE_CLOAKED_V_MISSILE = (performIdle);
 	};

	FLEE_FROM_MINE =
	{
	        	ENTER = (performFlee, "pauseAI: 2.5");
		UPDATE = ("setStateTo: FLEE");
    	}; 

	RECOVER =
	{
		ENTER = ("sendScriptMessage: cloakOff", "setSpeedTo: 0.0", performIdle);
		UPDATE = (checkEnergy, "pauseAI: 5.0");

	 	ATTACKED = (fightOrFleeHostiles);
			FIGHTING = (setTargetToPrimaryAggressor, "setStateTo: ATTACK_SHIP");
			FLEEING = ("setStateTo: FLEE");

		ENERGY_FULL = (exitAI); 
		ENERGY_HIGH = (exitAI); 
		FLEE_FROM_MINE = ("setStateTo: FLEE_FROM_MINE", "pauseAI: 0.5");
		HAVE_CLOAKED_V_MISSILE = (performIdle, setTargetToPrimaryAggressor, fightOrFleeHostiles);
		NORMAL_RESPONSE_TO_MISSILE = (fightOrFleeMissile, setTargetToPrimaryAggressor, fightOrFleeHostiles);
 	}; 

	// Next state called only by script
	EXIT_SYSTEM =
	{
		ENTER = (performHyperSpaceExit);
		"WITCHSPACE OKAY" = (wormholeEscorts, wormholeGroup);
		"WITCHSPACE BLOCKED" = ("setStateTo: FLEE");
		"WITCHSPACE UNAVAILABLE" = ("setStateTo: FLEE");
	};
}
I should point out that the 'FLEE_FROM_MINE' message, and the various missile messages, are generated by an associated script - as are various other messages in the AIs.

Re: Baffled about problem with attack code

Posted: Mon Jul 11, 2011 8:21 pm
by CommonSenseOTB
You know I looked up the ferdelance 3g AI and script and it looked to me like when the attack routine was entered it immediately called performAttack and then the script called an AI command to also performAttack when attacked(just once, not repeatedly) but you've changed all this and you say that it wasn't doing that so I have to go by what you are showing as your current AI.

I'm going to go completely off-center on this one and say that there is nothing really wrong with your AI. What you are descibing is classic behaviour that I have seen with fast ships with fuel injection on. This quick up/down slight weaving of the nose as they fly to you really fast making a pass on injectors. I would almost swear I've seen the regular ferdelance do this. Perhaps your ship is fast enough to start exhibiting this behaviour even without injection on.

The specific pitch/roll/speed/fuelinjectorson combination produces different results for the way in which ships attack depending on the exact combination. Similar(in stats)ships seem to attack in a similar way when they are on injectors(or I would guess also at high speeds). The ferdelances' 1pitch/3.6roll might be predisposed to this behaviour. Why don't you try some test combat against a regular ferdelance with injectors and see what happens? standard AI as well.

Just a thought...

Re: Baffled about problem with attack code

Posted: Mon Jul 11, 2011 10:12 pm
by UK_Eliter
CommonSenseOTB - you are right! Good god! No wonder I couldn't fix this. Would a moderator move this, then, to the bug reports forum?

I am going to have to try to create a hack that fixes this for my ships. I think, indeed, that I have one already - for there's some special stuff in my AI for cloaked 3Gs; and the cloaked 3Gs attack well. So I'll modify that stuff and port it to my uncloaked models.

Thanks a lot!