Advertisement
Guest User

Untitled

a guest
Sep 13th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 9.36 KB | None | 0 0
  1. //---------------------------SCRIPT CONFIG--------------------------------\\
  2. moon = GetCachedCelestial("M:3:438:8")
  3. coord, _ = ParseCoord("P:3:439:9")
  4. maxFleetValue = 0
  5. numberOfProbes = 5
  6. Deathstars = 0
  7. Cr = 0
  8. Bs = 0
  9. dessy = 0
  10. Mission = 0
  11.  
  12. time = import("time")
  13.  
  14. func getShipBaseSpeed(ship) {
  15.     speed = 0
  16.     switch ship {
  17.         case ESPIONAGEPROBE:
  18.             speed = 100000000
  19.         case CRUISER:
  20.             speed = 15000
  21.         case LIGHTFIGHTER:
  22.             speed = 12500
  23.         case BATTLESHIP:
  24.             speed = 10000
  25.         case BATTLECRUISER:
  26.             speed = 10000
  27.         case HEAVYFIGHTER:
  28.             speed = 10000
  29.         case SMALLCARGO:
  30.             speed = 5000
  31.         case LARGECARGO:
  32.             speed = 7500
  33.         case RECYCLER:
  34.             speed = 2000
  35.         case DESTROYER:
  36.             speed = 5000
  37.         case BOMBER:
  38.             speed = 4000
  39.         case COLONYSHIP:
  40.             speed = 2500
  41.         case DEATHSTAR:
  42.             speed = 100
  43.         default:
  44.             speed = 0
  45.     }
  46.     return speed
  47. }
  48.  
  49. func findLowestShipInFleet(ships, cd, id, hd) {
  50.     speed = 0
  51.     if ships.EspionageProbe > 0 {
  52.         tmp = getShipBaseSpeed(ESPIONAGEPROBE)
  53.         tmp = tmp + (tmp / 100 * 10 * cd)
  54.         if speed > tmp || speed == 0 {
  55.             speed = tmp
  56.         }
  57.         //Print(ESPIONAGEPROBE, speed)
  58.     }
  59.     if ships.Cruiser > 0 {
  60.         tmp = getShipBaseSpeed(CRUISER)
  61.         tmp = tmp + (tmp / 100 * 20 * id)
  62.         if speed > tmp || speed == 0 {
  63.             speed = tmp
  64.         }
  65.         //Print(CRUISER, speed)
  66.     }
  67.     if ships.LightFighter > 0 {
  68.         tmp = getShipBaseSpeed(LIGHTFIGHTER)
  69.         tmp = tmp + (tmp / 100 * 10 * cd)
  70.         if speed > tmp || speed == 0 {
  71.             speed = tmp
  72.         }
  73.         //Print(LIGHTFIGHTER, speed)
  74.     }
  75.     if ships.Battleship > 0 {
  76.         tmp = getShipBaseSpeed(BATTLESHIP)
  77.         tmp = tmp + (tmp / 100 * 30 * hd)
  78.         if speed > tmp || speed == 0 {
  79.             speed = tmp
  80.         }
  81.         //Print(BATTLESHIP, speed)
  82.     }
  83.     if ships.Battlecruiser > 0 {
  84.         tmp = getShipBaseSpeed(BATTLECRUISER)
  85.         tmp = tmp + (tmp / 100 * 30 * hd)
  86.         if speed > tmp || speed == 0 {
  87.             speed = tmp
  88.         }
  89.         //Print(BATTLECRUISER, speed)
  90.     }
  91.     if ships.HeavyFighter > 0 {
  92.         tmp = getShipBaseSpeed(HEAVYFIGHTER)
  93.         tmp = tmp + (tmp / 100 * 20 * id)
  94.         if speed > tmp || speed == 0 {
  95.             speed = tmp
  96.         }
  97.         //Print(HEAVYFIGHTER, speed)
  98.     }
  99.     if ships.SmallCargo > 0 {
  100.         tmp = getShipBaseSpeed(SMALLCARGO)
  101.         if id >= 5 {
  102.             tmp = tmp + (tmp / 100 * 20 * id)
  103.         } else {
  104.             tmp = tmp + (tmp / 100 * 10 * cd)
  105.         }
  106.         if speed > tmp || speed == 0 {
  107.             speed = tmp
  108.         }
  109.         //Print(SMALLCARGO, speed)
  110.     }
  111.     if ships.LargeCargo > 0 {
  112.         tmp = getShipBaseSpeed(LARGECARGO)
  113.         tmp = tmp + (tmp / 100 * 10 * cd)
  114.         if speed > tmp || speed == 0 {
  115.             speed = tmp
  116.         }
  117.         //Print(LARGECARGO, speed)
  118.     }
  119.     if ships.Recycler > 0 {
  120.         tmp = getShipBaseSpeed(RECYCLER)
  121.         if hd >= 15 {
  122.             tmp = tmp + (tmp / 100 * 30 * hd)
  123.         } else if id >= 17 {
  124.             tmp = tmp + (tmp / 100 * 20 * id)
  125.         } else {
  126.             tmp = tmp + (tmp / 100 * 10 * cd)
  127.         }
  128.         if speed > tmp || speed == 0 {
  129.             speed = tmp
  130.         }
  131.         //Print(RECYCLER, speed)
  132.     }
  133.     if ships.Destroyer > 0 {
  134.         tmp = getShipBaseSpeed(DESTROYER)
  135.         tmp = tmp + (tmp / 100 * 30 * hd)
  136.         if speed > tmp || speed == 0 {
  137.             speed = tmp
  138.         }
  139.         //Print(DESTROYER, speed)
  140.     }
  141.     if ships.Bomber > 0 {
  142.         tmp = getShipBaseSpeed(BOMBER)
  143.         if hd >= 8 {
  144.             tmp = tmp + (tmp / 100 * 30 * hd)
  145.         } else {
  146.             tmp = tmp + (tmp / 100 * 20 * id)
  147.         }
  148.         if speed > tmp || speed == 0 {
  149.             speed = tmp
  150.         }
  151.         //Print(BOMBER, speed)
  152.     }
  153.     if ships.ColonyShip > 0 {
  154.         tmp = getShipBaseSpeed(COLONYSHIP)
  155.         tmp = tmp + (tmp / 100 * 20 * id)
  156.         if speed > tmp || speed == 0 {
  157.             speed = tmp
  158.         }
  159.         //Print(COLONYSHIP, speed)
  160.     }
  161.     if ships.Deathstar > 0 {
  162.         tmp = getShipBaseSpeed(DEATHSTAR)
  163.         tmp = tmp + (tmp / 100 * 30 * hd)
  164.         if speed > tmp || speed == 0 {
  165.             speed = tmp
  166.         }
  167.         //Print(DEATHSTAR, speed)
  168.     }
  169.     return speed
  170. }
  171.  
  172. func getReport(coord) {
  173.     report, err = GetEspionageReportFor(coord)
  174.     if err != nil {
  175.         LogError("[SPY] err getting espionage report " + err)
  176.     }
  177.     Print(report)
  178.     list = {}
  179.     if report.HasResearches {
  180.         cd = report.CombustionDrive
  181.         if (*cd) >= 1 { list.COMBUSTIONDRIVE = *cd } else { list.COMBUSTIONDRIVE = 0 }
  182.         id = report.ImpulseDrive
  183.         if (*id) >= 1 { list.IMPULSEDRIVE = *id } else { list.IMPULSEDRIVE = 0 }
  184.         hd = report.HyperspaceDrive
  185.         if (*hd) >= 1 { list.HYPERSPACEDRIVE = *hd } else { list.HYPERSPACEDRIVE = 0 }
  186.     } else {
  187.         LogInfo("[SPY] probes couldnt get research info")
  188.         return nil
  189.     }
  190.     return list
  191. }
  192.  
  193. func spyCoord(coord, origin) {
  194.     LogInfo("spy " + coord)
  195.     for {
  196.         slots = GetSlots()
  197.         if slots.InUse < slots.Total {
  198.                 fleet = NewFleet()
  199.                 fleet.SetOrigin(origin)
  200.                 fleet.SetDestination(coord)
  201.                 fleet.SetMission(SPY)
  202.                 fleet.AddShips(ESPIONAGEPROBE, numberOfProbes)
  203.                 fleet, err = fleet.SendNow()
  204.                 if err != nil {
  205.                     LogError("[SPY] error sending probes " + err)
  206.                 }
  207.                 Sleep((4 + fleet.ArriveIn) * 1000)
  208.             break
  209.         } else {
  210.             Sleep(30000)
  211.         }
  212.     }
  213. }
  214.  
  215. func doWork() {
  216.     fleets, _ = Phalanx(moon.GetID(), coord)
  217.     Impact = 0
  218.     foundingFleet = 0
  219.     for fleet in fleets {
  220.         currentFleetValue = fleet.Ships.FleetValue()
  221.         if currentFleetValue > maxFleetValue {
  222.             maxFleetValue = currentFleetValue
  223.             foundingFleet = fleet
  224.             Deathstars = fleet.Ships.Deathstar
  225.             Cr = fleet.Ships.Cruiser
  226.             Bs = fleet.Ships.Battleship
  227.             dessy = fleet.Ships.Destroyer
  228.             Mission = fleet.Mission
  229.             Impact = time.Now()
  230.             Impact = Impact.Add(time.Second * fleet.ArriveIn)
  231.             Print("============================================================")
  232.             Print("Fleets Value: " + (Dotify(fleet.Ships.FleetValue())))
  233.             Print("Fleets From: " + fleet.Origin)
  234.             Print("Fleets to : " + fleet.Destination)
  235.             Print("Arrives In: " + (ShortDur(fleet.ArriveIn)))
  236.             Print("Impact Time: " + Impact.Clock())
  237.             Print("Fleet Mission: " + fleet.Mission)
  238.             Print("Ships in the Air: " + fleet.Ships)
  239.             Print("============================================================")
  240.         }
  241.     }
  242.     for {
  243.         activeFleet = false
  244.         fleets, _ = Phalanx(moon.GetID(), coord)
  245.         if len(fleets) > 0 {
  246.             for fleet in fleets {
  247.                 if fleet.Ships.Deathstar == Deathstars && fleet.Ships.Cruiser == Cr && fleet.Ships.Battleship == Bs && fleet.Ships.Destroyer == dessy {
  248.                     activeFleet = true
  249.                 }
  250.             }
  251.         }
  252.         if activeFleet == false {
  253.             recalledTime = time.Now()
  254.             Print("Fleet Recalled at " + recalledTime.Clock() + " Fleet had a value of " + (Dotify(maxFleetValue)) + " From the planet " + coord)
  255.             report = {}
  256.             for {
  257.                 spyCoord(foundingFleet.Origin, moon)
  258.                 report = getReport(foundingFleet.Origin)
  259.                 if report != nil {
  260.                     break
  261.                 }
  262.             }
  263.             Print(report)
  264.             lowestSpeedShipInFleet = findLowestShipInFleet(foundingFleet.Ships, report.COMBUSTIONDRIVE, report.IMPULSEDRIVE, report.HYPERSPACEDRIVE)
  265.             distance = Distance(foundingFleet.Origin, foundingFleet.Destination)
  266.             LogInfo("Here is your desired Return Time calculation")
  267.             speedFactor = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
  268.             for s in speedFactor {
  269.                 v = lowestSpeedShipInFleet // lowest ship in fleet
  270.                 a = OGAME_SERVER.Settings.FleetSpeed // fleet speed
  271.                 d = distance // distance between planets / moons
  272.                 secs = Round(((3500 / s) * Pow((d * 10 / v), (0.5)) + 10) / a)
  273.                 //LogInfo("Time till fleet is back on " + s*100 + "% " + ShortDur(secs))
  274.                
  275.                 //Print("TEST EXPERIEMENTAL in seconds")
  276.                 /* based on
  277.                 phalanxed arival            = 17:00
  278.                 time of recall              = 16:30
  279.                 original fleet time 100%    = 3h
  280.  
  281.                 Time of Return on starting planet: 16:30 + (3:00:00h - 0:30:00h(phalanxed arival - time of recall)) = 19:00
  282.                 */
  283.                 expectedTime = recalledTime.Add(time.Second * (secs - Impact.Sub(recalledTime).Seconds()))
  284.                 LogInfo("Fleet could be back on " + s*100 + "% " + expectedTime)
  285.             }
  286.             break
  287.         }
  288.         Sleep(3 * 1000)
  289.     }
  290. }
  291. doWork()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement