OGame Automizer Development Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Welcome on the OGame Automizer Development/Support Forum

If this is your first visit, be sure to check out the
http://ogameautomizer.com/doc/manual.html : A guide written by OA users with consultation of OA author (En)

http://ogameautomizer.com/doc/manual_de.html : A guide written by OA users with consultation of OA author (Benutzerschnittstellenhandbuch) (GE)

http://ogameautomizer.com/doc/scripting_manual.html : OA Scripting Manual (En)

Pages: [1] 2 3

Author Topic: Ressource Saver V0.2 06/17/2013  (Read 8888 times)

0 Members and 1 Guest are viewing this topic.

treibsand

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 56
    • View Profile
Ressource Saver V0.2 06/17/2013
« on: May 06, 2013, 12:03:15 PM »

If your defense is well developed and you want to just save your resources to a certain date, this script might help.
Because the script is still under development, for debugging purpose it is very verbosely...

Mainfeatures:
- find target to save on with slowest speed (to save deuterium)
- find debris on or near target
- send fleet in configurable composition (e.g. with or without RIP)
- in most cases the script will find a goal within only a few seconds or minutes away from the target time.
- provides detailed logfile

Maybe dateDiffSec() fails in other timezones. Is there a more reliable method to calculate the time difference?

Version 0.1, 05/06/2013:

Version 0.2, 06/17/2013:
  • Optimizing log-output
  • Added fullSave-option to save all ships and all ressources
  • Localizing number-format
  • Optimized search for debris. Now alternating planet-system by 0,+1,-1,+2,-2,+3,-3 etc. Larger scope possible.
  • Added configurable prompt to confirm fleetsave
  • Fleet-composer now takes minimum of given fleet-definition and available ships-count
  • RIP now counts as (xxl)-transporter  ;)

Code: [Select]
pauseScriptWhenOADisabled();
Locale loc = new Locale("en", "UK");  //change "en" and "UK" to "de" and "DE" for example to get other number formats.
@ImportsDefinitionStart
import java.text.NumberFormat
@ImportsDefinitionEnd
NumberFormat nf = NumberFormat.getInstance(loc);
//-------------- CONFIGURATION BY USER -----------------------------------------------
boolean fullSave = false; // !!!
def savePoint = "06/18/2013 08:00:00"; // "04/29/2013 10:00:00";
def planetNames = ["Colony1"]; // ["Colony1","Colony2","aso","Moonname","Moon2","otherMoon"]
int minRessources = 1E6; // Cause of easier reading... Don't know how many nulls this are: 10000000000!
int tolerance = 900; // Seconds deviation by finding savePoint
def sendTolerance = 100; // % deviation on debris-search
int remainingDeut = 250000;
boolean confirm = true; // With 'false' I don't ask for confirmation.
//-------------- END CONFIG ----------------------------------------------------------
int targetTime = 0;
int tmpTime = 9999999;
int tmpSpeed = 100;
int tmp = 0;
int diff = 0;
def targetPlanet;
def level = 0;
int lcs;
def target = null;
int i = 0;
def answ = null;
def errorMsg = "";
def logFile = "logRessourceSave.txt"
writeFile logFile, "";

def fleet = [
  DEATHSTAR : 1,
  BATTLESHIP : 0,
  BATTLECRUISER : 0,
  RECYCLER : 1,
  ESPIONAGEPROBE : 0,
  LIGHTFIGHTER : 0,
  HEAVYFIGHTER : 0,
  SMALLCARGO : 0,
  LARGECARGO : 0
]; // ensure, that LC is on last place in list! Easiest way to ensure, that RIPs also transport Ressources.

//-------------- BEGIN FUNCTION dateDiffSec() -------------------------------------------
def dateDiffSec = { time ->
  def now = new Date();
  return (Date.parse(time)-Date.parse(now.toGMTString()))
}
//-------------- END FUNCTION dateDiffSec -----------------------------------------------
//-------------- BEGIN FUNCTION log(errorMsg) -------------------------------------------
def log = { logMsg, console ->
  if(console) printOut logMsg;
  appendToFile logFile, Time.getTime()+" | "+logMsg+"\r\n";
}
//-------------- END FUNCTION log -------------------------------------------------------
//-------------- BEGIN FUNCTION findDebris ----------------------------------------------
def findDebris = {galaxy, system, planet, l ->
  String sql;
  switch (l) {
    case 1:
    case 2:
      startSyncGalaxyScan(galaxy, system);
      sql = "SELECT * FROM PLANET WHERE Galaxy = "+galaxy+" AND System = "+system+" AND Planet = "+planet+" AND IsMoon = 0";
    break;
    case 3:
      startSyncGalaxyScan(galaxy, system);
      sql = "SELECT * FROM PLANET WHERE Galaxy = "+galaxy+" AND System = "+system+" AND IsMoon = 0";
    break;
    case 4:
      for(sys in 1..20) {
        startSyncGalaxyScan(galaxy, sys);
      }
      sql = "SELECT * FROM PLANET WHERE Galaxy = "+galaxy+" AND (System >= 1 AND System <= 20) AND IsMoon = 0";
    break;
  }
  Connection conn = getDBConn();
  Statement statement = conn.createStatement();
  ResultSet result = statement.executeQuery(sql);
  while(result.next()) {
    if(result.getInt("DebrisMetal")+result.getInt("DebrisCrystal") > 0) {
      debris = new Coordinates(result.getInt("Galaxy"),result.getInt("System"),result.getInt("Planet"),Coordinates.DEBRIS_TYPE);
      log("Debris found on "+debris+", M: "+nf.format(result.getInt("DebrisMetal"))+", C: "+nf.format(result.getInt("DebrisCrystal")), true);
      break;
    } else debris = null;
  }
  statement.close();
  result.close();
  closeDBConn(conn);
  return debris;
}
//-------------- END FUNCTION findDebris() -----------------------------------------------

//-------------- MAIN ROUTINE -----------------------------------------------
log("-------------------------------------- Start RessourceSave --------------------------------------", true);
log("Minimum Ressources: "+nf.format(minRessources), true);
for(sourcePlanet in planetNames) {
// --- Initialising variables ---
  int M = 0;
  int C = 0;
  int D = 0;
  int totalRes = 0;
  answ = null;
  errorMsg = null;
// --- Go on with next/first/once Planet/Moon ---
  Planet p = getPlanet(sourcePlanet);
  updatePlanet(p);
  M = p.getMetal()+p.getMetalDelta();
  C = p.getCrystal()+p.getCrystalDelta();
  D = p.getDeuterium()+p.getDeuteriumDelta()-remainingDeut;
  totalRes = M+C+D;
  lcs = Math.ceil(totalRes/25000);
  plcs = getNumberOf('LARGECARGO', p);
  log("Planet: "+p+"\tRessources: "+nf.format(totalRes)+"\tTransports avail: "+nf.format(plcs)+"(needed: "+nf.format(lcs), true);
  if((plcs > 0) && (totalRes > minRessources) && (D > 0)) {
    // Compose fleet
    def iter = fleet.keySet().iterator();
    while(iter.hasNext()) {
      String key = iter.next();
      if(key=='DEATHSTAR') {
        fleet[key] = Math.min(getNumberOf(key, p), fleet[key]);
        prip = fleet[key];
        lcs = lcs-(40*prip);
      }
      if(key=='RECYCLER') fleet[key] = Math.min(fleet[key], getNumberOf(key, p));
      if(key=='LARGECARGO') fleet[key] = Math.max(Math.min(lcs, plcs),fleet[key]);
    }
    // End composing fleet
    if(plcs<lcs) {
      def quote = Math.ceil(lcs/plcs*1000)/1000;
      log("Take only proportionate ressources of "+(Math.round(100/quote))+"% ("+quote+")! "+nf.format(lcs)+" LC needed, "+nf.format(plcs)+" LC available.", true);
      M=Math.floor(M/quote);
      C=Math.floor(C/quote);
      D=Math.floor(D/quote);
      log("Total Res: "+nf.format(totalRes)+". Transportable Res: "+nf.format(M+C+D), true);
    }

    targetTime = dateDiffSec(savePoint)/2000;
    if(targetTime > 0) {
      def now = new Date();
      def zeit = new Date();
      zeit.setTime(Date.parse(savePoint));
      log("Start:\t\t"+now.toLocaleString()+" \t("+nf.format(Date.parse(now.toGMTString()))+" ms)", true);
      log("SavePoint:     \t"+zeit.toLocaleString()+" \t("+nf.format(Date.parse(savePoint))+" ms)", true);
      log("Differenz in Std:\t(2way)\t"+Math.round((dateDiffSec(savePoint))/36000)/100+"\t\t("+nf.format((int)(dateDiffSec(savePoint)))+" ms)", true);
      log("TripDuration:\t(2way)\t"+nf.format((dateDiffSec(savePoint))/1000), true);
      log("Calculating best savePoint...", true);
      for(speed = 100;speed >= 10; speed -= 10) {
        tmp = getTripDuration(p, p.coordinates.toString()+" Debris", speed, fleet);
        diff = Math.abs(tmp - targetTime);
        if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && (diff < tmpTime) && (speed <= tmpSpeed)) {
          tmpTime = diff;
          tmpSpeed = speed;
          level = 1;
          targetPlanet = new Coordinates((byte)p.coordinates.galaxy,(short)p.coordinates.system,(byte)p.coordinates.planet,Coordinates.DEBRIS_TYPE);
          log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
        }
        for(planet in 1..15) {
          tmp = getTripDuration(p, "["+p.coordinates.galaxy+":"+p.coordinates.system+":"+planet+"]", speed, fleet);
          diff = Math.abs(tmp - targetTime);
          if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {
            tmpTime = diff;
            tmpSpeed = speed;
            level = 2;
            targetPlanet = new Coordinates((byte)p.coordinates.galaxy,(short)p.coordinates.system,(byte)planet,Coordinates.PLANET_TYPE);
            log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
          }
        }
        for(sys in 1..499) {
          tmp = getTripDuration(p, "["+p.coordinates.galaxy+":"+sys+":1]", speed, fleet);
          diff = Math.abs(tmp - targetTime);
          if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && (diff < tmpTime) && (speed <= tmpSpeed)) {
            tmpTime = diff;
            tmpSpeed = speed;
            level = 3;
            targetPlanet = new Coordinates((byte)p.coordinates.galaxy,(short)sys,(byte)1,Coordinates.PLANET_TYPE);
            log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
          }
        }
        for(gala in 1..12) {
          tmp = getTripDuration(p, "["+gala+":1:1]", speed, fleet);
          diff = Math.abs(tmp - targetTime);
          if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && (diff < tmpTime) && (speed <= tmpSpeed)) {
            tmpTime = diff;
            tmpSpeed = speed;
            level = 4;
            targetPlanet = new Coordinates((byte)gala,(short)1,(byte)1,Coordinates.PLANET_TYPE);
            log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
          }
        }
      }
      log("Best savePoint: "+nf.format(tmpTime)+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, true);
      log("Difference ("+nf.format(tmpTime)+") / Tolerance ("+nf.format(tolerance)+") / Level ("+level+")\r\n", true);
      if(tmpTime <= tolerance) {
        log("Fleet:   \t"+(fleet.toString().replace(",","\r\n\t\t")).replace(":","      \t")+"\r\n\r\n"+
          "targetPlanet:\t\t"+targetPlanet+"\r\n"+
          "Calc-TripTime (1-way):\t"+Math.round(dateDiffSec(savePoint)/2000)+"\r\n"+
          "getTripDuration:\t\t"+nf.format(getTripDuration(p, targetPlanet, tmpSpeed, fleet))+"\r\n"+
          "Consumption from \t"+p+" to "+targetPlanet+" = "+nf.format(getTripConsumption(p, targetPlanet, tmpSpeed, fleet))+"\r\n"+
          "Level: "+level+"\t\tTarget-area for search debris: "+targetPlanet.galaxy+
          ":"+targetPlanet.system+
          ":"+targetPlanet.planet+
          "\tSmalest difference: "+nf.format(tmpTime), true);
        if(level == 1){
          target = targetPlanet;
          log("Level = "+level+" so Target = "+targetPlanet+
            "\tTripDuration:\t"+nf.format(getTripDuration(p, targetPlanet, tmpSpeed, fleet)), true);
        }
        target = null;
        i = 0;
        while(!target && i>-5 && i<5){
          log("Scanning system: "+targetPlanet.galaxy+":"+(targetPlanet.system+i), true);
          target = findDebris(targetPlanet.galaxy, (targetPlanet.system+i), targetPlanet.planet, level);
          if(i>=0) i++;
          i=i*-1
        }
        answ = null;
        errorMsg = null;
        if(!target) {
          errorMsg = "No suitable debris-field found. Please save manually!"
        } else {
          log("SmalestDifference: "+tmpTime+"\tRealDifference: "+Math.abs(getTripDuration(p, target, tmpSpeed, fleet)-targetTime)+
              "\tSendTolerance: "+(tolerance*(1+(sendTolerance/100))), true);
          if((tmpTime > tolerance) || ((target?Math.abs(getTripDuration(p, target, tmpSpeed, fleet)-targetTime):9999999) > (tolerance*(1+(sendTolerance/100))))) {
            errorMsg = "Trip-duration exceeds tolerance. Choose another savepoint or change tolerance ("+
                        nf.format(tmpTime)+"/"+nf.format(Math.abs(getTripDuration(p, target, tmpSpeed, fleet)-targetTime))+" vs "+nf.format(tolerance)+")!";
            zeit.setTime(now.getTime()+(getTripDuration(p, target, tmpSpeed, fleet)*2000));
            log("Returntime: "+zeit.toLocaleString(), true);
            if(confirm) {
              answ = getInput("ATTENTION!!!\r\n\r\n"+
                            "Returntime exceeds tolerance!!!\r\n"+
                            "Returntime: "+zeit.toLocaleString()+"\r\n"+
                            "Speed: "+tmpSpeed+"\r\n"+
                            "Fuel: "+nf.format(getTripConsumption(p, target, tmpSpeed, fleet))+"\r\n\r\n"+
                            "Send yet? If OK type 'Y'. Otherwise I will abort.");
              if(answ == "Y") errorMsg = null;
            } else {
              answ = "Y";
              errorMsg = null;
            }
          }
        }
        if(errorMsg) {
          log(errorMsg, true);
        } else {
          log("Target: "+target+
              ",\tTripDuration: "+nf.format(getTripDuration(p, target, tmpSpeed, fleet))+
              ",\tTripConsumption: "+nf.format(getTripConsumption(p, target, tmpSpeed, fleet)), true);
          log("Ressources: "+nf.format(M+C+D)+" = "+nf.format(lcs)+" LargeCargo.", true);
          log("sendFleet("+p+", "+target+", "+tmpSpeed+", "+nf.format(M)+", "+nf.format(C)+", "+nf.format(D)+", (fleet see above)", true);
          zeit.setTime(now.getTime()+(getTripDuration(p, target, tmpSpeed, fleet)*2000));
          log("Returntime: "+zeit.toLocaleString(), true);
          if(confirm) {
            if(!answ) answ = getInput("Returntime: "+zeit.toLocaleString()+"\r\n"+
                                    "Speed: "+tmpSpeed+"\r\n"+
                                    "Fuel: "+nf.format(getTripConsumption(p, target, tmpSpeed, fleet))+"\r\n\r\n"+
                                    "If OK type 'Y'. Otherwise I will abort.");
          } else { answ = "Y" }
            if(answ == "Y") {
            sleep 10000;
            if(fullSave?sendFleetResourcesSelector(p,target,FleetMission.RECYCLE_MISSION,tmpSpeed,"DCM",[:]):sendFleetWithResources(p, target, FleetMission.RECYCLE_MISSION, tmpSpeed, M, C, D, fleet)) {
              log("---------------------------------------- Succesfull send ----------------------------------------\r\n", true);
            } else {
              log("-------------------------------------- Error while sending --------------------------------------\r\n", true);
            }
          } else {
            log("-------------------------------------- You decided to abort -------------------------------------\r\n", true);
          }
        }
      } else {
        log("---------- No target fits timeslot for "+p+". Please choose other savepoint! ----------\r\n", true);
      }
    } else {
      log("---------- Negative TripDuration from "+p+"! Please correct savePoint! ----------\r\n", true);
    }
  } else {
    log("---------- Less transporter / low ressources on "+p+". Giving up... ----------\r\n", true);
  }
}
« Last Edit: June 17, 2013, 10:51:26 AM by treibsand »
Logged

