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

Expansion Subentity Missiles for Griff Cobra MkIII

Content

Manifest

from Expansion Manager's OXP list from Expansion Manifest
Description Subentity Missiles for NPC Cobra Mk III. Requires a video card capable of supporting Oolite Shaders. Subentity Missiles for NPC Cobra Mk III. Requires a video card capable of supporting Oolite Shaders.
Identifier oolite.oxp.Griff.Cobra_MkIII.SubentMissiles oolite.oxp.Griff.Cobra_MkIII.SubentMissiles
Title Subentity Missiles for Griff Cobra MkIII Subentity Missiles for Griff Cobra MkIII
Category Retextures Retextures
Author Griff Griff
Version 1.02 1.02
Tags
Required Oolite Version
Maximum Oolite Version
Required Expansions
  • oolite.oxp.Griff.Cobra_MkIII:1.04.3
  • oolite.oxp.Griff.Missiles:1.02.1
  • oolite.oxp.Griff_alloys_and_wreckage:1.0
  • oolite.oxp.Griff.Cobra_MkIII:1.04.3
  • oolite.oxp.Griff.Missiles:1.02.1
  • oolite.oxp.Griff_alloys_and_wreckage:1.0
  • Optional Expansions
    Conflict Expansions
    Information URL http://wiki.alioth.net/index.php/Griff_Industries n/a
    Download URL https://wiki.alioth.net/img_auth.php/b/bd/Oolite.oxp.Griff.Cobra_MkIII.SubentMissiles.oxz n/a
    License CC-BY-NC-SA 4.0 CC-BY-NC-SA 4.0
    File Size n/a
    Upload date 1610873455

    Documentation

    Also read http://wiki.alioth.net/index.php/Subentity%20Missiles%20for%20Griff%20Cobra%20MkIII

    Equipment

    This expansion declares no equipment.

    Ships

    This expansion declares no ships.

    Models

    This expansion declares no models.

    Scripts

    Path
    Scripts/griff_cobra_III_externalMissiles.js
    "use strict";
    this.name				= "griff_cobra_III_(alt)_externalMissiles.js";
    this.author				= "Thargoid";
    this.copyright			= "Creative Commons: attribution, non-commercial, sharealike.";
    this.description		= "Generic external missile launching script";
    this.version			= "1.01";
    
    this.shipSpawned = function()
    	{ // just to ensure ship is fully loaded with selected missile type and nothing else
    	if(this.ship.scriptInfo.missileRole) // missileRole should be defined in shipdata.plist
    		{ this.missileRole = this.ship.scriptInfo.missileRole; }
    	else
    		{ this.missileRole = "EQ_MISSILE"; } // default to standard missile if not
        
        if (this.ship.scriptInfo.initialMissiles)
            {this.initialMissiles = parseInt(this.ship.scriptInfo.initialMissiles);}
        else
            {this.initialMissiles = this.ship.missileCapacity;};
        
    	if (this.ship.missiles.length > 0) this.ship.awardEquipment("EQ_MISSILE_REMOVAL"); // remove all spawning missiles and restock with selected ones.
    	var addCounter = 0; 
    	for(addCounter = 0; addCounter < this.initialMissiles;addCounter++)
    		{ this.ship.awardEquipment(this.missileRole); }
    	}
    
    this.shipFiredMissile = function(missile, target)
    	{
    	if(!this.ship.subEntities || this.ship.subEntities.length === 0) {return}; // if we've run out of sub-ents before we run out of missiles
    	
    	var subCounter = this.ship.subEntities.length - 1; // Set counter to number of sub-ents minus 1 (as entity array goes up from zero)
    	for(subCounter = this.ship.subEntities.length - 1;subCounter>=0;subCounter--)
    		{
    		if(this.ship.subEntities[subCounter].hasRole(missile.primaryRole)) // if the sub-ent is the same as the missile being fired
    			{
    			missile.position = this.localToGlobal(this.ship.subEntities[subCounter].position); // move the fired missile to the sub-ent position
    			missile.orientation = this.ship.subEntities[subCounter].orientation.multiply(this.ship.orientation); // point the missile in the right direction
    			missile.desiredSpeed = missile.maxSpeed;
    			this.ship.subEntities[subCounter].remove(); // remove the sub-ent version of the missile
    			break; // come out of the loop, as we've done our swap
    			}
    		}
    	}
    
    this.localToGlobal = function(position)
    	{ // sub-ent position is relative to mother, but for swapping we need the absolute global position
    	let orientation = this.ship.orientation;
    	return this.ship.position.add(position.rotateBy(orientation));
    	}
    
    this.shipTakingDamage = function(amount, fromEntity, damageType)
    	{
    	if(this.ship.missiles.length === 0 && this.ship.subEntities.length === 0) // if we're all out of missiles and any sub-entities, bail out.
    		{ return; }
    	
    	this.missileSubs = 0;
    	var subCounter = this.ship.subEntities.length - 1; // Set counter to number of sub-ents minus 1 (as entity array goes up from zero)
    	for(subCounter = this.ship.subEntities.length - 1;subCounter>=0;subCounter--)
    		{
    		if(this.ship.subEntities[subCounter].hasRole(this.missileRole)) // if the sub-ent is a missile, count it
    			{ this.missileSubs++; }
    		}
    	
    	if(this.missileSubs === 0 && this.ship.subEntities.length === 0) // if we're all out of missiles and missile sub-entities, bail out.
    		{ return; }
    	
    	if(this.missileSubs < this.ship.missiles.length) // if we've got more missiles than sub-entity missiles
    		{
    		this.ship.awardEquipment("EQ_MISSILE_REMOVAL"); // get rid of all missiles
    		if(this.missileSubs > 0)
    			{
    			var missileCounter = 0; 
    			for(missileCounter = 0;missileCounter<this.missileSubs;missileCounter++) // restock with the correct number of selected missile
    				{ this.ship.awardEquipment(this.missileRole); }
    			}
    		return;	
    		}
    		
    	if(this.missileSubs > this.ship.missiles.length) // if we've got less missiles than sub-entity missiles
    		{
    		this.difference = this.missileSubs - this.ship.missiles.length;
    		var removeCounter = 0; 
    		for(removeCounter = 0;removeCounter<this.difference;removeCounter++) // loop through however many subs we need to remove
    				{
    				var subCounter = this.ship.subEntities.length - 1; // Set counter to number of sub-ents minus 1 (as entity array goes up from zero)
    				for(subCounter = this.ship.subEntities.length - 1;subCounter>=0;subCounter--)
    					{
    					if(this.ship.subEntities[subCounter].hasRole(this.missileRole)) // if the sub-ent is a missile, remove it
    						{ 
    						this.ship.subEntities[subCounter].remove(); 
    						break;
    						}
    					}
    				}
    		return;		
    		}	
    	}
    	
    this.shipDied = function() // event that occurs when the entity (ship) whose script this is dies
    	{
    
    	if(!this.ship || (player.ship.isValid && this.ship.position.distanceTo(player.ship.position) > 50000)) return; // exit the script if the explosion happens far from the player
    
     		this.largeCount = (Math.ceil(Math.random() * 4)); // between 0-4 pieces of wreckage
    		this.tinyCount =  (Math.ceil(Math.random() * 10) + 5); // between 5-10 tiny spark fragments
    		this.sparkCount =  (Math.ceil(Math.random() * 20) + 10); // between 10-20 spin spark fragments
    		this.ship.spawn("griffspark", this.tinyCount); // spawn the tiny spark fragments
    
    
    	if(this.largeCount > 0) // if there is large wreckage
    		{
    		this.ship.spawn("griffwreckage", this.largeCount); // spawn the larger wreckage
    		this.ship.spawn("spinspark", this.sparkCount); // spawn the spin sparks
    
    		}
    
    	}