Progress

General discussion for players of Oolite.

Moderators: winston, another_commander

User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Progress

Post by JensAyton »

It seems to me that it could be beneficial for the extra hermit to be added after shipWillExitWitchspace, so that it doesn’t need to happen if OXPs have already added secondary (immobile) stations.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Progress

Post by cim »

Ahruman wrote:
It seems to me that it could be beneficial for the extra hermit to be added after shipWillExitWitchspace, so that it doesn’t need to happen if OXPs have already added secondary (immobile) stations.
Possibly, yes. Of course, not every OXP station is suitable for pirates to dock at, not that there's any way for the pirates to tell this at the moment until it starts shooting at them.
Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: Progress

Post by Switeck »

cim wrote:
Switeck wrote:
I would just remove unwanted ships (in this case a Rock Hermit and associated nearby asteroids) myself...but I get occasional crashes-to-desktop when .js scripts move (or remove) ships while my ship is cloaked.
But only while cloaked, and not when ships are (re)moved by non-JS means?
Switeck wrote:
There are also graphical glitches associated with moving and/or removing "unwanted" ships on arriving at a new system. Normally, this is unseen...but it can be particularly jarring in the case of Thargoids in interstellar space, as these are both semi-large and often immediately in front of the player's ship when this happens
shipWillExitWitchspace occurs before anything is actually drawn for the new system, though, so any changes made there shouldn't be visible to the player. And then the next several frames are the break pattern.
Best I can tell, the automatic arrival of new traders to a system or the spawning of Thargoids in interstellar space are the main triggers of the CTD while cloaked.

A Rock Hermit only rarely causes a CTD if it adds a defensive ship while I'm cloaked, but I had to hack rockHermitAI.plist script to make that occur. I had to add in a delay between when it was attacked and when it launched a defensive ship to give me time to re-cloak.

The hyperspace arrival rings can sometimes be seen even if the Thargoids are removed.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Progress

Post by cim »

Following this discussion markSystem has been changed slightly from this approach

Its parameters can now either be numbers or objects. If they're numbers, they work exactly as they would in 1.76, so there should be no need to rewrite code from 1.76 just to get it to work in 1.77. However, by passing an object rather than a number you can put the marker in to its own group so that other OXPs can't accidentally overwrite it, and you can also change how the marker looks.
Image
Two markers, of different styles, applied to Leesti.

Cargo and passenger contract markers have been changed away from the old red-X style to distinguish them from mission destinations.

(People following trunk who are running r5117 or later will find that their mission markers all vanish when they upgrade to r5176 or later. It didn't seem worth cluttering up load/save with code to deal with that rare case. 1.76 savegames will get their markers converted to the new system just fine, of course)
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Progress

Post by cim »

A new feature for trunk: scriptable flight AI.

This provides an intermediate level between calling "performAttack" or "performFlyToRangeFromDestination" to let the core game code provide generic behaviour, and the other extreme of carefully repositioning and reorienting the ship every frame with a frame callback.

In the AI, you use the command "performScriptedAI" or "performScriptedAttackAI" to put the ship into scriptable flight AI mode. It will then remain in this behaviour mode until you switch it to a different mode in the AI, or an error occurs in the script. While in this mode, the scriptedAI function in the ship script is called each frame to determine the behaviour.

Code: Select all

this.scriptedAI = function(delta) 
{
    // delta = duration of frame. Often irrelevant unless you're doing
    // ultra-high-precision turns, or want a manouevre to last a particular
    // length of time

    // calculations happen here
    return flightParameters;  
}
The function gets a virtual joystick to control the ship with, by returning an object with up to 5 properties. All properties are optional, though returning an object is not. The default is level flight, at zero speed, with the forward weapon selected. Numbers outside the allowed range will be corrected to the nearest allowed value.
  • stickRoll: number between -ship.maxRoll and ship.maxRoll
  • stickPitch: similarly for pitch
  • stickYaw: and for yaw
  • desiredSpeed: number at least 0. If this is above ship.maxSpeed, and the ship has usable injectors, it will use them.
  • chosenWeapon: "FORWARD", "AFT", "PORT" or "STARBOARD"
The ship will then respond to the virtual joystick. If a large change is requested - say the ship is in level flight, and the virtual joystick is moved to maximum clockwise roll - then it will take some time for the ship to respond and accelerate to that roll rate: quite possibly more than one frame.

If the attack version of the AI is selected, and the ship's current target is in the sights of the selected weapon (and there is a weapon there, and it's ready to fire, etc.), the weapon will be fired.

For example:

Code: Select all

this.scriptedAI = function(delta) 
{
  return { stickPitch: -0.2;
           desiredSpeed: this.ship.maxSpeed;
           chosenWeapon: "PORT"; };
}
will make the ship perform a fairly wide loop, and in attack mode, firing its port laser if the target crosses its sights. Might be a decent evasive attack if the target is the size of a small moon...

This lets you make a ship fly in a way consistent with other ships, without having to mess around with quaternions and masses of validation that you're not suddenly flipping the ship over in a single frame. A good grasp of vectors (and dot products, if you want to line the ship up with anything) is still needed, though.

Since the function is called once per frame, it needs to be quick. This is not the place to mess around searching for entities and new targets, for instance. You do have time for a fair bit of vector maths, though.