atx

  • Newbie
  • *
  • Offline Offline
  • Posts: 39
    • View Profile
Re: Ressource Saver V0.1 05/06/2013
« Reply #1 on: June 16, 2013, 12:06:10 PM »

Been searching for a script like that for a while.

The only thing i would like to know or be edited is:

1. I always save from moons to Debris. So how can i define a moon to your planetNames Variable ?
    Would def planetNames = "[6:666:6] Moon"; be correct ?

2. I would like to save all my ships instead of defining the correct amount everytime (alternates due to expeditions etc.)

Thanks for your reply :)

Regards
Logged

treibsand

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 56
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #2 on: June 17, 2013, 10:53:38 AM »

1. Give Moon a unique name and add it to the 'planetNames' (see example in code).
2. Use fleet-definition or option fullSave.
Have fun!
Logged

LittleCat

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 61
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #3 on: June 17, 2013, 10:04:15 PM »

2. Use fleet-definition or option fullSave.
Have fun!
Where in the code i can find fullSave option?
Its not defined.
Logged

atx

  • Newbie
  • *
  • Offline Offline
  • Posts: 39
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #4 on: June 18, 2013, 09:33:08 AM »

2. Use fleet-definition or option fullSave.
Have fun!
Where in the code i can find fullSave option?
Its not defined.

8th row. He updated the script for me <3
Logged

abhurrido

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 81
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #5 on: June 19, 2013, 01:10:37 AM »

btw, you can use OA's API to read the remaining deut left in each planet, so there is no need to manually do "remaianingDeut"
Logged

treibsand

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 56
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #6 on: June 19, 2013, 12:17:31 PM »

In case of saving ressources or do a 'fullSave', the "remainingDeut" maybe will differ from the value, setted on the Building-tab. If you prefer to set this value dependet on each planet, the API-call can be more efficient.
Easy to implement...
Logged

wulf3010

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 447
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #7 on: August 14, 2013, 11:22:52 AM »

is it possible to save full fleet excluding certain amount of ships like transporter. Meaning leaving 4k small cargos behind but saving everything. Same goes for deut, saving everything exept example 1 million deut.

so in result same thing full save, expect defined amount of cargo and deut. Something need to stay for the incoming ress!
Logged

Death

  • Newbie
  • *
  • Offline Offline
  • Posts: 38
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #8 on: August 14, 2013, 06:26:02 PM »

come on!!!

do you read the config of the scripft before you are posting?

at the top of the scripft you can find a row with :"int remainingDeut = 250000;"... means that 250.000 are left over at the planet, after using this scripft

if ive seen correctly, LCs just will be used for transporting, if you choose "full fleet save = true",
Logged

wulf3010

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 447
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #9 on: August 15, 2013, 10:41:04 AM »

@death, iam not good in scripting, i dont know that and i dont see that.

perhaps, i saw the information you told, but what happend if i want the FS, leaving 1 million deut and 10k sc behind. How to do it?
Logged

Death

  • Newbie
  • *
  • Offline Offline
  • Posts: 38
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #10 on: August 15, 2013, 10:01:40 PM »

Code: [Select]
//-------------- CONFIGURATION BY USER -----------------------------------------------
boolean fullSave = false; // false = only use of needed ships ; true = alle ships are saved
def savePoint = "06/18/2013 08:00:00"; // "04/29/2013 10:00:00";
def planetNames = ["Colony1"]; // ["Colony1","Colony2","aso","Moonname","Moon2","otherMoon"]
int minRessources = 1E6; // Cause of easier reading... Don't know how many nulls this are: 10000000000!
int tolerance = 900; // Seconds deviation by finding savePoint
def sendTolerance = 100; // % deviation on debris-search
int remainingDeut = 250000; // remaining Deut left behind
boolean confirm = true; // With 'false' I don't ask for confirmation.
//-------------- END CONFIG ----------------------------------------------------------
int targetTime = 0;
int tmpTime = 9999999;
int tmpSpeed = 100;
int tmp = 0;
int diff = 0;
def targetPlanet;
def level = 0;
int lcs;
def target = null;
int i = 0;
def answ = null;
def errorMsg = "";
def logFile = "logRessourceSave.txt"
writeFile logFile, "";

