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: Fleet Saver Alternative (v4)  (Read 14334 times)

0 Members and 1 Guest are viewing this topic.

Devil's Hand

  • Administrator
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 2,523
    • View Profile
Fleet Saver Alternative (v4)
« on: February 23, 2012, 12:15:05 AM »

This script is provided as an example of OA API usage, should be used with cation on a real account

Create new OA Script.
Rename it to something like 'FS Alt 1',
Enable the option 'Execute after OA initialization',
Enable the option 'Restart the script on error',
In OA code editor (delete template code: select all text (CTRL+A) than Backspace), paste the following code:
Code: [Select]
// Let's make an alternative Fleet Saver
// This script is provided as an example of OA API usage, should be used with cation on a real account
pauseScriptWhenOADisabled()  //pause this Script when OA is Disabled or is not Logged-in

// Config
def fsTime = 15  //mins
def fsRadius = 50  //solar systems
def sendOneSpyOnEnemy = YES  //might help to show that you are see what is going on...

// In case there is some time ahead to FS and you cannot transport all resources, then try to invest
def fsInvestInBuildingsIfPossible = [
  TERRAFORMER,
  SOLARPLANT,
  CRYSTALMINE,
  METALMINE,
  //DEUTERIUMSYNTHESIZER,
  //FUSIONREACTOR,
  NANITEFACTORY,
  ROBOTICSFACTORY,
  SHIPYARD,
  METALSTORAGE,
  CRYSTALSTORAGE,
  //DEUTERIUMTANK,
  //METALDEN,
  //CRYSTALDEN,
  //DEUTERIUMDEN,
  RESEARCHLAB,
  ALLIANCEDEPOT,
  LUNARBASE,
  SENSORPHALANX,
  JUMPGATE,
  MISSILESILO
]
def fsInvestInTechnologiesIfPossible = [
  GRAVITONTECHNOLOGY,
  INTERGALACTICRESEARCHNETWORK,
  ASTROPHYSICS,
  ESPIONAGETECHNOLOGY,
  COMPUTERTECHNOLOGY,
  COMBUSTIONDRIVE,
  IMPULSEDRIVE,
  HYPERSPACEDRIVE,
  ARMOURTECHNOLOGY, WEAPONSTECHNOLOGY, SHIELDINGTECHNOLOGY,
  ENERGYTECHNOLOGY,
  HYPERSPACETECHNOLOGY,
  PLASMATECHNOLOGY,
  IONTECHNOLOGY, 
  LASERTECHNOLOGY
]
def fsInvestInShipsDefences = [
  DEATHSTAR: 1,
  BATTLESHIP: 5,
  BATTLECRUISER: 5,
  SMALLCARGO: 10,
  LARGECARGO: 5,
  ESPIONAGEPROBE: 5,
  //LIGHTFIGHTER: 10,

  PLASMATURRET: 5,
  GAUSSCANNON: 3,
  IONCANNON: 3,
  LIGHTLASER: 10,
  ROCKETLAUNCHER: 10
  //HEAVYLASER: 10,
]

def needFS = { fleet, planet ->
  if(fleet.getEntities().hasShips() && planet.getEntities().hasShips()){
    try {
      // Make a Battle Sim
      BattleSimResult bsr = battleSim fleet.getEntities(), planet.getEntities()
      if(bsr.defenderTotalLosses < 1) return false  //Incoming fleet looses, bypass FS ...
      printOut "Defender Losses Price: "+bsr.defenderLossesPrice
      printOut "Defender Total Losses: "+bsr.defenderTotalLosses
      printOut "Metal Debris: "+bsr.metalDebris
      printOut "Crystal Debris: "+bsr.crystalDebris
    } catch (BattleSimEmptyAttackerException bseae){
      return true
    } catch (BattleSimEmptyDefenderException bsede){
      return false
    }
  }
  return true
}
def burnResources = { attackedPlt ->
  return getFleetMaxTransportableWeigh(attackedPlt.getEntities()) < attackedPlt.getMetal()+attackedPlt.getMetalDelta() + attackedPlt.getCrystal()+attackedPlt.getCrystalDelta() + attackedPlt.getDeuterium()+attackedPlt.getDeuteriumDelta() 
}

