Back to Index Page generated: May 8, 2024, 6:16:03 AM

Expansion Pirate Cove

Content

Warnings

  1. License not specified
  2. XML Manifest found
  3. Unknown key 'licence' in XML manifest.plist

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Adds pirate bases to te system that are situated in rock hermits. Adds pirate bases to te system that are situated in rock hermits.
Identifier oolite.oxp.EricWalch.PirateCove oolite.oxp.EricWalch.PirateCove
Title Pirate Cove Pirate Cove
Category Ambience Ambience
Author Lazy Gun & Eric Walch Lazy Gun & Eric Walch
Version 1.4.2 1.4.2
Tags Hermits, Pirates Hermits, Pirates
Required Oolite Version
Maximum Oolite Version
Required Expansions
Optional Expansions
Conflict Expansions
Information URL http://wiki.alioth.net/index.php/Pirate_Coves_OXP n/a
Download URL https://wiki.alioth.net/img_auth.php/1/13/Pirate_Coves_1.4.2.oxz n/a
License
File Size n/a
Upload date 1610873237

Documentation

Also read http://wiki.alioth.net/index.php/Pirate%20Cove

Equipment

This expansion declares no equipment. This may be related to warnings.

Ships

Name
pirate-cove

Models

This expansion declares no models. This may be related to warnings.

Scripts

Path
Scripts/pirateCove.js
"use strict";
this.name        = "Pirate_Coves"; 
this.author      = "lazygun (JS adaption by EW)"; 
this.copyright   = "lazygun"; 
this.description = "Adds pirate coves to the system."; 
this.version     = "1.4.2"; 


this.startUp = function ()
{
    // restore the systems were a pirate cove is missing
    if (missionVariables.pirate_cove_systems)
    {
            this.pirateCoveSystems = JSON.parse(missionVariables.pirate_cove_systems);
    }
    else
    {
            this.pirateCoveSystems = new Array(256);
    }
    
    this.resetTimer = new Timer(this, this.shipExitedWitchspace, 0.1); // already add station before first launch
    this.basicDefenders = Math.round(Math.log(1 + player.score));
};

this.playerWillSaveGame = function()
{
    // encode the systems were a pirate cove is missing
    missionVariables.pirate_cove_systems = JSON.stringify(this.pirateCoveSystems);
}

this.playerEnteredNewGalaxy = function ()
{
    // reset the systems
    this.pirateCoveSystems = new Array(256);
}

this.shipExitedWitchspace = function ()
{
    // Test for [System.countShipsWithRole("pirate-cove") == 0] because the populater might already have added them as rock hermit replacement.
    if (!system.isInterstellarSpace && system.countShipsWithRole("pirate-cove") === 0 && !system.sun.hasGoneNova)
    {
		var isDead = this.pirateCoveSystems[system.ID];

		if (isDead == undefined || (isDead && (isDead + 20 < clock.days)))
		{
			this.$initialiseSystem();
        }
		
		if (!this.pirateCoveSystems[system.ID])
		{
			this.$addRockHermit();
		}
	}
};

this.$initialiseSystem = function ()
{
    // initialise
    if (system.countShipsWithPrimaryRole("pirate") > 9)
    {
        this.pirateCoveSystems[system.ID] = false; // allow stations untill killed.
    }
    else
    {
        this.pirateCoveSystems[system.ID] = clock.days; // don't allow a station for the next 20 days.
    }
}


this.$addRockHermit = function ()
{
    var random = this.$random(); // use a 'fixed' random to make it predictable by system.
    var coordinateSystem =  (random< 0.1) ? "ps" : "wp";
    var station = system.addShipsToRoute("rockhermit", 1, 0.10+random*0.3, coordinateSystem)[0];
    station.orientation = [1,0,0,0]; // orientate it along the z-axis like oolite hermits.
    var asteroidCount = Math.ceil(3 + random*8);
    system.addShips("asteroid", asteroidCount, station.position, 15000);
    if (station.scanClass == "CLASS_POLICE") return; // e.g. the astromine from commies.oxp, that should not be changed.
    station.setAI("pirateCoveAI.plist");
    station.setScript("pirateCoveRock.js");
    station.hasNPCTraffic = false; // we don't want trader launches. Happens otherwise by default on rotating hermits.
    station.script.defenderCount = this.basicDefenders + Math.floor(Math.random()*3);
    if (station.scanClass == "CLASS_NEUTRAL")
    {
    	// not all hermits have a scanclass defined.
    	if (0 >= oolite.compareVersion("1.77"))
    	{
    		station.scanClass = "CLASS_ROCK";
    	}
    	else
    	{
    		// scanClass is read-only in older Oolite versions.
    		station.scannerDisplayColor1 = "whiteColor"; 
    	}
    }
};

this.$random = function ()
{
    // return mostly the same value, but change over time.
    var salt = (clock.days & 0xE0) + 15; // change once every 32 days
    return system.scrambledPseudoRandomNumber(salt);
};
Scripts/pirateCoveRock.js
"use strict";
this.name        = "Pirate Cove Rock"; 
this.author      = "eric walch"; 
this.description = "Script for the Pirate_Cove Rock by Lazy Gun"; 
this.version     = "1.4.2"; 


this.defenderCount = 6;  // defenderCount is redefined by the main script.

this.shipSpawned = function ()
{
    this.ship.primaryRole = "pirate-cove"; // needed to set the market correct.
    this.maxAirbornDefenders = 3 + Math.floor(Math.random() * 4);
    if (player.score > 512) this.maxAirbornDefenders++;
    if (player.score > 6400) this.maxAirbornDefenders++;
}

// Correct clean hits.
this.shipBeingAttacked = function (attacker)
{
    if (attacker && attacker.owner === this.ship && attacker.target === this.ship)
	{
		attacker.reactToAIMessage("TARGET_LOST");
		log(this.name, "Pirate cove was friendly hit by: " + attacker.displayName);
	}
}


this.stationLaunchedShip = function (ship)
{
    if (ship.primaryRole === "defense_ship") ship.switchAI("pirateCovePirateAI.plist");
	if (ship.primaryRole === "scavenger"  && !ship.bounty) ship.bounty = 5 + Math.random() * 25;
	if (ship.primaryRole === "escort"  && !ship.bounty) ship.bounty = 5 + Math.random() * 15;
}

this.otherShipDocked = function (ship)
{
    if (ship.isPlayer) this.ship.displayName = "Pirate Cove"; // we are spotted!
    if (ship.primaryRole == "pirate") this.defenderCount++;
}

/*
In addition to the below launched pirates, the AI can also launch pirates as defense ships
when directly attacked.
*/
this.$launchDefender = function ()
{
    if (this.defenderCount > 0 && this.ship.target
             && this.ship.position.distanceTo(this.ship.target.position) < 15000
             && this.ship.group.count < this.maxAirbornDefenders)
    {
        var defender = this.ship.launchShipWithRole("pirate");
        if (defender)
        {
            defender.switchAI("pirateCovePirateAI.plist");
            defender.target = this.ship.target;
            this.ship.group.addShip(defender);
            defender.group = this.ship.group;
            if (!this.ship.bounty && this.ship.target.isPlayer)
            {
            	 this.ship.bounty = (this.ship.scanClass == "CLASS_NEUTRAL") ? 100: 1000; // the cove is no longer clean now.
            }
            this.defenderCount--;
        }
    }
};

this.shipDied = function ()
{
	// store the time of death
	worldScripts.Pirate_Coves.pirateCoveSystems[system.ID] = clock.days;	
};