def fleet = [
  DEATHSTAR : 1,
  BATTLESHIP : 0,
  BATTLECRUISER : 0,
  RECYCLER : 1,
  ESPIONAGEPROBE : 0,
  LIGHTFIGHTER : 0,
  HEAVYFIGHTER : 0,
  SMALLCARGO : 0,
  LARGECARGO : 0
]; // ensure, that LC is on last place in list! Easiest way to ensure, that RIPs also transport Ressources.

//-------------- BEGIN FUNCTION dateDiffSec() -------------------------------------------
def dateDiffSec = { time ->
  def now = new Date();
  return (Date.parse(time)-Date.parse(now.toGMTString()))
}
//-------------- END FUNCTION dateDiffSec -----------------------------------------------
//-------------- BEGIN FUNCTION log(errorMsg) -------------------------------------------
def log = { logMsg, console ->
  if(console) printOut logMsg;
  appendToFile logFile, Time.getTime()+" | "+logMsg+"\r\n";
}
//-------------- END FUNCTION log -------------------------------------------------------
//-------------- BEGIN FUNCTION findDebris ----------------------------------------------
def findDebris = {galaxy, system, planet, l ->
  String sql;
  switch (l) {
    case 1:
    case 2:
      startSyncGalaxyScan(galaxy, system);
      sql = "SELECT * FROM PLANET WHERE Galaxy = "+galaxy+" AND System = "+system+" AND Planet = "+planet+" AND IsMoon = 0";
    break;
    case 3:
      startSyncGalaxyScan(galaxy, system);
      sql = "SELECT * FROM PLANET WHERE Galaxy = "+galaxy+" AND System = "+system+" AND IsMoon = 0";
    break;
    case 4:
      for(sys in 1..20) {
        startSyncGalaxyScan(galaxy, sys);
      }
      sql = "SELECT * FROM PLANET WHERE Galaxy = "+galaxy+" AND (System >= 1 AND System <= 20) AND IsMoon = 0";
    break;
  }
  Connection conn = getDBConn();
  Statement statement = conn.createStatement();
  ResultSet result = statement.executeQuery(sql);
  while(result.next()) {
    if(result.getInt("DebrisMetal")+result.getInt("DebrisCrystal") > 0) {
      debris = new Coordinates(result.getInt("Galaxy"),result.getInt("System"),result.getInt("Planet"),Coordinates.DEBRIS_TYPE);
      log("Debris found on "+debris+", M: "+nf.format(result.getInt("DebrisMetal"))+", C: "+nf.format(result.getInt("DebrisCrystal")), true);
      break;
    } else debris = null;
  }
  statement.close();
  result.close();
  closeDBConn(conn);
  return debris;
}
//-------------- END FUNCTION findDebris() -----------------------------------------------