def spySent = false
// Main FS loop
while(true){
  if((isAttacked() || isSpied())){
    for(f in getFleetInAir()){
      if((f.type == "enemyflight" || f.type == "enemyflightEspionage") && Coordinates.isCoordinates(f.toPlanet) && needFS(f, getPlanetFromCoordinates(f.toPlanet))) {  //Enemy fleet, attacked planet has ships, battle is not in your advantage
        def attackedPlt = getPlanetFromCoordinates(f.toPlanet)
        if(f.time > fsTime*60*1000 && f.time < 2*fsTime*60*1000) {  //we have some time, beetween fsTime and fsTime * 2 => try to burn/invest some resources if needed
          if(sendOneSpyOnEnemy && !spySent && (getNumberOf('ESPIONAGEPROBE', attackedPlt.coordinates) != 0) && Coordinates.isCoordinates(f.fromPlanet)){
            spySent = sendFleet( attackedPlt.coordinates, f.fromPlanet, FleetMission.ESPIONAGE_MISSION, 50, [ESPIONAGEPROBE: 1] )
          }
          if(burnResources(attackedPlt)) {
            // You cannot transport all resource during FS => burn them
            for(invest in fsInvestInBuildingsIfPossible) {
              if(!isBuildingInProgress(attackedPlt) &&
                   canBuild(invest, attackedPlt) &&
                   (getPrice(invest, attackedPlt).getMetalValue() < attackedPlt.getMetal()) &&
                   (getPrice(invest, attackedPlt).getCrystalValue() < attackedPlt.getCrystal()) &&
                   (getPrice(invest, attackedPlt).getDeutValue() < attackedPlt.getDeuterium()))
              {
                if( investInBuildingTechnology(invest, attackedPlt) ) {
                  printOut "Investment in " + invest + " is done on planet " + attackedPlt
                  break;  //Breaking the for loop in order to reevaluate the condition to burn resources
                } else printOut "Investment in " + invest + " Failed !"
              }
            }
          }
          if(burnResources(attackedPlt)) {
            for(invest in fsInvestInTechnologiesIfPossible) {
              if(!isTechnologyInProgress() &&
                   canBuild(invest, attackedPlt) &&
                   (getPrice(invest, attackedPlt).getMetalValue() < attackedPlt.getMetal()) &&
                   (getPrice(invest, attackedPlt).getCrystalValue() < attackedPlt.getCrystal()) &&
                   (getPrice(invest, attackedPlt).getDeutValue() < attackedPlt.getDeuterium()))
              {
                if( investInBuildingTechnology(invest, attackedPlt) ) {
                  printOut "Investment in " + invest + " is done on planet " + attackedPlt
                  break;  //Breaking the for loop in order to reevaluate the condition to burn resources
                } else printOut "Investment in " + invest + " Failed !"
              }
            }
          }
          if(burnResources(attackedPlt)) {
            if( investInShipsDefences(fsInvestInShipsDefences, attackedPlt) ) {
              printOut "Ships/Defences Investment is done on planet " + attackedPlt
            } else printOut "Ships/Defences Investment Failed !"
          }
        } else if(f.time < fsTime*60*1000 && attackedPlt.getEntities().hasShips()) {  //Time to FS and attacked planet still has ships
          printOut "Starting FS"
          def safePlanet = ""
         
          // Start Galaxy Scan
          startAsyncGalaxyScan attackedPlt.coordinates.galaxy, attackedPlt.coordinates.system-10, attackedPlt.coordinates.system+10
         
          // Find some debris
          Connection conn = getDBConn()
          Statement statement = conn.createStatement();
          ResultSet result = statement.executeQuery("SELECT * FROM PLANET, GALAXY_SCAN WHERE PLANET.Galaxy=GALAXY_SCAN.Galaxy AND PLANET.System=GALAXY_SCAN.System AND PLANET.Planet=GALAXY_SCAN.Planet AND PLANET.IsMoon=GALAXY_SCAN.IsMoon AND PLANET.Galaxy="+attackedPlt.coordinates.galaxy+" AND PLANET.System>="+(attackedPlt.coordinates.system-fsRadius)+" AND PLANET.System<="+(attackedPlt.coordinates.system+fsRadius)+" AND (DebrisMetal>0 OR DebrisCrystal>0) AND ScanTimeSec>"+getRealTime2DBSec(timestamp-3600*1000)+" order by ScanTimeSec");
          def minDuration = Long.MAX_VALUE;
          while(result.next()){
            printOut result.getInt("Galaxy") + ":" + result.getInt("System") + ":" + result.getInt("Planet") + " " + result.getBoolean("IsMoon") + " " + result.getInt("DebrisMetal") + " " + result.getInt("DebrisCrystal")
            if(getTripDuration( attackedPlt.coordinates, result.getInt("Galaxy") + ":" + result.getInt("System") + ":" + result.getInt("Planet"), 10, [:] ) < minDuration) {
              safePlanet = result.getInt("Galaxy") + ":" + result.getInt("System") + ":" + result.getInt("Planet")
              minDuration = getTripDuration( attackedPlt.coordinates, safePlanet, 10, [:] )
            }
          }
          statement.close()
          result.close()
          closeDBConn(conn)
         
          // Try to save on Debris if the planet has some recyclers
          if(getNumberOf('RECYCLER', attackedPlt.coordinates) != 0 && !safePlanet.isEmpty()){
            printOut "Safe Planet is " + safePlanet
            // Send a all your ships on debris
            if(sendFleetResourcesSelector( attackedPlt.coordinates, safePlanet, FleetMission.RECYCLE_MISSION, 10, "DCM", [:] ) ) {
              recallFleet attackedPlt.coordinates, safePlanet, 10, [:], 0.0 //Recall time cannot be calculated as OA doesn't know about the exact fleet composition
              printOut "FS done."
              break
            } else printOut "Failed to send FS fleet: RECYCLE"
          }
          // Try to save with attack/transport mission
          if(attackedPlt.getEntities().hasShips() && !safePlanet.isEmpty()){
            printOut "Safe Planet is " + safePlanet
            // Send a all your ships as an attack
            if( sendFleetResourcesSelector( attackedPlt.coordinates, safePlanet, FleetMission.ATTACK_MISSION, 10, "DCM", [:] ) ) {
              recallFleet attackedPlt.coordinates, safePlanet, 10, [:], 0.0 //Recall time cannot be calculated as OA doesn't know about the exact fleet composition
              printOut "FS done."
              break
            } else {
              printOut "Failed to send FS fleet: ATTACK"
              // Send a all your ships as a transport
              if( sendFleetResourcesSelector( attackedPlt.coordinates, safePlanet, FleetMission.TRANSPORT_MISSION, 10, "DCM", [:] ) ) {
                recallFleet attackedPlt.coordinates, safePlanet, 10, [:], 0.0 //Recall time cannot be calculated as OA doesn't know about the exact fleet composition
                printOut "FS done."
                break
              } else {
                printOut "Failed to send FS fleet: TRANSPORT"
                if(Coordinates.isCoordinates(f.fromPlanet) && sendFleetResourcesSelector( attackedPlt.coordinates, Coordinates.parseCoordinates(f.fromPlanet), FleetMission.ATTACK_MISSION, 10, "DCM", [:] )) {
                  recallFleet attackedPlt.coordinates, Coordinates.parseCoordinates(f.fromPlanet), 10, [:], 0.0 //Recall time cannot be calculated as OA doesn't know about the exact fleet composition
                  printOut "FS done."
                  break
                } else printOut "Failed to send FS fleet: ATTACK on enemy"
              }
            }
          }
        }
      }
    }
  }
  sleep 1000
}
During all next OA startups, a different FS behavior will be executed fsTime mins before the enemy arrival on your planet.
Keep OA FS enabled but with FS time less than fsTime.

