Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 10.17 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.             Impact = Impact.Add(time.Hour * 1)
  232.             Print("============================================================")
  233.             Print("Fleets Value: " + (Dotify(fleet.Ships.FleetValue())))
  234.             Print("Fleets From: " + fleet.Origin)
  235.             Print("Fleets to : " + fleet.Destination)
  236.             Print("Arrives In: " + (ShortDur(fleet.ArriveIn)))
  237.             Print("Impact Time: " + Impact.Format("15:04:05 PM"))
  238.             Print("Fleet Mission: " + fleet.Mission)
  239.             Print("Ships in the Air: " + fleet.Ships)
  240.             Print("============================================================")
  241.         }
  242.     }
  243.     for {
  244.         activeFleet = false
  245.         fleets, _ = Phalanx(moon.GetID(), coord)
  246.         if len(fleets) > 0 {
  247.             for fleet in fleets {
  248.                 if fleet.Ships.Deathstar == Deathstars && fleet.Ships.Cruiser == Cr && fleet.Ships.Battleship == Bs && fleet.Ships.Destroyer == dessy {
  249.                     activeFleet = true
  250.                 }
  251.             }
  252.         }
  253.         if activeFleet == false {
  254.             recalledTime = time.Now()
  255.             recalledTime = recalledTime.Add(time.Hour * 1)
  256.             Print("Fleet Recalled at " + recalledTime.Format("15:04:05 PM") + " Fleet had a value of " + (Dotify(maxFleetValue)) + " From the planet " + coord)
  257.             PlaySound(1, 1.0)
  258.             report = {}
  259.             for {
  260.                 spyCoord(foundingFleet.Origin, moon)
  261.                 report = getReport(foundingFleet.Origin)
  262.                 if report != nil {
  263.                     break
  264.                 }
  265.             }
  266.             Print(report)
  267.             lowestSpeedShipInFleet = findLowestShipInFleet(foundingFleet.Ships, report.COMBUSTIONDRIVE, report.IMPULSEDRIVE, report.HYPERSPACEDRIVE)
  268.             distance = Distance(foundingFleet.Origin, foundingFleet.Destination)
  269.             LogInfo("Here is your desired calculation")
  270.             speedFactor = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
  271.             for s in speedFactor {
  272.                 v = lowestSpeedShipInFleet // lowest ship in fleet
  273.                 a = OGAME_SERVER.Settings.FleetSpeed // fleet speed
  274.                 d = distance // distance between planets / moons
  275.                 flight = Round(((3500 / s) * Pow((d * 10 / v), (0.5)) + 10) / a)
  276.                 Print("============================ " + s*100 + " % ===============================")
  277.                 Print("flight time: ", ShortDur(flight))
  278.                 Print("Fleet Recalled at " + recalledTime.Format("3:04:15PM") + " Fleet had a value of " + (Dotify(maxFleetValue)) + " From the planet " + coord)
  279.                 Launchtime = Impact.Add(-flight * time.Second)
  280.                 Print("Launchtime = Impact Time:" + Impact.Format("15:04:05 PM") + " - flight: " + (ShortDur(flight)) + " = Launchtime: " + Launchtime.Format("15:04:05 PM"))
  281.                 Journey = recalledTime.Add(-Launchtime * time.Second)
  282.                 Print("Journey = Recall Time: " + recalledTime.Format("3:04:15 PM") + " - Launchtime:", Journey.Format("3:04:15 PM"))
  283.                 Return = recalledTime.Sub(Journey)
  284.                 //Return = recalledTime.Add(Duration)
  285.                 Return = Return.Add(1 * time.Hour)
  286.                 Print("Return = Recall Time add Journey:", Return.Format("3:04:15PM"))
  287.                 Print("==================================================================")
  288.            
  289.        
  290. //               expectedTime = recalledTime.Add((secs - foundingFleet.ArriveIn) * time.Second)
  291. //                LogInfo("Fleet could be back on " + s*100 + "% " + expectedTime.Format("Jan 02, 15:04:05"))
  292.             }
  293.             break
  294.         }
  295.         Sleep(3 * 1000)
  296.     }
  297. }
  298. doWork()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement