Scripters cove

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

User avatar
GGShinobi
---- E L I T E ----
---- E L I T E ----
Posts: 291
Joined: Tue Dec 25, 2012 7:20 pm

Re: Question about Timers

Post by GGShinobi »

Thanks Wildeblood, I'll try that.

And I think I understand now why my first experiments with timers failed miserably... :lol:
忍 knowing that enough is enough, you'll always have enough.

Running Oolite 1.77 on Ubuntu Linux 12.04 LTS
User avatar
Rorschachhamster
---- E L I T E ----
---- E L I T E ----
Posts: 274
Joined: Sun Aug 05, 2012 11:46 pm
Contact:

Re: Scripters cove

Post by Rorschachhamster »

Ok, quaternions... :roll:
In the documentation on the wiki there is the example for a rotation with two subentities at 120° +/-. I work on a three point system of leading a ship slowly unto the position of another entity with a very slow pace (to avoid collision warning before the very near point is reached). This is what I have, with rotationBy as the example rotations, because it is three sided, for the vector that is the vector on wich the ship closes in:

Code: Select all

	this.vectorContainer = chosenWagon.vectorUp;
	var choosedirection = Math.ceil(Math.random()*3);
	switch (choosedirection) {
	case(1):
	this.vectorContainer = chosenWagon.vectorUp.rotateBy([0.5,0,0,0.8660254]);
	break;
	case (2):
	this.vectorContainer = chosenWagon.vectorUp.rotateBy([0.5,0,0,-0.8660254]);
	break;
	default:
	break;
	};
Now, if this.vectorContainer isn't changed it works like a charm... :? Any hints?
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

How do I scan an array and delete each element that has a particular value? I was thinking I could just use a for loop, but that's nonsense because as soon as an element gets deleted the array changes length.

Here the fifth element of each sub-array is its category:-

Code: Select all

this.$tips = [
	["content","content","content","content","myCategory"],
	["content","content","content","content","otherCategory"],
	["content","content","content","content","myCategory"]
];
And I want to remove two of the three sub-arrays by calling this.$removeTips(myCategory).

Code: Select all

// REMOVE ALL TIPS IN GIVEN CATEGORY

this.$removeTips = function(category)
	{
	var counter = 0;
	for (var i = 0; i < this.$tips.length; i++) // BOGUS!
		{
		if (this.$tips[i][5] && this.$tips[i][5] === category)
			{
			delete this.$tips[i];
			counter++;
			}
		}
	return counter;
	}
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Scripters cove

Post by Eric Walch »

Games use quaternions because this is the fastest way to calculate 3D movements. When you want to do movements, you start with calculating the movement quaternion: That do you by taking the identity quaternion [1,0,0,0] and rotate is according to the axes you need. Than you have the quaternion with the rotation and multiply that with the old ships quaternion.

e.g.
q = new Quaternion(1,0,0,0)
q = q.rotateZ(rol*Δt);
q = q.rotateX(pitch*Δt);
ship.orientation = ship.orientation.multiply(q);