FS behavior:
- Send one espionage probe on the enemy from the attacked planet
- Battle Simulation => if attacker loose => abort FS
- If you have too much resources on the attacked planet => try to burn them: invest in building, invest in technology, finally invest in ships/defs
- starts galaxy scan
- finds some debris not far away from the attacked planet
- if there is any recyclers on the planet, FS on debris
- if not, it's trying to attack a planet
- if not, it's trying to send a transport on a planet
- recall when the attack ends

Regards,
« Last Edit: November 07, 2012, 10:24:27 PM by Devil's Hand »
Logged

Zebra

  • Full Member
  • ***
  • Offline Offline
  • Posts: 212
    • View Profile
Re: Fleet Saver Alternative (1)
« Reply #1 on: February 23, 2012, 04:23:32 AM »

Risky behaviour if the attacked location is a planet.
On options:
1) A lanx on target would ensure inescapable destruction.
2) ditto
3) transport res to a neighbour's planet?? whats the difference of just letting the attacker have it?
Better option is:
(A) to scan for DF only if on a moon. if on moon, send on recycle to closest DF. Current FS on deploy is safer though.
(B) else if not on moon i.e. planet, scan for closest own planet (same galaxy within 127 systems), send on deploy return at slowest speed 10% (saves deut) and gives you chance of escape (undetectable deploy return) if attacked on destination. 