There's no direct support for things like missiles, ECM, and other ship equipment, but you can of course call ship.fireMissile() or ship.fireECM() from within the scriptedAI function.

A quick commented example: Orbital Patrol. This OXP adds a number of police ships to planetary orbit in the safer systems, and then uses a scripted AI to make them actually orbit the planet.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Progress

Post by Smivs »

cim wrote:
[*]chosenWeapon: "FORWARD", "AFT", "PORT" or "STARBOARD"[/list]
The ship will then respond to the virtual joystick. If a large change is requested - say the ship is in level flight, and the virtual joystick is moved to maximum clockwise roll - then it will take some time for the ship to respond and accelerate to that roll rate: quite possibly more than one frame.

If the attack version of the AI is selected, and the ship's current target is in the sights of the selected weapon (and there is a weapon there, and it's ready to fire, etc.), the weapon will be fired.

For example:

Code: Select all

this.scriptedAI = function(delta) 
{
  return { stickPitch: -0.2;
           desiredSpeed: this.ship.maxSpeed;
           chosenWeapon: "PORT"; };
}
will make the ship perform a fairly wide loop, and in attack mode, firing its port laser if the target crosses its sights.
So NPCs can have and use side lasers?
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Progress

Post by cim »

Smivs wrote:
So NPCs can have and use side lasers?
Yes
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Progress

Post by Smivs »

Ooooo! Missed that earlier. Brilliant - thanks. :D
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Cody
Sharp Shooter Spam Assassin
Sharp Shooter Spam Assassin
Posts: 16081
Joined: Sat Jul 04, 2009 9:31 pm
Location: The Lizard's Claw
Contact:

Re: Progress

Post by Cody »

cim wrote:
This OXP adds a number of police ships to planetary orbit in the safer systems, and then uses a scripted AI to make them actually orbit the planet.
Excellent... that fits nicely into some Oofic... thanks, cim!
Smivs wrote:
Missed that earlier.
Pay attention at the back there!
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Progress

Post by Smivs »

Eh, what? :D
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
Rese249er
---- E L I T E ----
---- E L I T E ----
Posts: 647
Joined: Thu Jun 07, 2012 2:19 pm
Location: Well, I WAS in G3...

Re: Progress

Post by Rese249er »

Huh-wha?
Got all turned around, lost my nav connection... Where am I now?
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:

Re: Progress

Post by Commander McLane »

cim wrote:
A new feature for trunk: scriptable flight AI.
:shock: Very intriguing! :D
cim wrote:
  • desiredSpeed: number at least 0. If this is above ship.maxSpeed, and the ship has usable injectors, it will use them.
It could perhaps also use an additional desiredSpeedFactor. If above 1.0, injectors would be used. This would allow ships with different max speeds to use the same scriptedAI and fly at their respective speeds.

This can of course be done with desiredSpeed: this.ship.maxSpeed * speedFactor, but since the traditional AI programming allows both setSpeedTo: and setSpeedFactorTo:, it might be more easily accessible to have two different methods in the scriptedAI as well.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Progress

Post by cim »

Commander McLane wrote:
This can of course be done with desiredSpeed: this.ship.maxSpeed * speedFactor, but since the traditional AI programming allows both setSpeedTo: and setSpeedFactorTo:, it might be more easily accessible to have two different methods in the scriptedAI as well.
The same logic would also suggest stickRollFactor, stickPitchFactor and stickYawFactor.

Added in r5204.
User avatar
CommonSenseOTB
---- E L I T E ----
---- E L I T E ----
Posts: 1397
Joined: Wed May 04, 2011 10:42 am
Location: Saskatchewan, Canada

Re: Progress

Post by CommonSenseOTB »

oh boy, oh boy, oh boy!!!

:lol:

:D

These are amazing cim, thanks for providing an easier way to do some things in some oxp features I have yet to write but are planned and of which some of the groundwork has already been made. :D

I have some requests:

1)currentWeapon working to query the npc's currently selected or used laser, if that's even possible. The currently chosenWeapon?

2)weapon positions exposed to javascript as a read property for at least the player ship.

3)thrust as a writeable property for the player ship(already writeable for the npc's)

All of these have uses in many of the 12 or so oxps on my hard drive that are in various states of construction.

Thanks for all the great work cim! I for one greatly appreciate your efforts! :D
Take an idea from one person and twist or modify it in a different way as a return suggestion so another person can see a part of it that can apply to the oxp they are working on.


CommonSense 'Outside-the-Box' Design Studios Ltd.
WIKI+OXPs
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Progress

Post by cim »

CommonSenseOTB wrote:
1)currentWeapon working to query the npc's currently selected or used laser, if that's even possible. The currently chosenWeapon?
NPCs don't quite have a concept of "current weapon" in the same way that the player does, but it's probably close enough.
CommonSenseOTB wrote:
2)weapon positions exposed to javascript as a read property for at least the player ship.
Sounds reasonable. Might as well be for all ships.
CommonSenseOTB wrote:
3)thrust as a writeable property for the player ship(already writeable for the npc's)
Hmm. Not sure about this one, since it's previously explicitly been excluded from being writeable for the player ship.
Post Reply