Page 1 of 2

Hello, thank you and a few questions...

Posted: Fri Jun 21, 2013 12:08 am
by Redspear
Hello all :) ,

I'm a veteran of Spectrum Elite back in the 80's but only ever made it to Dangerous.
Did the nova mission back then (big surprise jumping to a 'coloured' system).
Thought the game was an amazing experience: beyond what I'd previously thought possible on the ol' speccy.

So, many years later I find Oolite! Wow :shock: ... Thank you all. Whether you're a developer or your contribution is strictly 'feedback only', I've certainly had some fun with the fruits of your work. If you've contributed even a few oxps then chances are I've downloaded one of them and got something from it.

Just as Elite showed me what was possible on a simple home computer, Oolite has shown me what's possible with an active and supportive online community.
So if I may, (ahem :oops: ) "Right On Commanders!" :D


OK, now for some questions...
I'd like to tweak my game to make systems vary according to their inhabitants.
More specifically:

1. Different docking stations (e.g. Neolite stations for planets inhabited by birds)
2. Different shipyards (e.g. Ghavials only available on 'lizard worlds')
3. Different market prices (e.g. perhaps less demand for furs on feline planets but maybe more for luxuries)
4. Perhaps some other 'placements' (e.g. Wasp-nest station in insect worlds only)

Whilst I appreciate that there may be reasons not to do any one of these things, I think they would each add something to my 'Ooniverse'.

I thought that a 'condition script' would be the way to do this but it seems that 'Inhabitants' cannot be set as a condition in the way that 'Government' or 'Tech Level' can. I also looked at Hoopy Casinos to see if it could be done in similar manner i.e. picking a key word or phrase from a larger piece of text (e.g. 'lizards' from 'large bug-eyed cheese-eating lizards') but no luck as yet.

Is this sort of thing currently possible?
What level of 'coding skill' is it likely to require? (my current level is 'minimal')
Would anyone else like to see these sorts of things in game?
Is this post too long? :P

As I understand it, each system has a reference number, so I could perhaps use a conditon in the sense of 'any one of these systems', although I'm not sure how to approach that yet...

I may well have missed something simple but my time is limited these days (and my ability level probably even more so...)
I wouldn't want to spend hours working on something that is currently impractical.

Any help / advice would be appreciated.

Thanks again.

Re: Hello, thank you and a few questions...

Posted: Fri Jun 21, 2013 12:27 am
by another_commander
Hi and welcome.

It is indeed possible to scan the text of planet descriptions for keywords and act on them based on content, provided that localization is not an issue. Here is an example of searching for the keyword "insect" in planet descriptions using Javascript and regular expressions and using it for doing something (in this particular case, showing an image of an insect on the F7 screen):

Code: Select all

this.guiScreenChanged = function(toGUI)
{
	if (toGUI == 'GUI_SCREEN_SYSTEM_DATA')
	{
		var pat = /insect/i;
		if (System.infoForSystem(galaxyNumber, player.ship.targetSystem).inhabitants.match(pat))
		{
			setScreenOverlay("insectInhabitant.png");
		}
	}
}
Hope this helps. Glad you are enjoying the game and should you need more clarifications, don't hesitate to ask.

Re: Hello, thank you and a few questions...

Posted: Fri Jun 21, 2013 12:30 am
by Cody
Welcome aboard, Redspear. Interesting ideas - I hope you can cobble something together.

Re: Hello, thank you and a few questions...

Posted: Fri Jun 21, 2013 6:40 am
by cim
Redspear wrote:
I thought that a 'condition script' would be the way to do this but it seems that 'Inhabitants' cannot be set as a condition in the way that 'Government' or 'Tech Level' can. I also looked at Hoopy Casinos to see if it could be done in similar manner i.e. picking a key word or phrase from a larger piece of text (e.g. 'lizards' from 'large bug-eyed cheese-eating lizards') but no luck as yet.
A condition script can do this. But it has to be one of the new Javascript-based condition scripts from 1.77; as you've found, the legacy condition scripts can't check inhabitants.

So you could add to the Ghavial entry in shipyard.plist the line

Code: Select all

"condition_script" = "ghavial_conditions.js";
and then add a file called ghavial_conditions.js to the Scripts folder of the OXP

Code: Select all

this.allowOfferShip = function(shipKey) {
    if (shipKey == "ghavial-player") {
        var pat = /lizard/i;
        if (system.inhabitants.match(pat)) {
             return true; // Lizard world, Ghavials allowed
        } else {
             return false; // Not lizard world, Ghavials not allowed
        }
    }
    return true; // Not a Ghavial, so allow it anywhere
}
For NPC ships or stations, the condition_script reference goes in shipdata.plist instead, and you use the allowSpawnShip test.

Re: Hello, thank you and a few questions...

Posted: Fri Jun 21, 2013 2:21 pm
by Jenko
G'day all,
I'd like to firmly second these remarks of Redspear's:

"Thank you all. Whether you're a developer or your contribution is strictly 'feedback only', I've certainly had some fun with the fruits of your work. If you've contributed even a few oxps then chances are I've downloaded one of them and got something from it.

