Page 10 of 11

Posted: Sat Mar 15, 2008 5:08 pm
by Roberto
If it's reading it only once per system, presumably I don't need to reset at the end, right? Here's what I'm about to test (I'm still unsure as to whether there should be some more <dict>s in there):

Code: Select all

			<string>checkForShips: taranis_frigate</string>
				<dict>
					<key>conditions</key>
					<array>
					<string>shipsFound_number lessthan 1</string>
					</array>
					<key>do</key>
					<array>
					<string>set: taranis_frigate_d100 [d100_number]</string>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 1</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 145000 -29000 60500</string>
						</array>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 2</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 250024.81 25.77 -102991.52</string>
						</array>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 3</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 178372.66 -9495.88 142342.08</string>
						</array>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 4</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 41048.76 33024.20 -3352.26</string>
						</array>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 5</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 178919.30 -39904.60 73889.03</string>
						</array>
					</array>
				</dict>

Posted: Sat Mar 15, 2008 5:27 pm
by JensAyton
<key> only makes sense inside a <dict>, and each condition/do/else needs to be in a dictionary. This really is easier using the OpenStep syntax instead of XML; this:

Code: Select all

<dict>
    <key>conditions</key>
    <array>
        <string>your-conditions-here</string>
    </array>
    <key>do</key>
    <array>
        <string>your-actions-here</string>
    </array>
</dict>
becomes

Code: Select all

{
    conditions = ( "your-conditions-here" );
    do = ( "your-actions-here" );
}
See http://wiki.alioth.net/index.php/Property_list for more information on the two syntaxes.

Posted: Sat Mar 15, 2008 5:34 pm
by Roberto
Thanks Ahruman.

Posted: Sat Mar 15, 2008 10:07 pm
by Roberto
I've left it as XML (though I've used OpenStep elsewhere), because I just want to get this done now. And it's still not working... :(

Code: Select all

			<string>checkForShips: taranis_frigate</string>
				<dict>
					<key>conditions</key>
					<array>
					<string>shipsFound_number lessthan 1</string>
					</array>
					<key>do</key>
					<array>
					<string>set: taranis_frigate_d100 [d100_number]</string>
						<dict>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 1</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 145000 -29000 60500</string>
						</array>
						</dict>
						<dict>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 2</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 250024.81 25.77 -102991.52</string>
						</array>
						</dict>
						<dict>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 3</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 178372.66 -9495.88 142342.08</string>
						</array>
						</dict>
						<dict>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 4</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 41048.76 33024.20 -3352.26</string>
						</array>
						</dict>
						<dict>
						<key>conditions</key>
						<array>
						<string>taranis_frigate_d100 equal 5</string>
						</array>
						<key>do</key>
						<array>
						<string>addShipsAtPrecisely: taranis_frigate 1 pwm 178919.30 -39904.60 73889.03</string>
						</array>
						</dict>
					</array>
				</dict>