An alternative (riskier option but maybe cheaper ) is to scan for 2-3 random inactive 3-10 systems away, send probes on attack on all, check for DF, send recycler there to one of the random DF. Inactive planets are constantly being probed so lanxers are less likely to lanx those.

Just some ideas.
Logged

wulf3010

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 447
    • View Profile
Re: Fleet Saver Alternative (1)
« Reply #2 on: February 23, 2012, 05:43:58 PM »

add an recall after xx % then you wont get intercepted. Also check if you have a rip, if yes recall after 40% if not recall after 70%
Or alternativly send to next Moond on stationary
Logged

Devil's Hand

  • Administrator
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 2,523
    • View Profile
Re: Fleet Saver Alternative (v2)
« Reply #3 on: April 02, 2012, 08:53:19 PM »

updated v2: added Battle Simulation before taking decision of FS

Regards,
« Last Edit: April 23, 2012, 01:06:00 AM by Devil's Hand »
Logged

Devil's Hand

  • Administrator
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 2,523
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #4 on: April 23, 2012, 01:07:04 AM »

updated v3: added burn resources + send one espionage probe on the enemy from the attacked planet

Regards,
Logged

Trigun

  • Newbie
  • *
  • Offline Offline
  • Posts: 33
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #5 on: April 26, 2012, 02:04:46 PM »

for debris... 90% of time u can FS on ur debris ... bc when some1 crash a probe the debris is active for a lot of time...
maybe the bot can try to FS to debris on the same coords and if fail try to distant spot
Logged

wulf3010

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 447
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #6 on: May 14, 2012, 07:43:12 PM »

Saving on your own debris might be calculate able for an re.
Logged

asdasd

  • Full Member
  • ***
  • Offline Offline
  • Posts: 231
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #7 on: June 15, 2012, 08:43:34 AM »

for use this i must remove from advanced option a tic save a fleet when arrive... ? or no?
Logged

Devil's Hand

  • Administrator
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 2,523
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #8 on: June 15, 2012, 09:29:20 PM »

