[WIP] Captain AI overhaul. Updated 09.12.2014

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 21. Nov 14, 15:51

@UniTrader
That looks nice, thanks for the tip :) Have to look in to that, some speed hacks would be great for testing.

Actually got in sector boosting working relatively reliably yesterday :) Only challenge now is to force the get_safe_pos to give a consistent output. Trying to force it to return a point in space from the target toward ship which is ca 13KM away from target with:

Code: Select all

<get_safe_pos object="$target" zone="this.zone" directionobject="this.ship" angle="35deg" min="12500" max="13500" radius="this.ship.size" result="$pos" allowyaxis="false"/>
Works relatively OK but the output is sometimes a bit random and might give me a point on the opposite side of target, but usually get a OK position after 1-5 tries so have a do_while recheck hack for now. The range from target is always consistent. Any tip on what I'm doing wrong here?
The direction statement is not often used in the vanilla code so not much to go on, only in the undock code IIRC.

Here is the current codesnippet if someone want to play with it over the weekend. Have cleaned up some of my debugging stuff to help readability.
The forceposition="false" in boost move is important, without it the game will throw the ships around wildly on arrival. Have the minimum range for IS boost set to 20KM here.

Code: Select all

<do_if value="this.ship.distanceto.{$target} gt 20000 and this.ship.isplayerowned" >'
	<!--Stop and hold position/rotate to target-->
	<create_orientation name="$targetvector" refobject="$target" orientation="look_at">
		<position object="this.ship" space="this.ship.zone" />
	</create_orientation>
	<move_to destination="this.zone" object="this.ship" >
		<position object="this.ship" z="5m" />
		<rotation value="$targetvector" />
		<interrupt_after_time time="60s" />
		<interrupt>
			<conditions>
				<check_any>
					<event_object_destroyed object="$target"/>
					<event_boost_started object="$target" />
				</check_any>
			</conditions>
		</interrupt>
	</move_to>

	<!--Find safe pos ca 13KM from target in direction of this ship-->
	<set_avoid_collisions object="this.ship" enabled="false" />
	<get_safe_pos object="$target" zone="this.zone" directionobject="this.ship" angle="35deg" min="12500" max="13500" radius="this.ship.size" result="$pos" allowyaxis="false"/>
	<set_value name="$counter" exact="1"/>

	<!--HACK!: position sanity validation/force rechecks, max 30 retries to avoid infinite loop lockup...-->
	<do_while value="(this.ship.distanceto.{$target} - this.ship.distanceto.{$pos}) le 7000">
		<get_safe_pos object="$target" zone="this.zone" directionobject="this.ship" angle="35deg" min="12500" max="13500" radius="this.ship.size" result="$pos" allowyaxis="false"/>
		<set_value name="$counter" exact="$counter + 1"/>
		<do_if value="$counter ge 30">
			<break />
		</do_if>
	</do_while>
        <set_value name="$posY" exact="$target.position.y"/>
	<do_if value="$isstation">
		<set_value name="$posY" exact="$pos.y"/>
	</do_if>
	<do_if value="player.ship == this.ship">
		<speak actor="this" line="1029" comment="Engaging boosters." />
	</do_if>
	<start_boost object="this.ship" />
	<move_to destination="this.zone" object="this.ship" forceposition="false" finishonapproach="true" usehighways="false">
		<position x="$pos.x" y="$posY" z="$pos.z" />
		<rotation value="$targetvector" />
		<interrupt_after_time time="$updatetime" />
		<interrupt>
			<conditions>
				<check_any>
					<event_object_destroyed object="$target"/>
					<event_boost_started object="$target" />
					<check_all>
						<event_boost_charging_started object="$target" />
						<check_value value="this.ship.distanceto.{$target} le 15km" />
					</check_all>
				</check_any>
			</conditions>
		</interrupt>
	</move_to>
	<stop_boost object="this.ship" />
	<set_avoid_collisions object="this.ship" enabled="true" />
</do_if>

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Fri, 21. Nov 14, 15:53

I can't wait for v3.00 to be released so I can try this baby out :)

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 21. Nov 14, 17:17

@sparky
Been a really fun little project - and any "what if they do this"/ "when X they should Y" etc. ideas will be most appreciated :)

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sat, 22. Nov 14, 22:31

cicero111 wrote:Actually got in sector boosting working relatively reliably yesterday :) Only challenge now is to force the get_safe_pos to give a consistent output. Trying to force it to return a point in space from the target toward ship which is ca 13KM away from target with:

Code: Select all

