Page 1 of 1

AI to launch multiple defense ships

Posted: Mon Nov 20, 2006 9:04 pm
by Judebert
Background:
In https://bb.oolite.space/viewtopic.ph ... highlight= someone was a reminiscing about seeing Sidewinders pop out of Boas. I figured this would be a simple OXP and posted https://bb.oolite.space/viewtopic.ph ... highlight= to ask about replacing ships with variants at a specified frequencies.

I thought I'd be done in a day, maybe two tops. Boy, was I wrong.

What doesn't work
I tried "spawn: escort 3" and "ejectItem: escort 3" and various other variations with no luck. If I could get the position of the ship, I'd try to use one of the addShips variants. (Of course, then I'd have to figure out some way to specify who's the mother ship, but since I can't get the ship position, that's moot. For now.)

In the debug terminal, each of these report "Anaconda 329 does not respond to spawn:" or "...to ejectItem:". I guess the AI just isn't equipped for that.

What works, more or less
Here's what actually got a ship to launch:
1) change the shipdata.plist
a) give the carrier ship has a custom AI (microcarrierAI.plist in my case) that decides when to launch the ships.
b) add the "isCarrier" attribute to the ship.
c) add the "max_defense_ships" attribute to the ship.
d) add the "defense_ship_role" attribute to the ship.

I accomplished all that after a like-ship, so I didn't have to create new models or anything.

2) In the custom AI, use "launchDefenseShip" to launch a ship. This is case sensitive, and it's not in the Wiki, so far as I can tell.

I added this to occur whenever the ATTACKED message was sent to the ship.

Here's the problem: only one ship was ever launched. I tried setting max_defense_ships to 4 and 40, but only one ship gets launched. In the debug terminal, my debug message "eject sidewinder" shows up multiple times, but still only one sidewinder ever appears.

I was hoping to get three for the Anaconda.

What I've tried:
launchDefenseShips (plural; "does not respond")
launchDefenseShip: 4 ("does not respond")
launchDefenseShip; launchDefenseShip; launchDefenseShip (just one launch, no matter how many times I call it)

The questions:
Is there something in the core code that restricts the number of defense ships that can be launched? Perhaps based on the mass of the launcher? Or is it just that I haven't added a docking slit to the Anaconda? I was hoping to avoid modeling, but if that's what it takes...

Posted: Mon Nov 20, 2006 9:44 pm
by LittleBear
Think you will need to add a docking port to make it work properly. You should be able to avoid too much modeling by taking Giles's normal docking slit and resetting the size, then save a model as annacondadock.dat and add as a subentery.

lauchdefenceship is valid as it is used in the native stationAI, but to get the ship launcing lots of fighters, you may need to add a custom bit. Under all the incoming missile and attacked have a settargettoprimaryagressor, setstate to : SCRAMBLE. If you have only added the command when the ship is attacked in one AI state, then it will only launch a ship if it happens to be fired apon when in that state.

Define SCRAMBLE somthing like-

ENTER = (launchdefenceship, pauseAI 1.0, launchdefenceship)
UPDATE = (launchdefenceship)
ATTACKED = (launchdefenceship)
INCOMING MISSILE = (launchdefenceship, fightorfleemissile)

launchDefenseShip; launchDefenseShip; launchDefenseShip woudn't work as the commands need to be separated by a , but you might need the pause in the AI inbetween to stop them crashing into each other.

Spawn won't work in AI, but as the ship's final attack you could in shipdata have under deathactions spawn: specialsidewinder 3, so that the appear from the wreck of the ship when it is destroyed.

That should get it spewing defence ships!

One problem is that lauchdefence ship is normally used by things with lots of energy (like stations and carriers), there is a delay in the ship being launched built into Oolite. With a station or a Leviathen this dosen't matter as nobody will be able to blow up a Leviathen before it gets its birds in the air, but an Annaconda could be blown away before whilst the guys are still running for their sidewinders!

Posted: Tue Nov 21, 2006 5:44 am
by Judebert
Maybe it's just that I run on a Linux system, but I get "Anaconda 304 does not respond to launchdefenseship" (and no sidewinders) if I don't use the same capitalization I found in the root stationAI.plist.
littlebear wrote:
launchDefenseShip; launchDefenseShip; launchDefenseShip woudn't work as the commands need to be separated by a , but you might need the pause in the AI inbetween to stop them crashing into each other.
Blush. I'm using commas, of course. This is what happens when I post from work.

So I tried a few more things. Putting the launchDefenseShip in the UPDATE, the debug message gets called every 140ms or so. A new ship was launched every 10 seconds or so. Hmm.