for use this i must remove from advanced option a tic save a fleet when arrive... ? or no?
No, it's additional to OA built-in FS.
Logged

mandrakor

  • Jr. Member
  • **
  • Offline Offline
  • Posts: 77
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #9 on: June 20, 2012, 05:05:02 PM »

Have had a bug with this script ...

Two attack with less time betwin and the script don't have call back the fleets ...

Does it's possible to force the script to send fleet in deployement mode to avoid attack ?

Thx
Logged

asdasd

  • Full Member
  • ***
  • Offline Offline
  • Posts: 231
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #10 on: June 26, 2012, 09:42:12 PM »

is it possible recall fleet immediatly after attack?
Logged

John Titor

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #11 on: July 30, 2012, 05:49:29 PM »

I tried to modify Devil's Script, basically I deleted a few lines to make the script do what I want it to (with all due respect), can you tell me if it would still be valid?

Code: [Select]
//Let's make an alternative Fleet Saver
//This script is provided as an example of OA API usage, should be used with cation on a real account
pauseScriptWhenOADisabled()  //pause this Script when OA is Disabled or is not Logged-in

//Config
def fsTime = 15  //mins
def fsRadius = 50  //solar systems
def sendOneSpyOnEnemy = true  //might help to show that you are see what is going on...

//In case there is some time ahead to FS and you cannot transport all resources, then try to invest
def fsInvestInBuildingsIfPossible = [
  'TERRAFORMER',
  'SOLARPLANT',
  'CRYSTALMINE',   
  'METALMINE',
  //'DEUTERIUMSYNTHESIZER',
  //'FUSIONREACTOR',
  'NANITEFACTORY',
  'ROBOTICSFACTORY',
  'SHIPYARD',
  'METALSTORAGE',
  'CRYSTALSTORAGE',
  //'DEUTERIUMTANK',
  //'METALDEN',
  //'CRYSTALDEN',
  //'DEUTERIUMDEN',
  'RESEARCHLAB',
  'ALLIANCEDEPOT',
  'LUNARBASE',
  'SENSORPHALANX',
  'JUMPGATE',
  'MISSILESILO'
]
def fsInvestInTechnologiesIfPossible = [
  'GRAVITONTECHNOLOGY',
  'INTERGALACTICRESEARCHNETWORK',
  'ASTROPHYSICS',
  'ESPIONAGETECHNOLOGY',
  'COMPUTERTECHNOLOGY',
  'COMBUSTIONDRIVE',
  'IMPULSEDRIVE',
  'HYPERSPACEDRIVE',
  'ARMOURTECHNOLOGY', 'WEAPONSTECHNOLOGY', 'SHIELDINGTECHNOLOGY',
  'ENERGYTECHNOLOGY',
  'HYPERSPACETECHNOLOGY',
  'PLASMATECHNOLOGY',
  'IONTECHNOLOGY', 
  'LASERTECHNOLOGY'
]
def fsInvestInShipsDefences = [
  'DEATHSTAR': 1,
  'BATTLESHIP': 5,
  'BATTLECRUISER': 5,
  'SMALLCARGO': 10,
  'LARGECARGO': 5,
  'ESPIONAGEPROBE': 5,
  //'LIGHTFIGHTER': 10,

  'PLASMATURRET': 5,
  'GAUSSCANNON': 3,
  'IONCANNON': 3,
  'LIGHTLASER': 10,
  'ROCKETLAUNCHER': 10
  //'HEAVYLASER': 10,
]

def needFS = { fleet, planet ->
  if(fleet.getEntities().hasShips() && planet.getEntities().hasShips()){
    //Make a Battle Sim
    BattleSimResult bsr = battleSim fleet.getEntities(), planet.getEntities()
    if(bsr.defenderTotalLosses < 1) return false  //Incoming fleet looses, bypass FS ...
    printOut "Defender Losses Price: "+bsr.defenderLossesPrice
    printOut "Defender Total Losses: "+bsr.defenderTotalLosses
    printOut "Metal Debris: "+bsr.metalDebris
    printOut "Crystal Debris: "+bsr.crystalDebris
    return true
  }
  return true
}
def burnResources = { attackedPlt ->
  return true
}