<get_safe_pos object="$target" zone="this.zone" directionobject="this.ship" angle="35deg" min="12500" max="13500" radius="this.ship.size" result="$pos" allowyaxis="false"/>
Works relatively OK but the output is sometimes a bit random and might give me a point on the opposite side of target, but usually get a OK position after 1-5 tries so have a do_while recheck hack for now. The range from target is always consistent. Any tip on what I'm doing wrong here?
The direction statement is not often used in the vanilla code so not much to go on, only in the undock code IIRC.[/code]
maybe you should add a » ignored="this.ship" « attribute here to avoid getting a diffrent position when your Ship is already nearby? i am not really sure if this is in any way related you your problem, but i jast saw this when looking through the move.autopilot and thought it might be useful for you ;)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

User avatar
Sandalpocalypse
Posts: 4447
Joined: Tue, 2. Dec 03, 22:28
x4

Post by Sandalpocalypse » Sun, 23. Nov 14, 14:44

My balor definitely wasn't holding position, nor did ships move away from an exploding ship. Is there any indicator ingame to verify that the mod is working? I've verified it's in the right folder. Also, running 3.00 beta4.
Irrational factors are clearly at work.

UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader » Sun, 23. Nov 14, 14:49

i would use a
<show_help custom="'\033BBLUE - » %1 « - WINS\033X'.[$fleetnames.{$bluefleetid}]" position="0"/>
or a
<show_notification />
to display live status updates for testing purposes (show_help for simple stuff like what part of code is now used and show_notification for more complex things like displaying Positions or multiple Values)
if not stated otherwise everything i post is licensed under WTFPL

Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter ;)

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help ;)

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sun, 23. Nov 14, 18:59

@UniTrader
Yap, have tried ignored="this.ship" too, did not see any difference - currently bruteforcing the thing to see if anything sticks/ makes a difference :P Seems like direction="quadrant.right" etc. combined with directionobject works somewhat consistently - might just use that one instead, don't need to be that accurate here really.
Also have the wingmen IZ boosting to catch up now :) Lots of weirdness to work around when stations nearby though - much testing/hacking/headscratching still remaining with this one :)

@Sandalpocalypse
The current version is somewhat "noisy" in the debug log, so if you enable debug logging in the game launch options with

Code: Select all

-debug all -logfile debug.log
..you should quickly see if the mod is running. The logfile will be in the same dir as the savegame subdir.

You should see some output from move.attack.object.capital script in there, for example:

Code: Select all

[=ERROR=] aicontext<move.attack.object.capital,0x4a59f>: 338057.831RYK Gangrene Chaser is panicking. Distance to target: 2232, moralecheck: 33, hull: 44.9022, shield: 0

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Wed, 26. Nov 14, 22:46

New version is up, beta 2 :)
Changes:
Lots of optimizations, among other things don't recheck paths constantly when not in firing range, but only use "high attention" when close enough. I now use a lot of interrupts to "wake up" the captain to switch modes. Haven't seen any "lag" in big battles after the changes.
Also did a lot of code refactoring which should make it easy both to extend what it does, and to adapt if ego does something radical with their new AI code.

Improved explosion avoidance - I now use a (fighter) move away flight mode instead of just trusting what the find_safe_pos gives me - and risk getting a point on the opposite side of the enemy. Worked surprisingly well.

Some improvement to the shiptype close combat logic and tweaking with the ranges.

In sector boosting. Have boost to target, boost to my position, and "boost to catch up" for capship wingmen.
Still a validation/recheck loop in there to ensure I don't get a boost endpoint behind the enemy, but it seems reliable - haven't reached max retries yet (30).
Only tested without betterships for now, guess i'll have to add some stuff to make that combination not too weird.

Other:
Wasted a lot of time on some really weird bugs, Xenons bypassed all checks and boosted happily rounds around my little fleet even when i told them explicitly not to - in a lot of places. "The xenons have infected my machine" was one theory in my tired head :P Found out the AJD mod did a lot of strange stuff to the AI code - yes i run very modded, so some weirdness are to be expected :)


Have not added the new ship types from the expansion yet, so they will run vanilla when in close combat - it's on the todo list. Also have to do some more stuff to the escort script, but I'll do that when the new AI code is released.

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Wed, 26. Nov 14, 23:55

You beauty!
...May not be able to test until 3.00 is out due to beta-testing but I much appreciate your efforts.
cicero111 wrote: Xenons bypassed all checks and boosted happily rounds around my little fleet even when i told them explicitly not to - in a lot of places.
This happens with Xenon Ks occasionally in vanilla too. Sometime juddering away from the Skunk as well. If you have any code suggestions for Egosoft, I recon that would be handy.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Thu, 27. Nov 14, 17:20

Something very odd just happened.

I have a Taranis and two Stromvoks assigned in a squad to a Sucellus, reasoning that the Sucellus will start hammering any particularly interesting large targets from range, and that the other three ships will defend when said large target moves to engage (and incidentally shred any fighter escorts that might come close.)

I had the squad engage a marauding Titurel. Sucellus boosted towards the target (which I thought was fun). It then stopped around 12 km away, and just waited; which I found odd until I realized that it was waiting for the rest of the squad. (So I guess that that's cool, except I wonder how they would have acted if there were more hostile ships in the vicinity.)

Ok, squad assembled, they moved closer to the Titurel, and, I thought, here it comes, waiting for the IHC to fire, and the Sucellus fires Plasma.

Eh?! Plasma?! I would have expected it to fire the V rockets at least. The Sucellus has two Plasma Cannons, so it's going to take a while. Should outlast the Titurel though.

But is it supposed to do this?

Playing with v3.0 Beta 5 of X Rebirth, by the way, if there might be any conflicts with that.

PS. I'd capture the Titurel, but they seem to be everywhere in this Beta. Already got 9.

_____

Thought I'd add to this post rather than make another one. The problem seems to be with the Better Turrets mod. I deactivated it, and the fight just got a lot livelier: Sucellus closed to within 8 kilometers, and repeated firing of the IHC.

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Thu, 27. Nov 14, 21:09

@Sparky
Yeah, there seems to be "something" in there that makes the K's a bit "clingy" and insist on going close/triggering the break off part constantly of the script. Have been trying to add some "air" between the ships when they combat but those are a bit hard to control sometimes.
Adding the skunk as a priority target (same as L/XL) for pursuit is a good idea really, is their enemy's flagship after all. I'll do some testing :)

@w.evans
Plan is to do some more hacking in the escort scripts++ to make wingmen react a lot faster when leader is boosting, both IZ and zone changes + when leader is jumping. Whole fleet boosting or jumping in about the same time would be kinda sweet :)

The Sucellus IHC fires as usual in my game when oriented to target and within 9KM - haven't tested without my BetterTurrets mod yet, but if that one have some issues now I'll look in to it.
Do you run some other battle related mods? I usually cram as many mods that i can into my game, but might have missed one :P
Saw a change to the K's in latest patch though - they now shoot "fireballs" instead of that purple stuff, might be something related. Haven't seen any changes in egos AI code yet though.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Fri, 28. Nov 14, 09:04

I don't THINK that I have any other combat related mods. My setup is:

CaptainAIOverhaul
Mission Computer
Capital Ship Bridge
Mk5
More Crew
Enhanced Money Transfer
Show Me Your Faction, Please!
Show Skills
Speedy Delivery
Super Booster
Super Scanner
No random Sector music
Yet Another Trader

And the following are installed, but inactive, in case that somehow has a bearing on things:

Better Turrets
ButterMissions
ButterRewards
no Jump Fuel for Player Ships
Player Drone Recall

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 28. Nov 14, 13:59

@w.evans
Thanks for reporting back :) None of those mods influence the DO script afaik, and i use most of them myself. I use the Sucellus + 2 Taranis wingmen as primary test "fleet" for this mod (the other one is Fulmekron + misc wingmen thrown together) .
I'll enable some debug output in my BT mod again and see if some weirdness comes up that needs fixing :)

Edit: And yeah, one more question - was the DO in offensive or defensive mode? Just remembered I added a feature to not use the "big guns" at all when in defensive mode in the last version of that mod. Was buried deep in my wall O text at the BT mod page, moved it up a bit since that one is somewhat important :)

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Fri, 28. Nov 14, 19:47

I don't have the save anymore, unfortunately. I do remember that under Ship -> Details, the Defence Officer status read "Defending" (only time I've ever seen this change is when it reads "None" or "Nothing" or something like that) while under Ship -> Details -> Defence Officer -> Details, it read "Attacking."

edit: Oh, and the Sucellus was explicitly commanded to attack the Titurel. [Hail -> New Command -> Attack... -> Attack the Object]

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Fri, 28. Nov 14, 20:27

