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

Random Hits OXP

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

Moderators: winston, another_commander

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 difference in hassle is not that big, and I don't really mind adding a new page to the wiki. It needs to be done at some point or other, so we might as well do it to begin with anyway.

I do mind writing documentation in general, though! ;)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Kaks wrote:
The difference in hassle is not that big, and I don't really mind adding a new page to the wiki. It needs to be done at some point or other, so we might as well do it to begin with anyway.

I do mind writing documentation in general, though! ;)
If there are a few examples on the wiki of how things should be done, I'm pretty sure that some of us won't mind taking these new things and adding them to the wiki.

Let's just hope that the announcements have enough details in them that the transcription to the wiki becomes useful.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Post by Eric Walch »

Kaks wrote:
You mean something like this?

Code: Select all

system.info.distanceToSystem(System.infoForSystem(0, 55));
Hmmm, it's not on the wiki yet.
Hmm. there is a bug somewhere in trunk. "System" capitalised gives currently errors. "system" does work. Must be very recent as in UPS I always use "System". But I just tested, even "System.ID" returns an error and "system.ID" not. I was told in the past that writing "System" is preferred over "system". EDIT: In the latest build it works correct again.

Best way of writing is:

Code: Select all

system.info.distanceToSystem(system.infoForSystem(galaxyNumber, 55))
(It only works for the current galaxy, so it is more foolproof to fill in the global variable galaxyNumber)
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

I have begin translating the event-based property list script into an event-driven javascript script.

I have translated the first third of the code (3000 lines), with a reduction down to 16% of the original size.

I was going to provide a first-look at the code, but box.net isn't wanting to load for me right now, so I'll post the most interesting part of the code here, adding the spacebar.

A question to start with is:
  • The property list uses variables such as [random_hits_rocks_number2]. How is javascript to normally read those variables.

Code: Select all

this.addSpaceBarToSystem = function () {
    function systemIsAllowed() {
        var notAllowed = [46];
        if (notAllowed.indexOf(system.ID) > -1) {
            return false;
        }
        return true;
    }
    function spacebarNumber(systemID) {
        var spacebars = [ // 20 systems per row
            1,  1,  1,  1,  1,  1,  2,  2,  2,  2,  2,  2,  3,  3,  3,  3,  3,  3,  4,  4,
            4,  4,  4,  4,  5,  5,  5,  5,  5,  5,  6,  6,  6,  6,  6,  6,  7,  7,  7,  7,
            7,  7,  40, 40, 40, 40, 40, 8,  8,  8,  8,  8,  8,  9,  9,  9,  9,  9,  9,  10,
            10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 13, 13, 13,
            13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16,
            16, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, 19, 19, 20,
            20, 20, 20, 20, 20, 20, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22,
            23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 25, 25, 25, 25, 25, 25,
            25, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 28, 28, 28, 28, 28,
            28, 28, 29, 29, 29, 29, 29, 29, 29, 30, 30, 30, 30, 30, 30, 30, 31, 31, 31, 31,
            31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34,
            34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, 36, 36, 36, 37, 37,
            37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 39, 39, 39, 39
        ];
        return spacebars[systemID];
    }
    function addSpacebar(type) {
        var coords = [
            [-41190, 33291, 240408],
            [-5106, 5174, 388275],
            [12644, 13830, 353962],
            [25774, -10946, 314064],
            [-48509, -9524, 266555]
        ],
            coordIndex = [1, 2, 3, 4, 0, 1, 2, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1,
                        2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 3],
            position = coords[coordIndex[type - 1]];
        missionVariables.random_hits_seedy_spacebar_name = '[random_hits_barname' + type + ']';
        system.addShipsAtPrecisely('random_hits_spacebar' + type, 1, 'pwm', position);
        missionVariables.random_hits_spacebar_position = position;
        system.addShipsWithinRadius('random_hits_griff_autominer', '[random_hits_rocks_number]', 'pwm', position, 15000);
        system.addShipsWithinRadius('asteroid', '[random_hits_rocks_number2]', 'pwm', position, 25000);
        system.addShipsWithinRadius('random_hits_minesweeper', 1, 'pwm', position, 4000);
    }
    if (system.countShipsWithRole('random_hits_spacebar1') === 0) {
        if (system.government === 0 && systemIsAllowed()) {
            addSpacebar(spacebarNumber(system.ID));
            if (missionVariables.random_hits_seedy_spacebar_name === null && !system.isInterstellarSpace) {
                addSpacebar(17);
            }
        }
    }
};
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
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 »

pmw57 wrote:
The property list uses variables such as [random_hits_rocks_number2].
That's not a variable, but an entry in descriptions.plist (and yes, Random Hits uses a lot of those for the randomized descriptions).

If you want its content in a JS script, use expandDescription("[random_hits_rocks_number2]").
User avatar
LittleBear
---- E L I T E ----
---- E L I T E ----
Posts: 2868
Joined: Tue Apr 04, 2006 7:02 pm
Location: On a survey mission for GalCop. Ship: Cobra Corvette: Hidden Dragon Rated: Deadly.

Post by LittleBear »

It was really just a workround for the fact that in legacy you can only have a random number with a d100 (0 - 100) or d256 (0 - 256). So if in legacy you want a random number between say 5 and 15, you have to put the numbers into a descriptions.plist array and then use the array's name as your random number generator.

As Commander McLane says, most of the descriptions file is lists of words used to make the messages and hails in the same way as the original "deady goats" strings are used in Elite. Eg, you've probabley noticed that on the BBs each victims is described as a [something] [somthing] [somthing]. The mission text just contains the array names. A name from each list is randomly picked for each array independantly to create "a nasty rotund arts graduate" "a stange radioactive actor" or whatever.
OXPS : The Assassins Guild, Asteroid Storm, The Bank of the Black Monks, Random Hits, The Galactic Almanac, Renegade Pirates can be downloaded from the Elite Wiki here.
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 »

pmw57, I would seriously consider internalising those descriptions.plist arrays as js arrays and pick a random adjective/name from those.

Whenever any description from descriptions.plist is accessed, oolite has to go through a dictionary (obj-c speak for associative array) made up of the sum of all the descriptions.plists for all oxps put together, which isn't exactly the most efficient way of doing things, but was the only available option using legacy script...
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Kaks wrote:
pmw57, I would seriously consider internalising those descriptions.plist arrays as js arrays and pick a random adjective/name from those.

Whenever any description from descriptions.plist is accessed, oolite has to go through a dictionary (obj-c speak for associative array) made up of the sum of all the descriptions.plists for all oxps put together, which isn't exactly the most efficient way of doing things, but was the only available option using legacy script...
That's a good idea. I take it that there are situations where keeping the names in the descriptions.plists file is more appropriate (for data separation and internationalisation) in which case reading them in when the script starts, into a script-based array would be an appropriate solution.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
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 »

One situation I can think of is if an AI.plist needs to access a string. In that case, we definitely want to keep the original string inside descriptions.plist... :)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Kaks wrote:
One situation I can think of is if an AI.plist needs to access a string. In that case, we definitely want to keep the original string inside descriptions.plist... :)
Okay, so for now I will cache the desired descriptions when the script loads, to help avoid any cross-use issues.
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post by JensAyton »

pmw57 wrote:

Code: Select all

Instead of bickering, here is a better way to seed a random number based on the time.

[code]this.ReserveDutySystemDetermination = function()
{
	var sec = clock.minutesComponent * 60 + clock.secondsComponent,
		dummy;
	for (var i = 0 ; i < sec ; i++) {
		dummy = Math.random();
	}
	this.ReserveDutySystemDeterminationPt2();
}
Er, what exactly is this intended to achieve? JavaScript’s Math.random() is not affected by Oolite’s random seed resets. Math.random() doesn’t seem to be an especially good PRNG (although better than either of Oolite’s), but “stirring” it like this shouldn’t give you an appreciably “more random” result.
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

Ahruman wrote:
pmw57 wrote:

Code: Select all

Instead of bickering, here is a better way to seed a random number based on the time.

[code]this.ReserveDutySystemDetermination = function()
{
	var sec = clock.minutesComponent * 60 + clock.secondsComponent,
		dummy;
	for (var i = 0 ; i < sec ; i++) {
		dummy = Math.random();
	}
	this.ReserveDutySystemDeterminationPt2();
}
Er, what exactly is this intended to achieve? JavaScript’s Math.random() is not affected by Oolite’s random seed resets. Math.random() doesn’t seem to be an especially good PRNG (although better than either of Oolite’s), but “stirring” it like this shouldn’t give you an appreciably “more random” result.
You're right. It's not not the best way, it's just a better way than what was being done before.

The best way is to to just use the javascript Math.random() function by itself, because the randomness is seeded by the current time.

--
Paul Wilkins
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
pmw57
---- E L I T E ----
---- E L I T E ----
Posts: 389
Joined: Sat Sep 26, 2009 2:14 pm
Location: Christchurch, New Zealand

Post by pmw57 »

pmw57 wrote:
Er, what exactly is this intended to achieve? JavaScript’s Math.random() is not affected by Oolite’s random seed resets. Math.random() doesn’t seem to be an especially good PRNG (although better than either of Oolite’s), but “stirring” it like this shouldn’t give you an appreciably “more random” result.
You're right. It's not not the best way, it's just a better way than what was being done before.

The best way is to to just use the javascript Math.random() function by itself, because the randomness is seeded by the current time.

--
Paul Wilkins[/quote]
A trumble a day keeps the doctor away, and the tax man;
even the Grim Reaper keeps his distance.
-- Paul Wilkins
aracer
Average
Average
Posts: 9
Joined: Mon Nov 02, 2009 1:26 am

Post by aracer »

Sorry I've not been through the whole thread (only about 20 pages of it!), so don't know if this has already been mentioned, but I've found a bug in the OXP.

I scooped the escape vessel of the hit, then as I was in an Anarchy my first dock was with a bar. When I docked I got the message that the bar was under attack and did I want to go out and fight - I selected to go and fight. I then got the message about having not fulfilled the contract and did I want to contact the cops or murder the hit - I found I couldn't switch between the selections or select one as I was already launched - could fly but had no view until I selected F1.

Anyway I then shot down a few pirates before redocking, at which point I get the mission selection screen. I selected one, but pressing f5,f5 still says "dock for a moral dilemma" - I don't seem to be able to select a new mission. Tried leaving and redocking and also docking at the normal station instead, but no change (whenever I dock I now get a strange screen until I press f5). It seems I'm stuck with not being able to do any more missions at the moment. I'd guess part of the problem now might be that I sold my slaves after selecting a new mission!

Presumably I should be able to edit my save file to fix this (happy to lose the kill - it was only an easy one anyway) - any tips on how to do this?

BTW thanks for the OXP - has kept up the interest in oolite when I was about to give up.
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 »

pmw57 wrote:
Kaks wrote:
One situation I can think of is if an AI.plist needs to access a string. In that case, we definitely want to keep the original string inside descriptions.plist... :)
Okay, so for now I will cache the desired descriptions when the script loads, to help avoid any cross-use issues.
How do you do that? I'd like to do the same withe the descriptions.plist I use for personalities.oxp, but don't know how to.

So, how do I convert the arrays in descriptions.plist into an JS-array? I haven't yet managed to address the array-entries in descriptions.plist one by one. If I try something like personalities-mclane-attacked[n], I don't get the n'th entry in the personalities-mclane-attacked array, but the n'th letter in one random entry. What is the correct JS syntax?
Post Reply