Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Player reputations and AI

An area for discussing new ideas and additions to Oolite.

Moderators: winston, another_commander

Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Post by Switeck »

I'm at a loss on how to have an AI.plist script check for the player's number of kills...and immediately avoid/flee if you're Dangerous/Deadly/Elite.
Closest I can come up with would be an ODDS check...flee if "ODDS_BAD".
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

The best way to do it is to use a mixture of AI & js. The ship needs to have a custom js script, with a function that generates AI messages the AI is configured to respond to. On the AI side you need something like:

Code: Select all

"TARGET_FOUND" = ( setTargetToFoundTarget, "sendScriptMessage: checkTargetRank");
"TARGET_NOTPLAYER" = (//whatever);
"TARGET_NOOB" = (//oh yeah!);
"TARGET_AVERAGEISH" = (//doable);
"TARGET_RISKY" = (//am I feeling lucky?);
"TARGET_DANGEROUS" = (//run like the wind!);

and on the js side something like

Code: Select all

this.checkTargetRank = function (){
    var messageAI = 'TARGET_NOTPLAYER';
    var T = this.ship.target;
    if (T && T.isPlayer) {
        if (T.score < 25) messageAI = 'TARGET_NOOB';
        else if (T.score < 100) messageAI = 'TARGET_AVERAGEISH';
        else if (T.score < 250) messageAI = 'TARGET_RISKY';
        else messageAI = 'TARGET_DANGEROUS';
    }
    reactToAIMessage(messageAI);
}
Of course you need to replace my (//comments) on the AI side with actual commands, otherwise Oolite will complain! :)

Note that you can make up the message names! As it's right and proper an AI will only react to the messages it knows about, and they could be named anything you like.


Using this kind of method you could create all sort of behaviours, like pirates that attack you only if you're carring at least 2 tons of computers, or a ragtag band of rusties only attacking other ships if they're carring food supplies, etc...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

Like Kaks said. Not doable via AI alone, but very easy with a ship script. The catch is of course how to attach this script to all pirates.

You can do it in the shipdata of all ships which can have the role "pirate". However, this is impractical, as you would need a shipdata-overrides.plist containing each possible ship, and you would have to release an amended version of your OXP each time somebody releases a new pirate ship. Also you could accidentally override other ship scripts.

So you're left with the second approach, which is to attach your script functions to the existing ship scripts of pirates "on the fly". It's a workaround, and it won't work in all cases, but it is doable, and it's the best I can come up with spontaneously.

There is an explanation by Ahruman either in the scripting requests thread or in the progress thread on how to attach scripts on the fly. Basically you need a world script running on every exitingWitchspace event, which identifies all ships in system with primary role "pirate", and copies the piece of script laid out by Kaks into their ship scripts. The main caveat is that only the pirate ships already in existence when the player enters the system would get the script. Entering traders turning pirates later would not get it.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Well, what I thought was that you could have your very own 'clever pirates', working independently from the usual ones.

If you want to override all pirates everywhere, you could do that by using the shipSpawned world event. It should get fired every time a new ship appears in the ooniverse.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Disembodied
Jedi Spam Assassin
Jedi Spam Assassin
Posts: 6884
Joined: Thu Jul 12, 2007 10:54 pm
Location: Carter's Snort

Post by Disembodied »

I think a sprinkling of "smart pirates" would be better than simply altering the behaviour of all pirates everywhere ... there's no way the player can see, for example, how dangerous an NPC might be. Maybe some pirates might be more clued-up than others, but there should still be a lot of uninformed and/or reckless bandits out there. Apart from anything else, it would make life very frustrating for players if all our potential targets just legged it the minute they came onto the scanners!

Would this also be a method of reducing the chances of pirates attacking Offender/Fugitive players?
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Post by Commander McLane »

@ Kaks: I didn't have shipSpawned as a world event on my radar, I have only ever used it as a ship event. But of course it's perfect for this. :D

@ Disembodied: The OXP Switeck has in the making is a complete overhaul of the generic ship behaviours, so the player actually would expect altered behaviours everywhere.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Post by Kaks »

Commander McLane wrote:
@ Kaks: I didn't have shipSpawned as a world event on my radar.
If I may misquote Commander McLane: look up the scripting information on the wiki, it's a really good source of information! :twisted:

There was quite a huge improvement in scriptability between 1.73 & 1.74, I doubt any of us managed to catch up with all that stuff.

On a slightly sadder note, I was looking up some new-ish features a little while ago, only to find out they had been added by Kaks. :roll:
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Post by Switeck »

Commander McLane wrote:
@ Disembodied: The OXP Switeck has in the making is a complete overhaul of the generic ship behaviours, so the player actually would expect altered behaviours everywhere.
I'm still fishing for ideas, but my mod almost certainly won't include pirates fleeing/ignoring the player based on the players' stats as default behavior. Most pirates won't know about you. Of the few that do, few will care. Of those that care, most won't care in a NICE way! :twisted:
Post Reply