//-------------- MAIN ROUTINE -----------------------------------------------
log("-------------------------------------- Start RessourceSave --------------------------------------", true);
log("Minimum Ressources: "+nf.format(minRessources), true);
for(sourcePlanet in planetNames) {
// --- Initialising variables ---
  int M = 0;
  int C = 0;
  int D = 0;
  int totalRes = 0;
  answ = null;
  errorMsg = null;
// --- Go on with next/first/once Planet/Moon ---
  Planet p = getPlanet(sourcePlanet);
  updatePlanet(p);
  M = p.getMetal()+p.getMetalDelta();
  C = p.getCrystal()+p.getCrystalDelta();
  D = p.getDeuterium()+p.getDeuteriumDelta()-remainingDeut;
  totalRes = M+C+D;
  lcs = Math.ceil(totalRes/25000);
  plcs = getNumberOf('LARGECARGO', p);
  log("Planet: "+p+"\tRessources: "+nf.format(totalRes)+"\tTransports avail: "+nf.format(plcs)+"(needed: "+nf.format(lcs), true);
  if((plcs > 0) && (totalRes > minRessources) && (D > 0)) {
    // Compose fleet
    def iter = fleet.keySet().iterator();
    while(iter.hasNext()) {
      String key = iter.next();
      if(key=='DEATHSTAR') {
        fleet[key] = Math.min(getNumberOf(key, p), fleet[key]);
        prip = fleet[key];
        lcs = lcs-(40*prip);
      }
      if(key=='RECYCLER') fleet[key] = Math.min(fleet[key], getNumberOf(key, p));
      if(key=='LARGECARGO') fleet[key] = Math.max(Math.min(lcs, plcs),fleet[key]);
    }
    // End composing fleet
    if(plcs<lcs) {
      def quote = Math.ceil(lcs/plcs*1000)/1000;
      log("Take only proportionate ressources of "+(Math.round(100/quote))+"% ("+quote+")! "+nf.format(lcs)+" LC needed, "+nf.format(plcs)+" LC available.", true);
      M=Math.floor(M/quote);
      C=Math.floor(C/quote);
      D=Math.floor(D/quote);
      log("Total Res: "+nf.format(totalRes)+". Transportable Res: "+nf.format(M+C+D), true);
    }

    targetTime = dateDiffSec(savePoint)/2000;
    if(targetTime > 0) {
      def now = new Date();
      def zeit = new Date();
      zeit.setTime(Date.parse(savePoint));
      log("Start:\t\t"+now.toLocaleString()+" \t("+nf.format(Date.parse(now.toGMTString()))+" ms)", true);
      log("SavePoint:     \t"+zeit.toLocaleString()+" \t("+nf.format(Date.parse(savePoint))+" ms)", true);
      log("Differenz in Std:\t(2way)\t"+Math.round((dateDiffSec(savePoint))/36000)/100+"\t\t("+nf.format((int)(dateDiffSec(savePoint)))+" ms)", true);
      log("TripDuration:\t(2way)\t"+nf.format((dateDiffSec(savePoint))/1000), true);
      log("Calculating best savePoint...", true);
      for(speed = 100;speed >= 10; speed -= 10) {
        tmp = getTripDuration(p, p.coordinates.toString()+" Debris", speed, fleet);
        diff = Math.abs(tmp - targetTime);
        if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && (diff < tmpTime) && (speed <= tmpSpeed)) {
          tmpTime = diff;
          tmpSpeed = speed;
          level = 1;
          targetPlanet = new Coordinates((byte)p.coordinates.galaxy,(short)p.coordinates.system,(byte)p.coordinates.planet,Coordinates.DEBRIS_TYPE);
          log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
        }
        for(planet in 1..15) {
          tmp = getTripDuration(p, "["+p.coordinates.galaxy+":"+p.coordinates.system+":"+planet+"]", speed, fleet);
          diff = Math.abs(tmp - targetTime);
          if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {
            tmpTime = diff;
            tmpSpeed = speed;
            level = 2;
            targetPlanet = new Coordinates((byte)p.coordinates.galaxy,(short)p.coordinates.system,(byte)planet,Coordinates.PLANET_TYPE);
            log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
          }
        }
        for(sys in 1..499) {
          tmp = getTripDuration(p, "["+p.coordinates.galaxy+":"+sys+":1]", speed, fleet);
          diff = Math.abs(tmp - targetTime);
          if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && (diff < tmpTime) && (speed <= tmpSpeed)) {
            tmpTime = diff;
            tmpSpeed = speed;
            level = 3;
            targetPlanet = new Coordinates((byte)p.coordinates.galaxy,(short)sys,(byte)1,Coordinates.PLANET_TYPE);
            log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
          }
        }
        for(gala in 1..12) {
          tmp = getTripDuration(p, "["+gala+":1:1]", speed, fleet);
          diff = Math.abs(tmp - targetTime);
          if((diff < tolerance) && ((diff < tmpTime) || (speed < tmpSpeed))) {//((diff < tolerance) && (diff < tmpTime) && (speed <= tmpSpeed)) {
            tmpTime = diff;
            tmpSpeed = speed;
            level = 4;
            targetPlanet = new Coordinates((byte)gala,(short)1,(byte)1,Coordinates.PLANET_TYPE);
            log("Best savePoint: "+tmpTime+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, false);
          }
        }
      }
      log("Best savePoint: "+nf.format(tmpTime)+"\tTarget: "+targetPlanet+"\tSpeed: "+tmpSpeed, true);
      log("Difference ("+nf.format(tmpTime)+") / Tolerance ("+nf.format(tolerance)+") / Level ("+level+")\r\n", true);
      if(tmpTime <= tolerance) {
        log("Fleet:   \t"+(fleet.toString().replace(",","\r\n\t\t")).replace(":","      \t")+"\r\n\r\n"+
          "targetPlanet:\t\t"+targetPlanet+"\r\n"+
          "Calc-TripTime (1-way):\t"+Math.round(dateDiffSec(savePoint)/2000)+"\r\n"+
          "getTripDuration:\t\t"+nf.format(getTripDuration(p, targetPlanet, tmpSpeed, fleet))+"\r\n"+
          "Consumption from \t"+p+" to "+targetPlanet+" = "+nf.format(getTripConsumption(p, targetPlanet, tmpSpeed, fleet))+"\r\n"+
          "Level: "+level+"\t\tTarget-area for search debris: "+targetPlanet.galaxy+
          ":"+targetPlanet.system+
          ":"+targetPlanet.planet+
          "\tSmalest difference: "+nf.format(tmpTime), true);
        if(level == 1){
          target = targetPlanet;
          log("Level = "+level+" so Target = "+targetPlanet+
            "\tTripDuration:\t"+nf.format(getTripDuration(p, targetPlanet, tmpSpeed, fleet)), true);
        }
        target = null;
        i = 0;
        while(!target && i>-5 && i<5){
          log("Scanning system: "+targetPlanet.galaxy+":"+(targetPlanet.system+i), true);
          target = findDebris(targetPlanet.galaxy, (targetPlanet.system+i), targetPlanet.planet, level);
          if(i>=0) i++;
          i=i*-1
        }
        answ = null;
        errorMsg = null;
        if(!target) {
          errorMsg = "No suitable debris-field found. Please save manually!"
        } else {
          log("SmalestDifference: "+tmpTime+"\tRealDifference: "+Math.abs(getTripDuration(p, target, tmpSpeed, fleet)-targetTime)+
              "\tSendTolerance: "+(tolerance*(1+(sendTolerance/100))), true);
          if((tmpTime > tolerance) || ((target?Math.abs(getTripDuration(p, target, tmpSpeed, fleet)-targetTime):9999999) > (tolerance*(1+(sendTolerance/100))))) {
            errorMsg = "Trip-duration exceeds tolerance. Choose another savepoint or change tolerance ("+
                        nf.format(tmpTime)+"/"+nf.format(Math.abs(getTripDuration(p, target, tmpSpeed, fleet)-targetTime))+" vs "+nf.format(tolerance)+")!";
            zeit.setTime(now.getTime()+(getTripDuration(p, target, tmpSpeed, fleet)*2000));
            log("Returntime: "+zeit.toLocaleString(), true);
            if(confirm) {
              answ = getInput("ATTENTION!!!\r\n\r\n"+
                            "Returntime exceeds tolerance!!!\r\n"+
                            "Returntime: "+zeit.toLocaleString()+"\r\n"+
                            "Speed: "+tmpSpeed+"\r\n"+
                            "Fuel: "+nf.format(getTripConsumption(p, target, tmpSpeed, fleet))+"\r\n\r\n"+
                            "Send yet? If OK type 'Y'. Otherwise I will abort.");
              if(answ == "Y") errorMsg = null;
            } else {
              answ = "Y";
              errorMsg = null;
            }
          }
        }
        if(errorMsg) {
          log(errorMsg, true);
        } else {
          log("Target: "+target+
              ",\tTripDuration: "+nf.format(getTripDuration(p, target, tmpSpeed, fleet))+
              ",\tTripConsumption: "+nf.format(getTripConsumption(p, target, tmpSpeed, fleet)), true);
          log("Ressources: "+nf.format(M+C+D)+" = "+nf.format(lcs)+" LargeCargo.", true);
          log("sendFleet("+p+", "+target+", "+tmpSpeed+", "+nf.format(M)+", "+nf.format(C)+", "+nf.format(D)+", (fleet see above)", true);
          zeit.setTime(now.getTime()+(getTripDuration(p, target, tmpSpeed, fleet)*2000));
          log("Returntime: "+zeit.toLocaleString(), true);
          if(confirm) {
            if(!answ) answ = getInput("Returntime: "+zeit.toLocaleString()+"\r\n"+
                                    "Speed: "+tmpSpeed+"\r\n"+
                                    "Fuel: "+nf.format(getTripConsumption(p, target, tmpSpeed, fleet))+"\r\n\r\n"+
                                    "If OK type 'Y'. Otherwise I will abort.");
          } else { answ = "Y" }
            if(answ == "Y") {
            sleep 10000;
            if(fullSave?sendFleetResourcesSelector(p,target,FleetMission.RECYCLE_MISSION,tmpSpeed,"DCM",[:]):sendFleetWithResources(p, target, FleetMission.RECYCLE_MISSION, tmpSpeed, M, C, D, fleet)) {
              log("---------------------------------------- Succesfull send ----------------------------------------\r\n", true);
            } else {
              log("-------------------------------------- Error while sending --------------------------------------\r\n", true);
            }
          } else {
            log("-------------------------------------- You decided to abort -------------------------------------\r\n", true);
          }
        }
      } else {
        log("---------- No target fits timeslot for "+p+". Please choose other savepoint! ----------\r\n", true);
      }
    } else {
      log("---------- Negative TripDuration from "+p+"! Please correct savePoint! ----------\r\n", true);
    }
  } else {
    log("---------- Less transporter / low ressources on "+p+". Giving up... ----------\r\n", true);
  }
}