Thanks :) And no worries about the save - that was very helpful. Iirc "attacking" shows on both offensive/defensive when they are shooting at the target, but when in offensive they will fall back to "attacking enemies" while idling.
The DO gets the target via attack object command, and vanilla DO's will fire what they have at it no matter their def/off state, but i added some code in there so when DO is in defensive they'll avoid damaging the hull and just target weapons/engines/jumpdrive with their turrets as capping support.
Gives me an excellent excuse to revisit and do some more in that mod :) One thing I'll add in the todo list is "make the thing user friendly", that wall of text at the mod page is not that :P Maybe add some info popups at first launch or some other GUI stuff.

HailedGorion
Posts: 38
Joined: Sun, 2. Jan 11, 18:35
x3tc

Post by HailedGorion » Fri, 28. Nov 14, 21:42

Does this mod has anything to do with the "Captain and Defense Officer AI Overhaul" mod existent in the Steam workshop?

If not, even still in beta, why not adding there? This should make things much more convenient and would increase its visibility to other players.

Im saying that cuz I believe this mod has great potential and would help new players to get a much greater experience from the game.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Fri, 28. Nov 14, 23:09

@cicero111

Yup, read about the DO mode switching in the write-up. Partly why I wanted to try it out: that, the added relevance of DO skill, and the drone functionality. Is there a way to manually switch the DO's mode from offensive to defensive and vice versa though? Assumed that if the ship was following and there are hostiles, that it would be in defensive mode, and would switch to offensive if either commanded to attack everything, attack a particular target, or maybe (hopefully) the new patrol command.

edit: Just thought I'd add: I think that the wall of text is fine. It's consistent with the traditions exemplified by some of the great mods from X3! It IS a lot of information to take in though, so one has to read it, download and install, play, read it again; and do that a few times before it all sinks in. At least I have to. Then again, maybe I'm slow.

@HailedGordon

I actually prefer getting the mods here since we get them in loose files. Easier to see which files are modded to check for compatibility, and also allows one to take a peek in the altered scripts to see how things work under the hood, and maybe tweak sometimes. The steam workshop does make updates more convenient though.

The CDOAIO doesn't seem to have been updated since v2.5ish. I vaguely remember reading that clj (The author of CDOAIO) lost interest in the game and isn't actively updating the mod anymore. (Don't quote me on that though, because I just looked, and can't seem to find the relevant post. Maybe he/she's just busy.) Hoping that he (she?) 'll come back and pick it up again though now that the game's starting to actually be fun. Same for Mad_Joker and his UFO. Man, that mod kicked ass! And Lucike! (Although Lucike could be over at the German board modding under a different alias for all we know. Ah, the wonders of the internet.)
Last edited by w.evans on Fri, 28. Nov 14, 23:41, edited 1 time in total.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Fri, 28. Nov 14, 23:22

Hm, there's a thought.

Hey cicero111, you wouldn't happen to be interested in picking up Mad_Joker's UFO now would you? In his last post over at the Steam forums (as MrWolfZ), he mentioned that "the sources of UFO are completely publicly available on my GitHub repository (link on Egosoft forums), so if the author of CDOAIO wants to, they can copy most of the things and incorporate them in their mod."

I mean, you seem to have a pretty good idea of how the combat and movement scripts work. Might be fun.

Tracked down the files here if you want to take a look:

https://github.com/MrWolfZ/XRebirth

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sat, 29. Nov 14, 16:23

@HailedGorion
Yeah, this one combined with BetterTurrets have more or less become a remake of CDOAIO, the "overhaul" in the title is a nod in direction of clj's mod :) Started on both since that one was not updated + was inspired with what iforgotmysocks managed to do with the AI code in his skunkturret mod.
The BT mod will be released on Steam WS soon'ish since no reports of broken saves or computers catching fire in latest beta - I'm a bit on the fence till ego releases their complete 3.0 AI package though to be sure I'm not introducing any problems.
I'll release this one on steam as well, but there are a lot of changes and tweaks to be done in the code still.

@w.evans
Saw you started a post in the BT mod thred - I'll answer the relevant stuff there :)
And yes, have been looking at MadJoker's UFO scripts among others to find the "tricks of the trade", so am somewhat familiar with the code.
Doing some 3.0 compatibility updates to that one is a good idea really - was a great mod, I'll think about it.

cicero111
Posts: 108
Joined: Sat, 13. Aug 11, 14:30
x4

Post by cicero111 » Sun, 7. Dec 14, 23:13

A quick update.
Ego made some (minor) changes to the captain AI code in the latest 3.0 betas which broke xpath patching of this mod.
Goal is to release a 3.0 compatible version in a couple of days (have to finish testing).

Post Reply

Return to “X Rebirth - Scripts and Modding”