% % Starbase Building % % + WantBase: Counts everything on incoming ships, % and everything on the planet, and tells you % how much more to ship in to build a starbase. % Derived from the NextTurn.q Sample Script. % % + BaseReady: Looks at each of your planets, % and tells you which ones are ready to build. % % Note: This script uses TaxYield from Taxes.q % % Author: Eric Wald % Version: 1.0 % Date: 12 April 2002 % Print "[Starbase.q, 12/Apr/2002 by Eric Wald]" TryLoad 'Taxes.q' If Not IsEmpty(ScriptDir) Then TryLoad ScriptDir & 'Taxes.q' EndIf % Prints a list of planets ready to build a starbase % Warning: This can be very slow, with the Ship loop. Sub BaseReady Local require = "402T 120D 340M 900$" Local avail, remain, total=0 ForEach Planet Do If Owner$ = My.Race$ and Not Base.YesNo Then avail := Mined.Str & (Zap(Money) # '$') & (Zap(Supplies) # 'S') ForEach Ship Do If Owner$ = My.Race$ and Orbit$ = Planet.Id Then avail := CAdd(avail, Cargo.Str) EndIf Next remain := CSub(avail, require) If InStr(remain, '-') = 0 Then Print Name, ' (', remain, ' remaining)' total := total + 1 EndIf EndIf Next Print "You can", If(total, " build "& total, "'t build any"), " Starbase", If(total=1, "", "s"), " this turn." EndSub % Determines how much more it will take to build a starbase next turn. Sub WantBase if Base.YesNo then Abort "Already has a starbase" Local nt = Mined.T, nd = Mined.D, nm = Mined.M, nmc = Money, nsup = Supplies Local dt = 0, dd = 0, dm = 0, dmc = 0, dsup = 0 Local st = 402, sd = 120, sm = 340, smc = 900 Local x = Loc.x, y = Loc.y % First, sum cargo of incoming ships. ForEach Ship If (Owner$=My.Race$) AND (Distance(Waypoint.X,Waypoint.Y, x,y)<=3) Then Want.AddShip If Mission$=7 And Mission.Tow<>0 Then With Ships(Mission.Tow) Do If Distance(Waypoint.X,Waypoint.Y, x,y)>3 Then Want.AddShip EndIf Next % Supply production dsup := Factories % Bovinoid supplies If Natives.Race$=2 Then dsup := dsup + Max(Int(Natives / 100),Colonists) nsup := nsup + dsup % Tax income Try TaxYield dmc := Tax.Colonist + Tax.Native nmc := nmc + dmc % Mining Local minerate = Cfg("RaceMiningRate", Owner$) Local natscale = If(Natives.Race$=3 AND Natives, 2, 1) Local minet = natscale * Round(Mines * Density.T * minerate / 10000) Local mined = natscale * Round(Mines * Density.D * minerate / 10000) Local minem = natscale * Round(Mines * Density.M * minerate / 10000) If minet > Ground.T Then minet := Ground.T If mined > Ground.D Then mined := Ground.D If minem > Ground.M Then minem := Ground.M % Output Print "==== To Build a Starbase (Once incoming ships arrive) ====" If (smc > nmc + nsup) then Print "Money/Supplies: ", smc - nmc - nsup, " needed", If((dsup+dmc), " (" & Int( (smc - nmc - nsup) / (dsup + dmc) + .9999) & " more turns of production)") Else Print "Money/Supplies: ", nmc + nsup - smc, " remaining" EndIf Want.Mineral "Tritanium: ", nt, minet, st Want.Mineral "Duranium: ", nd, mined, sd Want.Mineral "Molybdenum: ", nm, minem, sm EndSub % helper function: print one mineral. Sub Want.Mineral (name, have, mines, need) If (need > have) then Print name, need - have, " needed", If(mines, " (" & Int( (need - have) / mines + .9999) & " more turns of mining)") Else Print name, have - need, " remaining" EndIf EndSub % helper function: add current ship's cargo Sub Want.AddShip % without the following check, an unknown ship (towee) would set the % results to EMPTY. We assume that if we know Cargo.N, we know the % others, too. If IsEmpty(Cargo.N) Then Return % nn := nn + Cargo.N % not counted, ships need fuel themselves nt := nt + Cargo.T nd := nd + Cargo.D nm := nm + Cargo.M nmc := nmc + Cargo.Money nsup := nsup + Cargo.Supplies EndSub