(I am not sure about the multiplying order in the last line. It could be the other way round. It is a long time ago I wrote a test script doing it this way and I can't find it anymore)

In here Δt is the time parameter, assuming you do it in frameCallbacks.
Last edited by Eric Walch on Wed Mar 06, 2013 4:10 pm, edited 1 time in total.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Wildeblood wrote:
How do I scan an array and delete each element that has a particular value? I was thinking I could just use a for loop, but that's nonsense because as soon as an element gets deleted the array changes length.
Reverse the for loop

Code: Select all

for (var i = this.$tips.length-1 ; i >= 0 ; i--)
Then if you delete an element from the array, it only reindexes elements you've already considered, and doesn't affect your array pointer.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

cim wrote:
Reverse the polarity of the plasma conduits.
Thanks, cim.
User avatar
Rorschachhamster
---- E L I T E ----
---- E L I T E ----
Posts: 274
Joined: Sun Aug 05, 2012 11:46 pm
Contact:

Re: Scripters cove

Post by Rorschachhamster »

Eric Walch wrote:
Games use quaternions because this is the fastest way to calculate 3D movements. When you want to do movements, you start with calculating the movement quaternion: That do you by taking the identity quaternion [1,0,0,0] and rotate is according to the axes you need. Than you have the quaternion with the rotation and multiply that with the old ships quaternion.

e.g.
q = new Quaternion(1,0,0,0)
q = q.rotateZ(rol*Δt);
q = q.rotateX(pitch*Δt);
ship.orientation = ship.orientation.multiply(q);

(I am not sure about the multiplying order in the last line. It could be the other way round. It is a long time ago I wrote a test script doing it this way and I can't find it anymore)

In here Δt is the time parameter, assuming you do it in frameCallbacks.
Ok... this sounds like I can understand it, eventually. :lol: Oh, and I probably have to because visualEffects can't be AIed. :D

But the actual problem is really more a Vector3D question, in wich rotateBy uses a Quaternion to specify the rotation. :D
I need the vectorUp rotated by 120° (and 240° or -120°) around the z-axis of the ship that it's originates from, but it's in another ship's script.
The chosenWagon is the origin of the vectorUp. So, it has to be turned around the vectorForward (or heading) of that ship, and I thought this would be done by the same quaternion as in the subentities example on the wiki. Obviously this doesn't work. Maybe because I have to work that z-axis to be turned around somehow in? :P I really don't know, how...
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

Hello helpful people. Question about weaponFacings.

I'm using this code to read the number of weapon facings of a targeted ship:

Code: Select all

this.shipTargetAcquired = function(target) {
	log("facings", target.weaponFacings);
}
I'm getting a reading 15 from Orbital Shuttle and Buoy (amongst others). Is this property in use yet and what does it actually tell?

I'm am a bit confused as Orbital Shuttle's shipdata says:

Code: Select all

forward_weapon_type = "WEAPON_NONE";
...
weapon_facings = 0;
weapon_position_aft = "0.0 0.0 -17.5";
weapon_position_forward = "0.0 -4.5 17.5";
weapon_position_port = "-9.0 0.0 11.5";
weapon_position_starboard = "9.0 0.0 11.5";
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Scripters cove

Post by Thargoid »

The wiki tells all. The value is a bitmask of the four facings and whether they are available or not.

The other bits in shipdata are the weapon positions on the model-is where the beam comes from when that weapon fires. But yes the weapon_facings setting in the shipdata does seem a bit odd and is being ignored for some reason, maybe being overridden by having the position entire in there.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

spara wrote:
I'm getting a reading 15 from Orbital Shuttle and Buoy (amongst others). Is this property in use yet and what does it actually tell?

I'm am a bit confused as Orbital Shuttle's shipdata says:
Do you have any replacement shipsets installed? If so, I don't believe any of those have yet been updated to include the weapon_facings parameter, so they'll be overriding the core shipdata, not specifying it, and it'll default back to 15.
User avatar
Smivs
Retired Assassin
Retired Assassin
Posts: 8408
Joined: Tue Feb 09, 2010 11:31 am
Location: Lost in space
Contact:

Re: Scripters cove

Post by Smivs »

cim wrote:
Do you have any replacement shipsets installed? If so, I don't believe any of those have yet been updated to include the weapon_facings parameter...
<Smivs adds another line to his 'To do' list...>
Commander Smivs, the friendliest Gourd this side of Riedquat.
User avatar
spara
---- E L I T E ----
---- E L I T E ----
Posts: 2691
Joined: Wed Aug 15, 2012 4:19 am
Location: Finland

Re: Scripters cove

Post by spara »

Why of course :shock:. You must be psychic cim. I'm using Griff's atm and at the same time looking at the core ship definitions. All clear now, thanks a lot.

This probably means, that before the most popular shipsets are updated, it's not advisable to rely on this property.
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

spara wrote:
This probably means, that before the most popular shipsets are updated, it's not advisable to rely on this property.
Well, that and we're never going to be in a position where every miscellaneous ship OXP has it set even if they should. Before 1.77 every NPC ship had a value of 15 (and the property was implicit). Now almost every ship still has a value of 15, but some of them don't. It's one of those things that will gradually get better over time, but it's still at least slightly useful now.
User avatar
Rorschachhamster
---- E L I T E ----
---- E L I T E ----
Posts: 274
Joined: Sun Aug 05, 2012 11:46 pm
Contact:

Re: Scripters cove

Post by Rorschachhamster »

Quick AI script question:
Does "setTargetToRandomStation" choose the main station as well?
Because I never encountered it in my tests, and that were many tests... :roll:

EDIT: ...and, connected to the first question can I use "rollD: 10" and then only let something happen if a 1 is rolled and ignore other results? I would think so...
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

Re: Scripters cove

Post by cim »

Rorschachhamster wrote:
Does "setTargetToRandomStation" choose the main station as well?
Only if there are no other non-carrier dockables in the system, which is generally rare.
Rorschachhamster wrote:
EDIT: ...and, connected to the first question can I use "rollD: 10" and then only let something happen if a 1 is rolled and ignore other results? I would think so...
Yes, certainly. The rollD command just generates a particular AI event, and as with other AI events you're under no obligation to respond.
Post Reply