I added a pauseAI after each launch. If I pound it with my military laser, I can kill it before it gets a single ship off. If I give it some time, it will launch a load of ships. Same when I remove the pauseAI.

It looks like 10 seconds is the minimum time to launch a ship. Perhaps with a docking slit it takes less time? As it is, it's a great way to get kills: just wait till it starts spewing, then pick 'em off as they come out!

Rather than launch ships indiscriminately (although that has been fun), I think I'm going to set the AI to launch a wing of escorts when it's first attacked, and another wing if it has to flee. The size and type of a "wing" will be determined by the ship type.

Perhaps a launching slit would let me launch more than one at a time, too.

Maybe it would be more realistic if I kept launching until "ODDS_GOOD", then launched as many as possible when I flee. If I can figure out how to get that determination. Probably have to put something in UPDATE.

Finally, an observation: I've been seeing ships "flicker". They appear on the radar, then disappear almost immediately. This has happened a few times with my testing script.plist, too. It'll tell me "adding microcarrier" twice, but I only actually get one. And a flicker.

Posted: Tue Nov 21, 2006 5:56 am
by LittleBear
Looks good!

I think your AI is a good as it can be, the 10 second delay being somthing build into Oolite. If you open fire on a space station, it is still a while before the first viper launches. Realistic, I guess to simulate the defenders running to their ships! You could boost the energy of your special ships a bit to make it less likley that the mother is blown up before she gets her ships launched. Maybe giving it more than one docking port would also speed up the launching?

Unless you set the role to include "station (000.1)", nobody will be able to dock with the Annaconda, but it would look good to have the ships comming out of some special luanching bay.

Posted: Tue Nov 21, 2006 3:07 pm
by Judebert
I'm going to try multiple docking slits before I declare success. As it is, it's just too easy to pound the thing to death, then deal with the surviving escorts. Increasing its energy sounds like a possible remedy, though.

I like using the role "escort", since it's brought up Sidewinders, Mambas, and even a Chuckwalla that I wasn't expecting. But I'm worried that if I do use a docking slit, it'll be too small and damage the defenders on the way out. I'll do some experimentation later tonight.

If I have to customize the defense ships to get them to launch faster (like scaling them down to fit though the docking slit), I will. "The Sidewinder Defender is designed as a portable weapons platform with minimum cargo footprint. Since it is always carried by a support ship, it jettisons cargo space, fuel capacity, witchdrive, and everything but basic life support to provide the smallest possible platform with enhanced Sidewinder combat characteristics." Yeah, that sounds good.

I'm also considering a custom defenderAI.plist: defenders shouldn't mess around. They should immediately position themselves between the mothership and the attacker to absorb damage, then cut the attacker to ribbons. Defender pilots are fearless and fanatic: they never flee, and the only time they take evasive action is to lead a missile away. Then they come back for the kill.

Posted: Tue Nov 21, 2006 6:17 pm
by LittleBear
Tweaking ThargoidAI should do that! Always fights, never runs!

Posted: Tue Nov 21, 2006 11:57 pm
by TGHC
Judebert wrote:
Increasing its energy sounds like a possible remedy, though.
Right on Commander, it's combined shield strength and energy refresh rate needs to be sufficient to withstand a full miltary laser blast untill it's escort can begin to do what it's paid for!

"So I spot a lone Boa, no Galcop vipers about and I let loose with my front military laser, but just as it shields are at straining point and it starts to shed plasma, out drops a really angry gecko (wouldn't you be angry if you were disturbed with your trousers round your ankles and a toilet roll in one hand?), that comes at you like a demented wasp. I'm waiting for my miltary laser to cool down so I have to take violent evasive action and sort the Gecko out who really is a pain. Ok so now he's out of the way where the hell is that Boa, damn, he's hightailed it towards the Planet 23km away on full throttle and I need to get to him fast, right a quick injector burn, he's in my target, I've locked on, uh oh is that pirates or a trader with escorts on my scanner, finger hovers over the fire button, whoooo Galcops now, I need to stay clean, so do I sit tight and wait for the galcops to pass, there might be more coming through, or do I cut and run, mmm have to admit I could really slaughter some Riedquat ale right now"

Don't you just love Oolite!

Posted: Wed Nov 22, 2006 4:42 am
by Judebert
Okay, I'm looking through the code, and it looks like a 6-second delay is hardcoded. It's possible each subentity will have its own launch queue, but what do I really know? This language isn't C/C++, Modula, Ada, Fortran, Pascal, Java, PHP, or Perl. Heck, it isn't even APL. Close enough to C++ for me to get the gyst, but not enough for me to understand why a ship responds to launchDefenseShip when the method is only defined in StationEntity.m.