Just as Elite showed me what was possible on a simple home computer, Oolite has shown me what's possible with an active and supportive online community.
So if I may, (ahem :oops: ) "Right On Commanders!" :D"


In the last two weeks since discovering Oolite - I've had a lot of fun - & don't tell me to get a life (as if anyone here would). I've already had a long & good'un.
Cheers
Jenko

Re: Hello, thank you and a few questions...

Posted: Sat Jun 22, 2013 1:36 am
by Redspear
Thanks for the warm welcome! :D

Really appreciate you taking the time to give me some coding examples. That's both improved my understanding and saved me a lot of time and experimentation. Great stuff! :D

another_commander : It does help, thanks. I'm likely to need my fair share of clarifications, so that's good to know :)
Cody : Thanks for your interest. Yes, 'cobble' sounds about right for my programming 'skills' :lol:
cim : Ahh, so I need to upgrade my thinking to 1.77... Nicely explained :) .
Jenko : Nice to know that the sentiment is shared :D . Glad you're enjoying the game.

Thanks everyone!

Looks like I've got some tweaking to do :wink:

Re: Hello, thank you and a few questions...

Posted: Sat Jun 22, 2013 9:00 am
by Diziet Sma
And yet another victim one slips closer to the Dark Side™™.. :twisted:

Welcome aboard, Redspear! 8)

Re: Hello, thank you and a few questions...

Posted: Thu Jun 27, 2013 1:40 pm
by Redspear
Diziet Sma wrote:
And yet another victim one slips closer to the Dark Side™™.. :twisted:

Welcome aboard, Redspear! 8)
Thanks Diziet Sma!
I hear it's a slippery slope :wink:

Re: Hello, thank you and a few questions...

Posted: Sat Jun 29, 2013 1:46 pm
by Diziet Sma
It is indeed.. very few can resist its' siren song, once heard..

Cody is one of the rare few who manages to resist.. but even he still hears it calling to him, in the dark of the night.

Re: Hello, thank you and a few questions...

Posted: Sat Jun 29, 2013 1:59 pm
by Cody
Diziet Sma wrote:
It is indeed.. very few can resist its' siren song, once heard..
'I was drawn by the Sirens of Titan
Carried along by their call
Seeking for a way to enlighten
Searching for the sense of it all!'

Diziet Sma wrote:
Cody is one of the rare few who manages to resist.. but even he still hears it calling to him, in the dark of the night.
Some nights, I awake suddenly, drenched in cold sweat. Visions of plists and AIs haunt me... and cookies!

Re: Hello, thank you and a few questions...

Posted: Sat Jun 29, 2013 2:04 pm
by Smivs
The cookies make it worth it :D

Re: Hello, thank you and a few questions...

Posted: Sat Jun 29, 2013 4:38 pm
by Fatleaf
Who mentioned Cookies :shock:

Where? :D

Re: Hello, thank you and a few questions...

Posted: Sat Jun 29, 2013 5:30 pm
by Tricky
Mmm... Cookies!

Cookie dispener OXP anyone? 8)

Re: Hello, thank you and a few questions...

Posted: Thu Jul 04, 2013 2:42 pm
by Redspear
Having trouble getting this to work using the allowSpawnShip method for stations...
cim wrote:
So you could add to the Ghavial entry in shipyard.plist the line

Code: Select all

"condition_script" = "ghavial_conditions.js";
and then add a file called ghavial_conditions.js to the Scripts folder of the OXP

Code: Select all

this.allowOfferShip = function(shipKey) {
    if (shipKey == "ghavial-player") {
        var pat = /lizard/i;
        if (system.inhabitants.match(pat)) {
             return true; // Lizard world, Ghavials allowed
        } else {
             return false; // Not lizard world, Ghavials not allowed
        }
    }
    return true; // Not a Ghavial, so allow it anywhere
}
For NPC ships or stations, the condition_script reference goes in shipdata.plist instead, and you use the allowSpawnShip test.
I've created the file example above, swapped allowOfferShip for allowSpawnShip, changed Ghavial-player for the relevant station name and I've even remembered to add the condition script line to the relevant shipdata.plist.

Here's part of the log report:
[script.javaScript.exception.unexpectedType]: ***** JavaScript exception (zocto_conditions.js.anon-script): TypeError: system.inhabitants is undefined
13:44:58.300 [script.javaScript.exception.unexpectedType]: ../AddOns/Stations.oxp/Z_GrOovy_System_Stations.oxp/Scripts/zocto_conditions.js, line 4.
Some things that may be relevant :?: :

You may have noticed that I group oxps in folders to make it easier for me to manage them; such as all of my station oxps within the imaginatively titled, 'Stations.oxp".

I was having all sorts of problems making sense of the log reports until I realised that I was editing them using Notepad :roll:
I've since 'fixed' (or have I :?: ) them by simply opening the affected files with wordpad and then saving them.

Any ideas what I might be doing wrong?
I've mucked about with plists aplenty before but scripting is still new to me.

Re: Hello, thank you and a few questions...

Posted: Thu Jul 04, 2013 2:44 pm
by Cody
Do get Notepad++ - it's free and excellent. Grouping OXPs should be no problem - I've done similar for ages.