Page 9 of 9

Re: RepairBots OXP

Posted: Fri Oct 24, 2014 4:26 am
by CheeseRedux
Diziet Sma wrote:
I've had it do this trying to "repair" a ship's cat..
Same.
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.

Re: RepairBots OXP

Posted: Fri Oct 24, 2014 4:34 am
by vsfc
Well, my thinking on this one is, once equipment gets broken one of the recharges is used. It does take a time to fix equipment and you may dock before it gets fixed. When you leave a station another recharge is used and this happens every time you leave station with broken equipment even though it is already used recharge before. Should we have some life time timeout before the next one is used or well what is the nature of these bots? (They die / run away when airlock is opened on the station? :lol: )

You are right Dizzi, I do bite a bullet occasionally.

Re: RepairBots OXP

Posted: Fri Oct 24, 2014 4:58 am
by CheeseRedux
But why are you repeatedly launching and docking? Apart from experiments or other special circumstances, I launch for one of two reasons: To go to a different system, or a different station in-system. Both of these usually mean plenty of time for the 'bots to do their thing. On the occasions they are working on something when I arrive at my destination, my standard response is to loiter until they are done.

A timeout might seem like a good idea when you are in the station aegis, but you do not want the 'bots on a coffee break in the middle of a battle with essential equipment down.
A possible solution could be a half-off switch; Tell the system to finish what it is working on, but not start any new repairs. Would ideally have to be switchable both in flight and when docked.
I am not sure how much demand there would be for such a thing though, and at any rate nothing is likely to happen until the OXP finds a new maintainer.

Re: RepairBots OXP

Posted: Fri Oct 24, 2014 7:21 pm
by Lone_Wolf
A repair charge is subtracted everytime a repair starts.

Upon docking, repairbots is stopped. any ongoing repair is cancelled then, so that charge is gone.

If there's still equipment damaged after launch, a new repair is started > needs a repaircharge.

Best solution is to wait with docking until everything is repaired, or pay for the repair when docked.

Re: RepairBots OXP

Posted: Tue Jun 02, 2015 1:54 pm
by Lone_Wolf
I've always found repair bots are slow in fixing repairs and looked into speeding it up.

repairtime = base + Math.ceil(Math.random() * rnd_fac);
repair bots itself : base =60, rnd_fac =120 . repairtime is between 60 and 180 seconds
other equipment : base = 120, rnd_fac = 180 > repairtime between 120 and 300 seconds

I'm currently thinking about having 4 types of recharges for next version :
basic : same as now

Standard : speed * 2 , price * 3
times : 30 - 90 & 60 - 150

Advanced : speed * 3 , price * 6
times : 20 - 60 & 40 - 100

Military grade : speed * 6, price * 10
times : 10 - 30 & 20 - 50

Comment on this idea please.

Re: RepairBots OXP

Posted: Tue Jun 02, 2015 4:55 pm
by Day
I'm still in the stage where money is scarce: fully equipped ship, and between 20.000 and 100.000 credits.
Bought a slow freighter, I'm constantly followed and hit by ne'er-do-wells.

I love the auto-repair bots and this proposition would make the period where I struggle for money longer. I'm all for it :-)

Re: RepairBots OXP

Posted: Sat Feb 20, 2016 10:13 pm
by Lone_Wolf
After looking thoroughly into RB code I decided a redesign of RB is needed to get rid of the timers .
The new design is almost completely event-driven and will allow the different rechargetypes mentioned earlier .
For now it will continue to use the "RB controller first,random selected device otherwise" policy but does allow other selection mechanisms like FIFO, LIFO and priority-based .

The code below should give an idea how i want to implement things.

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;
  };