Thats your Script... At the top of the script you can find an area called "config". There you can set your own config, for using this script.

Code: [Select]
//-------------- CONFIGURATION BY USER -----------------------------------------------
boolean fullSave = false; // false = only use of needed ships ; true = alle ships are saved
def savePoint = "06/18/2013 08:00:00"; // "04/29/2013 10:00:00";
def planetNames = ["Colony1"]; // ["Colony1","Colony2","aso","Moonname","Moon2","otherMoon"]
int minRessources = 1E6; // Cause of easier reading... Don't know how many nulls this are: 10000000000!
int tolerance = 900; // Seconds deviation by finding savePoint
def sendTolerance = 100; // % deviation on debris-search
int remainingDeut = 250000; // remaining Deut left behind
boolean confirm = true; // With 'false' I don't ask for confirmation.
//-------------- END CONFIG ----------------------------------------------------------

In your case you should write:
boolean fullSave = false; // false = only use of needed ships ; true = alle ships are saved
 => This means, that all ships. which arent needed for transporting the ressources are left behind on the planet
true means that all ships are saved

int remainingDeut = 1000000; // remaining Deut left behind
that means that 1k deut are left behind on your planet
Logged

wulf3010

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 447
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #11 on: August 15, 2013, 10:51:31 PM »

ok but:

