Same.Diziet Sma wrote:I've had it do this trying to "repair" a ship's cat..
Led me to remove the cats from my game. I'm not wasting time and 'bots on a non-essential item, and to me not worth the hassle to fix locally.
Moderators: winston, another_commander
Same.Diziet Sma wrote:I've had it do this trying to "repair" a ship's cat..
Code: Select all
"use strict";
this.name = "Repair Bots";
this.author = "Thargoid,Lone_Wolf";
this.copyright = "Creative Commons Attribution - Non-Commercial - Share Alike 3.0 license with clauses - see readme.txt.";
this.description = "main repairbots script";
this.version = "3.0.0";
this._rb_repair_list = [];
// list of items to be repaired
this._rb_chances = [];
// 2-dimensional arry, repair chance for all known equipment items
this._rb_speedup = 1;
// higher setting will make repairs go faster
this._rb_bot_status = 0;
// 0 : bots offline
// 1 : busy repairing
// 2 : repair success
// 3 : repair failed
this._rb_item_under_repair = { eq:"none", reptime:0, chance:0 }
this.startUpComplete = function()
{
if ( !missionVariables.repairCounter ) { missionVariables.repairCounter = 0; }
this._rb_bot_status = ( missionVariables === 0 ) ? 0 : 1;
this._rb_initialise_repair_chances;
this._rb_check_systems;
};
this._rb_repair_control = function()
{
/*
called when :
ship exits hyperspace
ship launches from dock
repair timer has finished one repair attempt
equipmentDamaged
equipmentRepaired
*/
// bots don't work while docked or in hyperspace , should never happen
if ( player.ship.status !== "STATUS_IN_FLIGHT" ) { return;};
// offline bots can't do repairs
if ( this._rb_bot_status === 0 ) { return; };
// are we already repairing something ?
if ( this._rb_bot_status === 1 ) { return; };
// is there something to repair ?
if ( this._rb_repair_list.length === 0 ) { return; };
// do we have repair charges available ?
if ( missionVariables.repairCounter === 0 )
{ this._rb_bot_status = 0;
player.consoleMessage("Repair System offline - out of nanobots", 6 );
return;
};
if ( this._rb_repair_item_timer )
{
this._rb_repair_item_timer.stop();
delete this._rb_repair_item_timer;
};
this._rb_bot_status = 1;
missionVariables.repairCounter -= 1;
this._rb_item_under_repair.eq = this._rb_select_item();
this._rb_item_under_repair.reptime = this._rb_calc_reptime(this._rb_item_under_repair.eq);
this._rb_item_under_repair.chance = this._rb_calc_chance(this._rb_item_under_repair.eq);
this._rb_repair_item_timer = new Timer(this, this._rb_repair_item, this._rb_item_under_repair.reptime, -1);
};
this._rb_repair_item = function()
{
var eq = this._rb-item_under_repair.eq
if ( Math.random() < this._rb_item_under_repair.chance )
{
// repair succesfull
// remove item from list
this._rb_repair_list.splice(this._rb_repair_list.indexOf( eq ), 1)
this._rb_bot_status = 2;
player.consoleMessage( EquipmentInfo.infoForKey(eq).name + " online and operational.", 5 );
this._rb_fix_item( eq );
}
else
{
// repair failed
this._rb_bot_status = 3;
player.consoleMessage( EquipmentInfo.infoForKey(eq).name + " repair attempt failed - work continuing.", 5 );
};
this._rb_repair_control;
};
this._rb_fix_item = function(eq)
{
player.ship.setEquipmentStatus(eq,"EQUIPMENT_OK"); // actually fix the thing!
// deal with specific OXP equipment which need rebooting after fixing, or have other issues.
switch ( eq )
{
case "EQ_FRAME_FUEL_COLLECTOR":
worldScripts["Fuel Collector"].shipLaunchedFromStation(); // restart the timers in it's world script
break;
case "EQ_FRAME_BOUNTY_SCANNER":
worldScripts["Bounty Scanner"].shipLaunchedFromStation(); // restart the timers in it's world script
break;
case "EQ_EEU":
worldScripts["Emergency Energy Unit"].shipLaunchedFromStation(); // restart the timers in it's world script
break;
case "EQ_ROCKHERMIT_SCANNER"
worldScripts["rockHermit_Locator"].shipLaunchedFromStation() // use the inbuild scripting of the OXP to restart it.
break;
default:
break;
};
};
this._rb_initialise_repair_chances = function()
{
var eq_info = equipmentInfo.allEquipment;
for ( list_counter =0; list_counter<eq_info.length; list_counter++ )
{
var chance = -1;
if ( eq_info[list_counter].damageProbability === 0 )
{
// invulnerable equipment will never need repairs
chance = 0;
}
else
{
var rb_chance = eq_info[list_counter].scriptInfo.thargoidRepairBotChance;
if ( rb_chance !== undefined && !isNaN(rb_chance) )
{
chance = ( rb_chance < 0 ) ? 0 : rb_chance;
}
else
{
// no usable thargoidRepairBotChance set
chance = this._rb_calc_chance( eq_info[list_counter].effectiveTechLevel );
};
};
this._rb_chances.[eq_info[list_counter].equipmentKey] = chance;
};
};
this._rb_calc_chance = function(tech_level)
{
if ( tech_level < 9 ) { return 1; };
if ( tech_level > 8 && tech_level < 17 ) { return 1 - ( (tech_level - 8)/10 ); };
if ( tech_level < 99 ) { return 0.2; };
return 0.1;
};
this._rb_checkSystems = function()
{
// called when game is loaded
this._rb_repair_list = [];
var equipment = player.ship.equipment;
for ( listCounter = 0; listCounter<equipment.length; listCounter++ )
{
// if it's broke and fixable, add it to the list.
var eq = equipment[listCounter].equipmentKey;
if ( this._rb_is_fixable(eq) )
{
this._rb_repair_list.push( { eq, this._rb_chances[eq] } );
};
};
};
this._rb_is_fixable = function(eq)
{
// returns true if eq is broken & fixable, otherwise false
var fixable = false;
if ( player.ship.equipmentStatus(eq) === "EQUIPMENT_DAMAGED" && this._rb_chances[eq] > 0 )
{ fixable = true;};
return fixable;
};
this._rb_select_item = function()
{
// returns key for equipment to be repaired
var eq="";
var base = 0;
var rnd_fac = 0;
if ( this._rb_repair_list.indexOf("EQ_REPAIRBOTS_CONTROLLER") !== -1 )
{
// RB controller damaged,fix first
eq = "EQ_REPAIRBOTS_CONTROLLER";
base = 60; rnd_fac = 120;
}
else
{
// RB controller is fine, select a random item
// in future versions choice made based on FIFO,LIFO or priority may be also possible here
index = Math.floor( Math.random() * this._rb_repair_list.length );
eq = this._rb__rb_repair_list[index];
base = 120; rnd_fac = 180;
};
this._rb_item_under_repair.eq = eq
this._rb_item_under_repair.reptime = this._rb_calc_reptime( base, rnd_fac );
this._rb_item_under_repair.chance = this._rb_calc_chance( eq );
return eq;
};
this._rb_calc_reptime = function(base,rnd_fac)
{
// returns repairtime in seconds
var reptime = base + Math.ceil(Math.random() * rnd_fac);
reptime = Math.ceil( reptime / this._rb_speedUp );
return reptime;
};