So I'd like to try multiple docking slits, but I need a quick tutorial on subentities. Do they get their own AI? How do I define them? How do I send commands/messages to them? Anybody care to elucidate? I'm too sleepy to search my OXPs.

Posted: Wed Nov 22, 2006 5:00 am
by Judebert
I lied; I'm not too sleepy. I found a station with a dock-flat subentity and copied it so that the Anaconda had two docking slits. Big bubbas, hanging on either side. Turned it into the biggest TIE fighter you ever saw.

No effect on defense ship launch speed, though. Unless there's some way to assign them an AI that launches a ship when I tell them to, I'll have to resort to bigger shields.

I even tried giving it escorts; I figured deployEscorts would launch them all at once. But no; it doesn't seem to work at all. Littlebear, I seem to remember you had a similar problem in the Assassins OXP (victim defined with escorts that don't always appear), but the thread never says how you fixed it. Do you remember.

NOW I'm too sleepy. Good night, all.

Posted: Wed Nov 22, 2006 1:28 pm
by LittleBear
Arrgh Escorts!

In the end I gave up using the Escort Command and got the same effect another way. There are so many problems with it, that I coudn't work out how to get round! In theory it works, all you need to do is in shipdata include:-

<escorts>
<interger>4</interger> {the number of escorts}

Then either:-

<escort-ship>
<string>myspecialship</string> {If you want the ship to be a special ship you desgined}

or

<escort-role>
<string>pirate</string> {If you want the ship to be escorted by a ship random ship picked of the list of ships with this role}.

You then add a setupescorts command in the AI, probabley under gobel is best. It works! When the mother is added she appears with her escorts and off they all go in formation. BUT these are the problems:-

Whatever AI you assaing an Escort Ship, Oolite will ignor and default to the native EscortAI. This causes too big problems:-

1) Under certain states in EscortAI, the AI will switch to route1patrolAI. This is a police partrol AI. Once switched the ship becomes a police patrol ship in terms of its behaviour. Now fine if your mother ship appears by the witchspace beacon, but if it turns up half way say, then by the time the player gets there 9 times out of ten Mum will be alone. This is because on the way to the planet the Escort ships will have spotted a ship with a criminal record. Even if the ship is a minor offender and does not attack, as the Escorts are using scanforoffenders, they say to say to themselves "That guy is a crim. Lets go kill him", whilst Mum with her traderAI holds her cause to the planet. By the time they've got their target, Mum is out of scanner range and they can't find her.

2) EscortAI is pretty tardy about protecting Mum, somtimes they do and somtimes they don't. Giles's native ships are usually pretty effective, as his roles have suff hard-wired in, but this doesn't seem to work well with OXP escorts.

The trick I used was to give mum and escorts the same basic "Head for planet and dock" AI (unless attacked) and the same speed. Then I used an addshipswithinradius pwm {Mums starting point} 1000, so the escorts and Mum start off together. As their Ai and speed are the same the stay together flying towards the planet.

I was wanting to uses escorts to keep a battle fleet of 30 Deamon Class Cruisers, 20 odd Scorpion Frigates and 50 light fighters together until they came across the enemey (the player, plus various different rebelships) so I included as updates 4 LOOK FOR TARGET states (scanforship with role rebel, found = attack nothing found = set state to look for targets2, where it scans for rebelfrigate and so on). This caused the ships to stay in formation until and fly together towards the planet until the encountered the enemy. (see fleetAI and MindersAI in Assassins).

I guess you could do somthing similar with a scanforhostiles command.

Roberto kept going with Escorts and I think he got it sorted out. Have a look at this thread:-

https://bb.oolite.space/viewtopic.php?t=2366

As he posted quite a bit of his AI code.

Posted: Wed Nov 22, 2006 3:46 pm
by Dr. Nil
Thanks for sharing your knowledge guys. It's very inspiring.

I have a launch related AI question. Does one of you know if it's possible to have an AI scan for ships with a given role and launch ships of a certain type if the number found is smaller than a given integer?

Also related to launches (but in the shipdata): Is it possible to define specific ships as a stations scavengers etc.? Is it possible to define other roles for the AI to launch besides defense ship, miner and scavenger? Would eg. launchHunter work or even launchMyship?

EDIT: I am aware of "checkForShips: <role>" but have no idea how to use it or the number it returns.