i have 20 rips, 2k bs, 1k sxer and lets say 50k light fihgers, with another 20k big transporters and 40k small transporters.
I want that he saves all ships who are attacking and taking the big transporters for getting all ressources from the planet except 10 million deut.

As far as i understand, i can choose in the script above if i want to take all ships or if i save ships until i have my ressources away, but does he saves the war ships then the cargos or does he just take the cargos and leave the warships behind?
Logged

Death

  • Newbie
  • *
  • Offline Offline
  • Posts: 38
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #12 on: August 16, 2013, 10:24:48 AM »

try to define your fleet on your own:

def fleet = [
  DEATHSTAR : 1,
  BATTLESHIP : 0,
  BATTLECRUISER : 0,
  RECYCLER : 1,
  ESPIONAGEPROBE : 0,
  LIGHTFIGHTER : 0,
  HEAVYFIGHTER : 0,
  SMALLCARGO : 0,
  LARGECARGO : 0
]; // ensure, that LC is on last place in list! Easiest way to ensure, that RIPs also transport Ressources.


insert your ships above^^
Logged

wulf3010

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 447
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #13 on: August 16, 2013, 10:31:59 AM »

ok i understand, but:
is there an way for automatic difference from war and transport fleet within the script.
Manually i can define my fleet, but what if the fleet gets bigger and bigger. then i have to change the script everytime i add some ships to my war fleet. So the solution would be a script who saves first the war fleet (maybe this ships can be defined whats war and whats not) then the ress fleet, then the empty cargos.

perfect would be if you can define different saving behaviours.
Sorry for asking again, i might have seen some like this with different scripts, but i cant put them together correctly. an i miss the war fleet definition.
Logged

biggog

  • Newbie
  • *
  • Offline Offline
  • Posts: 25
    • View Profile
Re: Ressource Saver V0.2 06/17/2013
« Reply #14 on: August 28, 2013, 03:19:32 AM »

this script not correctly detect destination planet,
my planet 1:100:4
04:11:34 : Consumption from    [1:100:4] to [1:100:3] = 58
1:100:3 is free, no planet, why this script take it don't understand.

Please check

Code: [Select]
04:11:32 : -------------------------------------- Start RessourceSave --------------------------------------
04:11:32 : Minimum Ressources: 1 000
04:11:34 : Planet: [1:100:4] Ressources: 238 995 Transports avail: 21(needed: 10
04:11:34 : Start: 28.08.2013 4:11:34 (1 377 652 294 000 ms)
04:11:34 : SavePoint:      28.08.2013 8:00:00 (1 377 666 000 000 ms)
04:11:34 : Differenz in Std: (2way) 3.81 (13 706 000 ms)
04:11:34 : TripDuration: (2way) 13 706
04:11:34 : Calculating best savePoint...
04:11:34 : Best savePoint: 679 Target: [1:100:3] Speed: 80
04:11:34 : Difference (679) / Tolerance (900) / Level (2)
04:11:34 :
04:11:34 : Fleet:    [DEATHSTAR      0
04:11:34 : BATTLESHIP      0
04:11:34 : BATTLECRUISER      0
04:11:34 : RECYCLER      1
04:11:34 : ESPIONAGEPROBE      0
04:11:34 : LIGHTFIGHTER      0
04:11:34 : HEAVYFIGHTER      0
04:11:34 : SMALLCARGO      0
04:11:34 : LARGECARGO      10]
04:11:34 :
04:11:34 : targetPlanet: [1:100:3]
04:11:34 : Calc-TripTime (1-way): 6853
04:11:34 : getTripDuration: 7 532
04:11:34 : Consumption from [1:100:4] to [1:100:3] = 58
04:11:34 : Level: 2 Target-area for search debris: 1:100:3 Smalest difference: 679
04:11:35 : Scanning system: 1:100
04:11:38 : Scanning system: 1:99
04:11:39 : Scanning system: 1:101
04:11:40 : Scanning system: 1:98
04:11:46 : Scanning system: 1:102
04:11:47 : Scanning system: 1:97
04:11:51 : Scanning system: 1:103
04:11:52 : Scanning system: 1:96
04:11:53 : Scanning system: 1:104
04:11:59 : No suitable debris-field found. Please save manually!

Code: [Select]
boolean fullSave = true; // !!!
def savePoint = "08/28/2013 08:00:00"; // "04/29/2013 10:00:00";
def planetNames = ["abc","def","ab11","cd122","ed331"]; // ["Colony1","Colony2","aso","Moonname","Moon2","otherMoon"]
int minRessources = 1E3; //6; // Cause of easier reading... Don't know how many nulls this are: 10000000000!
int tolerance = 900; // Seconds deviation by finding savePoint
def sendTolerance = 100; // % deviation on debris-search
int remainingDeut = 2500;
boolean confirm = true; // With 'false' I don't ask for confirmation.
Logged
Pages: [1] 2 3
 

Page created in 0.038 seconds with 20 queries.