% % PCC Sample Script -- What will I have here next turn? % % To try this function: % + load the script, by using [Alt-R] on the race screen, or % `Load "nextturn.q"' on the console % + on a planet, type `NextTurn' at the console. This will print the % amounts of minerals you'll have here next turn to the console. % % Known problem: if ship A tows ship B, and both have their waypoint % set to "here", B's cargo will be counted twice. A possible solution % would be a helper property "this ship already counted". % % 22/Feb/2001 Native taxes fixed; added some comments. % Sub NextTurn Local nn = 0, tt = 0, dd = 0, mm = 0, mc = 0, sup = 0 Local x = Loc.x, y = Loc.y % First, sum minerals of incoming ships. Note the use of a yet-undefined % subroutine, `Next.AddShip'. ForEach Ship If (Owner$=My.Race$) AND (Waypoint.X=x) AND (Waypoint.Y=y) AND (Move.ETA<=1) Then Next.AddShip If Mission$=7 And Mission.Tow<>0 Then With Ship(Mission.Tow) Do Next.AddShip EndIf Next % supply production sup := sup + Factories % Tax income Local taxrate = Cfg("ColonistTaxRate", Owner$), nattax = 0, coltax = 0 Local natrate = Cfg("NativeTaxRate", Owner$) % PHost only If IsEmpty(natrate) Then natrate := taxrate If Natives Then nattax := Round(Natives * Natives.Tax * Natives.Gov$ / 5000) If nattax > Colonists Then nattax := Colonists If Natives.Race$=6 Then nattax := 2*nattax nattax := Round(nattax * natrate / 100) EndIf coltax := Round(Round(Colonists * Colonists.Tax / 1000) * taxrate / 100) mc := mc + coltax + nattax % Mining Local minerate = Cfg("RaceMiningRate", Owner$) Local natscale = If(Natives.Race$=3 AND Natives, 2, 1) Local minen = natscale * Round(Mines * Density.N * minerate / 10000) 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 minen > Ground.N Then minen := Ground.N If minet > Ground.T Then minet := Ground.T If mined > Ground.D Then mined := Ground.D If minem > Ground.M Then minem := Ground.M % Bovinoid supplies If Natives.Race$=2 Then sup := sup + Int(Natives / 100) % Output Print "=== Next-Turn Resources ===" Print Money + mc, " mc (+", mc, (", " # Z(coltax) # " col"), (", " # Z(nattax) # " nat"), ")" Print Supplies + sup, " supplies (+", sup, ")" Next.Mineral " N ", Mined.N, nn, minen Next.Mineral " T ", Mined.T, tt, minet Next.Mineral " D ", Mined.D, dd, mined Next.Mineral " M ", Mined.M, mm, minem EndSub % helper function: print one mineral. Note the use of `#' to suppress % empty entries in the "detailed" list. Sub Next.Mineral (name, have, ship, mines) Print have + ship + mines, name, "(+", ship + mines, (", " # Z(ship) # " ships"), (", " # Z(mines) # " mines"), ")" EndSub % helper function: add current ship's cargo Sub Next.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 tt := tt + Cargo.T dd := dd + Cargo.D mm := mm + Cargo.M mc := mc + Cargo.Money sup := sup + Cargo.Supplies EndSub