def spySent = false
//Main FS loop
while(true){
  if((isAttacked() || isSpied())){
    for(f in getFleetInAir()){
      if((f.type == "enemyflight" || f.type == "enemyflightEspionage") && Coordinates.isCoordinates(f.toPlanet) && needFS(f, getPlanetFromCoordinates(f.toPlanet))) {  //Enemy fleet, attacked planet has ships, battle is not in your advantage
        def attackedPlt = getPlanetFromCoordinates(f.toPlanet)
        if(f.time > fsTime*60*1000 && f.time < 2*fsTime*60*1000) {  //we have some time, beetween fsTime and fsTime * 2 => try to burn/invest some resources if needed
          if(sendOneSpyOnEnemy && !spySent && (getNumberOf('ESPIONAGEPROBE', attackedPlt.coordinates) != 0) && Coordinates.isCoordinates(f.fromPlanet)){
            spySent = sendFleet( attackedPlt.coordinates, f.fromPlanet, FleetMission.ESPIONAGE_MISSION, 50, [ESPIONAGEPROBE: 1] )
          }
          if(burnResources(attackedPlt)) {
            for(invest in fsInvestInTechnologiesIfPossible) {
              if(!isTechnologyInProgress() &&
                   canBuild(invest, attackedPlt) &&
                   (getPrice(invest, attackedPlt).getMetalValue() < attackedPlt.getMetal()) &&
                   (getPrice(invest, attackedPlt).getCrystalValue() < attackedPlt.getCrystal()) &&
                   (getPrice(invest, attackedPlt).getDeutValue() < attackedPlt.getDeuterium()))
              {
                if( investInBuildingTechnology(invest, attackedPlt) ) {
                  printOut "Investment in " + invest + " is done on planet " + attackedPlt
                  break;  //Breaking the for loop in order to reevaluate the condition to burn resources
                } else printOut "Investment in " + invest + " Failed !"
              }
            }
          }
          if(burnResources(attackedPlt)) {
            if( investInShipsDefences(fsInvestInShipsDefences, attackedPlt) ) {
              printOut "Ships/Defences Investment is done on planet " + attackedPlt
            } else printOut "Ships/Defences Investment Failed !"
          }
        }
      }
    }
  }
  sleep 1000
}

Basically, what I want is a script that will burn all resources in case of an attack, and will burn them in the order (1- Tech, 2- Ship/Def).
To do so, I changed the lines def burnResources to always return true (Therefore, if a serious attack is comming, it always burn resources)
And I also deleted the lines to make fleet save to debris field and/or planet.

So, would it still work?
Logged

Devil's Hand

  • Administrator
  • Hero Member
  • *****
  • Offline Offline
  • Posts: 2,523
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #12 on: July 30, 2012, 07:42:01 PM »

Quote
So, would it still work?
Probably yes, just test it and let us know.

You can also remove the following
Code: [Select]
def fsInvestInBuildingsIfPossible = [ ...as you don't use it in the script.

Regards,
Logged

John Titor

  • Newbie
  • *
  • Offline Offline
  • Posts: 2
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #13 on: July 31, 2012, 03:04:53 AM »

Thanks. I will test it when given the chance. I hope not to be attacked for a while, though.
Logged

bohne

  • Newbie
  • *
  • Offline Offline
  • Posts: 44
    • View Profile
Re: Fleet Saver Alternative (v3)
« Reply #14 on: September 11, 2012, 08:45:56 PM »

would you mind to update this script to 5.0 and a function
if attacked send massage xy ? ;)
Logged
Pages: [1] 2 3
 

Page created in 0.035 seconds with 20 queries.