Posted: Wed Nov 22, 2006 4:18 pm
by LittleBear
You can only have lauchDefenceShip in AI.

BUT you can specify the ship to be lauched in the Shipdata. So if (eg) you wanted your commie factory to launch people's vipers as defenceships, then you'd include in the factory ship's shipdata, a specified defence_ship_role.

EG: The Special Branch Base:-

Code: Select all

<key>sbstat</key>
  <dict>
	<key>ai_type</key>
	<string>sbstationAI.plist</string>
	<key>beacon</key>
	<string>S-Special Branch</string>
	<key>defense_ship_role</key>
	<string>sbfighter</string>
	<key>cargo_type</key>
	<string>CARGO_NOT_CARGO</string>
	<key>energy_recharge_rate</key>
	<real>100</real>
	<key>equipment_price_factor</key>
	<real>2.0</real>
	<key>equivalent_tech_level</key>
	<integer>13</integer>
	<key>forward_weapon_type</key>
	<string>WEAPON_NONE</string>
	<key>frangible</key>
	<false/>
	<key>has_ecm</key>
	<true/>
	<key>has_escape_pod</key>
	<false/>
	<key>has_scoop</key>
	<false/>
	<key>likely_cargo</key>
	<integer>0</integer>
	<key>max_cargo</key>
	<integer>0</integer>
	<key>max_defense_ships</key>
	<integer>5</integer>
	<key>max_energy</key>
	<real>50000</real>
	<key>max_flight_pitch</key>
	<real>8</real>
	<key>max_flight_roll</key>
	<real>8</real>
	<key>max_flight_speed</key>
	<real>0.0</real>
	<key>missiles</key>
	<integer>0</integer>
	<key>model</key>
	<string>stationD2.dat</string>
	<key>name</key>
	<string>Special Branch Orbital Headquaters</string>
	<key>port_radius</key>
	<real>500</real>
	<key>roles</key>
	<string>sbstat rotating-station station(0.0001)</string>
	<key>rotating</key>
	<true/>	
	<key>subentities</key>
	<array>
	<string>ballturretD3 42.5 0.0 480.0 .866 0 .5 0</string>
	<string>ballturretD3 -50.0 0.0 500.0 1 0 0 0</string>
	<string>*FLASHER* 0 -16 252 30.0 1 0.5 12</string>
	<string>*FLASHER* 0 16 252 30.0 1 0.5 12</string>
	<string>*FLASHER* 16 0 252 30.0 1 0.0 12</string>
	<string>*FLASHER* -16 0 252 30.0 1 0.0 12</string>
	</array>
	<key>thrust</key>
	<real>100</real>
	<key>weapon_energy</key>
	<real>0.0</real>
	<key>weapon_offset_x</key>
	<real>0.0</real>
	<key>scanClass</key>
	<string>CLASS_STATION</string>
	<key>smooth</key>
	<true/>
	</dict>

This creates a dockable station where its defence fighters are ships with the role "sbfighter" (an OXP ship). It will also fire its turrets at you if you attack it, as the sub-entries arm it with two of Giles's (native) turrets!

If you wanted to, you could make the role a standard Oolite role like "police", "pirate" "hunter" etc. This would cause Oolite to pick the ship to be launched from the list of ships with this role (but in AI they will function as a defenceship). Eg: The Native Dodec Station has the defenceship "police". If you have no OXPs in, then lasering a station will cause you to be attacked by Vipers (the only ship in the native game with the role police). But if you (say) had Sleezens SWAT vipers installed, then as he gave his ship the role police, you could also be attacked by his SWAT vipers.

Posted: Wed Nov 22, 2006 7:09 pm
by Dr. Nil
Thanks again LB. :) The defence ship slot was already taken though.

I'm trying to get an Astromine Penal Colony to be inhabited by both guards (in Rays) and convicts (in tiny mining pods). I could script the appearance of such mines and set prisoners and guards up around the mine in the script instead. I just found it wasteful to set up an extra asteroid field and hoped that the mines could have been set up with roles to take the place of some of coves and hermits in commie systems.

Another possibility might of course be to give the mining pod a very high value for the miner role in those systems and find a way to have the astromine (a hermit with purple radar signature so far) launch a group of those to begin with.

Advise and ideas are welcome.

Again struggling with this simple stuff really makes me appreciate the efforts of everyone involved with this game and it's expansions.
Judebert wrote:
Okay, I'm looking through the code, and it looks like a 6-second delay is hardcoded.
Thank you for sharing this knowledge. Please do tell of other unpublished limitations (and possibilities) you come across. Some of us have no chance of discovering these things ourselves.