(To test it, I added 45 more possibilities to up the odds to 50%, but I've been in and out of the system God knows how many times, and nothing.)

Posted: Sat Mar 15, 2008 10:42 pm
by LittleBear
This might be an easier way to do it (might work better on the dice). In descriptions .plist set an array with the different co-ordinates as variables. Eg somthing like:-

Code: Select all

	<key>mission_my_mission_start_position_number</key>
	<array>
	<string>145000 -29000 60500</string>
	<string>250024.81 25.77 -102991.52</string>

...  etc etc for all your different co-ords

	</array>

Then in script you only need one command of:-

Code: Select all

addShipsAtPrecisely: taranis_frigate 1 pwm [mission_my_mission_start_position_number]
Cos Oolite randomly picks one of your co-ordinate numbers in the strings from the list set as [mission_my_mission_start_position_number], that should work to give you the random effect you want. I used this wheeze in RandomHits to get a random number of rocks near the Space Bars and create a random starting position for the victims.
[/code]

Posted: Sat Mar 15, 2008 10:58 pm
by Roberto
Thanks LB - I'll give that a try.

*EDIT* Well, it works... except that it always seems to select the first set of coordinates. Like, five or six times in a row.

Posted: Sun Mar 16, 2008 12:12 am
by Kaks
If you haven't done it yet, try resetting the d100 variable! If you don't you'll be getting the same 'random' result over and over...

Posted: Sun Mar 16, 2008 12:28 am
by Roberto
*Sobs quietly*

But shouldn't it do a new roll every time I enter the system? In any case, descriptions.plist is failing to generate randomness.

OK, I've put (most of) planetinfo into OpenStep format now...

Code: Select all

{
	conditions = ("galaxy_number equal 0", "planet_number equal 141");
	do = (
		"checkForShips: taranis",
				{
				conditions = ("shipsFound_number lessthan 1");
				do = ("addShipsAtPrecisely: taranis 1 pwm 147000 -30000 60000");
				},
		"checkForShips: taranis_frigate",
				{
				conditions = ("shipsFound_number lessthan 1");
				do = (
				"set: taranis_frigate_d100 [d100_number]",
					{
					conditions = ("taranis_frigate_d100 equal 1");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 145000 -29000 60500");
					},
					{
					conditions = ("taranis_frigate_d100 equal 2");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 250024.81 25.77 -102991.52");
					},
					{
					conditions = ("taranis_frigate_d100 equal 3");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 178372.66 -9495.88 142342.08");
					},
					{
					conditions = ("taranis_frigate_d100 equal 4");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 41048.76 33024.20 -3352.26");
					},
					{
					conditions = ("taranis_frigate_d100 equal 5");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 178919.30 -39904.60 73889.03");
					},
				);
				},
		"checkForShips: taranis_billboard",
				{
				conditions = ("shipsFound_number lessthan 1");
				do = ("addShipsAtPrecisely: taranis_billboard 1 pwm 134090.75 -21957.00 55025.19");
				},
		<key>station</key>
		<string>taranis_sysstation</string>
		<key>description</key>
		<string>This planet is a dull place. The headquarters of shipbuilder Taranis Corp is in high orbit above it.</string>
	</dict>
</dict>
</plist>
How do I convert the two bits at the end, and do I still need to reset taranis_frigate_d100 at the end? (If so, I'm confused as to why - won't Oolite just roll a new number the next time it reads the plist, i.e. when you re-enter the system?)

Posted: Sun Mar 16, 2008 1:43 am
by Kaks
Ok, I'm really confused too.

However, if planetinfo.plist is exactly like this:

Code: Select all

{
	"0 141" = {
		"description" = "This planet is a dull place. The headquarters of shipbuilder Taranis Corp is in high orbit above it.";
		"station" = "taranis_sysstation";
		"script_actions"=(
			"checkForShips: taranis",
			{
				conditions = ("shipsFound_number lessthan 1");
				do = ("addShipsAtPrecisely: taranis 1 pwm 147000 -30000 60000");
			},
			"checkForShips: taranis_frigate",
			{
				conditions = ("shipsFound_number lessthan 1");
				do = (
					"set: mission_taranis_frigate_d100 [d100_number]",
					{
						conditions = ("mission_taranis_frigate_d100 equal 1");
						do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 145000 -29000 60500");
					},
					{
						conditions = ("mission_taranis_frigate_d100 equal 2");
						do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 250024.81 25.77 -102991.52");
					},
					{
						conditions = ("mission_taranis_frigate_d100 equal 3");
						do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 178372.66 -9495.88 142342.08");
					},
					{
						conditions = ("mission_taranis_frigate_d100 equal 4");
						do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 41048.76 33024.20 -3352.26");
					},
					{
						conditions = ("mission_taranis_frigate_d100 equal 5");
						do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 178919.30 -39904.60 73889.03");
					},
					"reset: mission_taranis_frigate_d100"
				);
			},
			"checkForShips: taranis_billboard",
			{
				conditions = ("shipsFound_number lessthan 1");
				do = ("addShipsAtPrecisely: taranis_billboard 1 pwm 134090.75 -21957.00 55025.19");
			},
		);
	},
}
your problems should be over - hoping that I haven't made a typo anywhere...

Posted: Sun Mar 16, 2008 10:34 am
by Eric Walch
Roberto wrote:
*EDIT* Well, it works... except that it always seems to select the first set of coordinates. Like, five or six times in a row.
also my experience with "random" selections from a description.plist. For a certain system, the majority of the selections are always the same. In an other system it might be an other. I noticed this in 1.65/1.69 but it might be also under 1.70.

Just a question why you only select with a chance of 1%. This means you have to enter that specific system 100 times to see it once. It looks a little to rare to me.

Posted: Sun Mar 16, 2008 11:26 am
by Commander McLane
I think the problem is that "random" in Oolite isn't really random; it's, well, pseudo-random, determined by the seed.

I think we can imagine it like a long list of numbers that are somehow randomly evenly distributed between 0 and 99. If a script calls for a random number, the engine just takes the next number from the list.

So, Roberto, if you load a save-game for testing purposes, the list will always be the same, and of course the position the engine has reached on the list will always be the same. Therefore also the next number in the list will always be the same.

In reality and with many OXPs installed this is not so big an issue, because scripts are executed in a random order. So if you reload a savegame, any of the scripts may get the "next number from the list", and your script will then get the second-to-next or third-to-next, which for the player looks more randomly. But in any situation where only one script could require a "next number from the list", it will always get the same number, if started from the same position on the list.

Posted: Sun Mar 16, 2008 2:14 pm
by Eric Walch
I think the problem is that "random" in Oolite isn't really random; it's, well, pseudo-random, determined by the seed.
Just for testing purposes I made once a description.plist with content: one, two, three etc. Then in flight I issued a commsMessage with this description on every update. 4 out of 5 time it used the same text. When I jumped into an other system, an other number was the dominant message. When coming back in a system I was before, the same message as before was dominant. Distributed over all systems it is random but within a system some selections are preferred.

Posted: Sun Mar 16, 2008 2:19 pm
by JensAyton
The problem here is that Oolite uses two different “random” number generators, and both are used both for things that should be “really” random and for things that should be predictable. Maybe we should add a third one for “really really random” things…

Posted: Sun Mar 16, 2008 2:58 pm
by Kaks
...or bite the bullet and use javascript for random numbers...
And everything else! :)

- What? Biased? Me? :D

Posted: Sun Mar 16, 2008 3:32 pm
by Roberto
Kaks, I've now got this, but Terminal doesn't like it:

Code: Select all

{
	"0 141" = {
		"description" = "This planet is a dull place. The headquarters of shipbuilder Taranis Corp is in high orbit above it.";
		"station" = "taranis_sysstation";
		"script_actions" = (
			"checkForShips: taranis",
				{
				conditions = ("shipsFound_number lessthan 1");
				do = ("addShipsAtPrecisely: taranis 1 pwm 147000 -30000 60000");
				},
			"checkForShips: taranis_frigate",
				{
				conditions = ("shipsFound_number lessthan 1");
				do = (
				"set: taranis_frigate_d100 [d100_number]",
					{
					conditions = ("taranis_frigate_d100 equal 1");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 145000 -29000 60500");
					},
					{
					conditions = ("taranis_frigate_d100 equal 2");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 250024.81 25.77 -102991.52");
					},
					{
					conditions = ("taranis_frigate_d100 equal 3");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 178372.66 -9495.88 142342.08");
					},
					{
					conditions = ("taranis_frigate_d100 equal 4");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 41048.76 33024.20 -3352.26");
					},
					{
					conditions = ("taranis_frigate_d100 equal 5");
					do = ("addShipsAtPrecisely: taranis_frigate 1 pwm 178919.30 -39904.60 73889.03");
					},
				"reset: taranis_frigate_d100"
				);
				},
			"checkForShips: taranis_billboard",
				{
				conditions = ("shipsFound_number lessthan 1");
				do = ("addShipsAtPrecisely: taranis_billboard 1 pwm 134090.75 -21957.00 55025.19");
				},
		);
	},
}
Apparently this is what's wrong...

XML parser error:
Unexpected character { at line 1
Old-style plist parser error:
Missing ';' on line 45

...and I don't see what I'm supposed to do. Make it open { ( { somehow? :(