% % Taxation Scripts % % + SafeTax: Brings Amorphs to 96 HP, everyone else to 71 HP. % Must be called from Planet context. % + GrowthTax: Safe taxes only under specific conditions, % Designed to let your populations grow if they can. % Must be called from Planet context. % + SafeTaxAll and GrowthTaxAll: % Calls the appropriate tax model on each of your planets. % Also calls Tax.Corrections at the end, if you have defined it. % % + TaxYield: Calculates the number of megacredits % a planet will generate, and stores it in Tax.Native and Tax.Colonist % (shared variables, not planet properties). % + Tax.PrintYield: Calls TaxYield and prints its values to the console. % + CalcGrowth: Calculates the population growth for a planet % and stores it in Natives.Growth and Colonists.Growth % (planet properties, not shared variables). % + GrowthReport: Outputs to a file the expected and actual growth % of each of your planets. % % Author: Eric Wald % Version: 2.0 % Date: 12 April 2002 % Print "[Taxes.q, 12/Apr/2002 by Eric Wald]" % Print "[ SafeTaxAll, SafeTax, TaxYield]" CreatePlanetProperty Natives.Taxed CreatePlanetProperty Colonists.Taxed Shared Tax.Native, Tax.Colonist, Tax.Hissers, Tax.File % Maximum number of turns to leave a population untaxed Shared Tax.MaxTurns = 2 % Reload scripts, in case they have been edited. % "ScriptDir" should be a shared variable % containing the directory where this file is located. Sub Tax.Reload TryLoad 'Taxes.q' If Not IsEmpty(ScriptDir) Then TryLoad ScriptDir & 'Taxes.q' EndIf EndSub % Run SafeTax on all of my planets Sub SafeTaxAll Tax.File := FreeFile() Local fn := "Tax_p" & My.Race$ & ".txt" Open fn For Output As #Tax.File Print #Tax.File, "SafeTax Recommendations for ", My.Race.Full, " (Turn ", Turn, ")" Print "===== Changing All Taxes =====" ForEach Planet Do If Owner$=My.Race$ Then SafeTax Print "Recommendations logged in ", fn Close #Tax.File Tax.File := Zap(0) % Let the user correct specific planets Try Tax.Corrections EndSub Sub Tax.Print (line, Optional quiet) If IsEmpty(Zap(Quiet)) Then Print line If not IsEmpty(Tax.File) Then Print #Tax.File, line EndSub Sub GrowthTaxAll Tax.File := FreeFile() Local fn := "Tax_p" & My.Race$ & ".txt" Open fn For Output As #Tax.File Print #Tax.File, "GrowthTax Recommendations for ", My.Race.Full, " (Turn ", Turn, ")" Print "===== Changing All Taxes =====" ForEach Planet Do If Owner$=My.Race$ Then GrowthTax Print "Recommendations logged in ", fn Close #Tax.File Tax.File := Zap(0) % Let the user correct specific planets Try Tax.Corrections EndSub % Set the taxes to bring everyone to 71% happiness % Must be called from Planet context Sub SafeTax Tax.Print "", True If Owner$ <> My.Race$ Then Return If Colonists <= 0 Then Tax.Print Name & " has been Orphaned!" Return EndIf Tax.GetHissers SafeTax.Natives SafeTax.Colonists Tax.PrintYield EndSub Sub Tax.GetHissers Tax.Hissers = 0 If My.Race.Id = 2 and Cfg("AllowHiss") Then ForEach Ship Do If Orbit$=Planet.ID and Owner$=2 and Mission$=9 and Cargo.N>0 Then Tax.Hissers := Tax.Hissers + 1 Tax.Print " Hissing " & Planet.Name & ": " & Comment EndIf Next Else ForEach Ship Do If Orbit$=Planet.ID and Owner$=2 and Beam.Max>0 Then Tax.Hissers := Tax.Hissers + 1 EndIf Next If Tax.Hissers > 0 Then UI.Message ("How many ships will hiss " & Name & "?"), ("SafeTax " & Name), (If(Tax.Hissers > 5, "More ") & If(Tax.Hissers > 4, "5 ") & If(Tax.Hissers > 3, "4 ") & If(Tax.Hissers > 2, "3 ") & If(Tax.Hissers > 1, "2 ") & "1 0") Tax.Hissers := 1 + Tax.Hissers - UI.Result EndIf If Tax.Hissers > 0 Then Tax.Print " Hissing " & Name & ": " & Tax.Hissers & " Lizard" & If(Tax.Hissers > 1, "s") EndIf EndSub Sub SafeTax.Natives If Not Natives Then Return If Natives.Race$ = 5 Then % Amorphs don't generate money, don't respond to Hissing, % and aren't limited in their growth by taxes. % Just keep them happy to limit clan eating. Natives.Tax := 0 Tax.Native := 0 Else % Deliberately let the new happiness go too low Do While (Natives.Happy$ + Natives.Change$) > (70 - 5*Tax.Hissers) and Natives.Tax < 100 Natives.Tax := Natives.Tax + 1 Loop % Then bring it up to mimimum for growth % Allow one extra happiness point; less money, % but less risk of unhappiness due to structures or rounding Do While (Natives.Happy$ + Natives.Change$) < (71 - 5*Tax.Hissers) and Natives.Tax > 0 Natives.Tax := Natives.Tax - 1 Loop % Raise it to the minimum for the same credit Yield TaxYield Local maxtax := Tax.Native Do Natives.Tax := Natives.Tax - 1 TaxYield Loop While (Tax.Native = maxtax and Natives.Tax > 0) If Tax.Native < maxtax Then Natives.Tax := Natives.Tax + 1 EndIf EndSub Sub SafeTax.Colonists % Deliberately let the new happiness go too low Do While (Colonists.Happy$ + Colonists.Change$) > (70 - 5*Tax.Hissers) and Colonists.Tax < 100 Colonists.Tax := Colonists.Tax + 1 Loop % Then bring it back up Do While (Colonists.Happy$ + Colonists.Change$) < (71 - 5*Tax.Hissers) and Colonists.Tax > 0 Colonists.Tax := Colonists.Tax - 1 Loop TaxYield % Raise it to the minimum for the same credit Yield Local maxtax := Tax.Colonist Do Try Colonists.Tax := Colonists.Tax - 1 TaxYield Loop While (Tax.Colonist = maxtax and Colonists.Tax > 0) If Tax.Colonist < maxtax Then Colonists.Tax := Colonists.Tax + 1 EndSub Sub GrowthTax Tax.Print "", True If Owner$ <> My.Race$ Then Return If Colonists <= 0 Then Tax.Print Name & " has been Orphaned!" Return EndIf If IsEmpty(Colonists.Taxed) Then Colonists.Taxed := 0 If IsEmpty(Natives.Taxed) Then Natives.Taxed := 0 If Natives Then Natives.Tax := 0 Colonists.Tax := 0 Tax.GetHissers CalcGrowth % Reasoning on whether to tax Natives: % 1) We may have already decided to tax them % 2) Tax if they have reached 100 happiness points % 3) Tax if no growth is possible, even at zero taxes % 4) Tax if the colonists limit tax collection % 5) Otherwise, tax if we have hit the maximum untaxed turns If (Natives.Taxed = Turn) OR (Natives.Happy$ >= 100) OR (Natives.Growth <= 0) OR (Natives.Taxed < Turn - Tax.MaxTurns) Then SafeTax.Natives TaxYield % Rig the test if colonists limit tax collection Natives.Taxed := If(Tax.Native < Colonists, Turn, 0) If Natives.Race$ = 2 Then % What shall we do about Bovinoids? EndIf TaxYield Else Tax.Natives := 0 EndIf % Reasoning on whether to tax Colonists: % 1) We may have already decided to tax them % 2) Tax if no growth is possible, even at zero taxes % 3) Don't tax if the colonists limit native collection % 4) Otherwise, tax if we have hit the maximum untaxed turns If (Colonists.Taxed = Turn) OR (Colonists.Growth <= 0) OR (Tax.Native < Colonists AND (Colonists.Taxed < Turn - Tax.MaxTurns)) Then SafeTax.Colonists If Colonists.Tax > 0 Then Colonists.Taxed := Turn EndIf Tax.PrintYield EndSub % Print the results of TaxYield for the planet of the context Sub Tax.PrintYield CalcGrowth TaxYield Local line:= If(Colonists.Tax < 10, " ") & Colonists.Tax & "% on " line:= line & String(Abs(5-Len(Str(Colonists)))) & Colonists line:= line & " Colonists at " & Name & String(Abs(15-Len(Name))) line:= line & (" ->" # String(Abs(4-Len(Str(Tax.Colonist)))) # Zap(Tax.Colonist) # " mc") Tax.Print line line:= " (Taxed = " & Colonists.Taxed & " Temp " & Temp$ & " -> +" & Colonists.Growth & If(Colonists.Growth = 1, " Clan)", " Clans)") Tax.Print line, True If Natives Then line:= If(Natives.Tax < 10, " ") & Natives.Tax & "% on " line:= line & String(Abs(5-Len(Str(Natives)))) & Natives & " " line:= line & Natives.Race & String(Abs(10-Len(Natives.Race))) line:= line & " at " & Name & String(Abs(15-Len(Name))) line:= line & (" ->" # String(Abs(4-Len(Str(Tax.Native)))) # Zap(Tax.Native) # " mc") Tax.Print line line:= " (Taxed = " & Natives.Taxed & " Temp " & Temp$ & " -> +" & Natives.Growth & If(Natives.Growth = 1, " Clan)", " Clans)") Tax.Print line, True EndIf EndSub % Calculate the tax income for a planet % Must be called from a planet context % Doesn't account for no collection if happiness < 30, % or for Cyborg 20% maximum tax setting. Sub TaxYield If Owner$ > 0 Then Local maxmc = Cfg("MaxPlanetaryIncome") Local taxrate = Cfg("ColonistTaxRate", Owner$) Local natrate = Cfg("NativeTaxRate", Owner$) % PHost only If IsEmpty(natrate) Then natrate := taxrate If Natives and Natives.Race$ <> 5 Then Tax.Native := Round(Natives * Natives.Tax * Natives.Gov$ / 5000) If Tax.Native > Colonists Then Tax.Native := Colonists If Natives.Race$=6 Then Tax.Native := 2*Tax.Native Tax.Native := Round(Tax.Native * natrate / 100) If Tax.Native > maxmc Then Tax.Native := maxmc Else Tax.Native := 0 EndIf Tax.Colonist := Round(Round(Colonists * Colonists.Tax / 1000) * taxrate / 100) If Tax.Colonist + Tax.Native > maxmc Then Tax.Colonist := maxmc - Tax.Native EndIf EndSub CreatePlanetProperty Colonists.Had CreatePlanetProperty Colonists.Growth CreatePlanetProperty Natives.Had CreatePlanetProperty Natives.Growth % Calculate the amount of growth by next turn. % This routine still has a number of bugs, mostly noted. Sub CalcGrowth % Includes Tim's 3.14 in Degrees, combined with the division by 100 Local SinT = Sin(1.79909*(100-Temp$)) Local TempDep = SinT % Crystalline Desert Advantage If My.Race.ID = 7 AND Cfg("CrystalsPreferDeserts") Then TempDep := Temp$/100 Colonists.Had = Colonists Natives.Had = Natives If Colonists > (TempDep * 100000) Then % We should account for Arctic and Desert planets here, too... Colonists.Growth = 0 Else Colonists.Growth = Round( SinT * (Colonists/20) * (5/(Colonists.Tax+5)) ) EndIf If Natives.Race$ = 5 Then % Amorphs eat natives % This doesn't yet account for unhappy Amorphs eating more... Colonists.Growth := Colonists.Growth - 5 EndIf % Siliconoid natives have a different temperature dependence TempDep := If(Natives.Race$ = 9, (Temp$/100), SinT ) % Unfortunately, Siliconoids won't grow quite this high... If Natives > 0 and Natives < (TempDep * 150000) Then % Still doubles the growth sometimes, for no apparent reason Natives.Growth = Round( (Natives/25) * (5/(If(Natives.Race$=5,0,Natives.Tax)+5)) * TempDep / If(Natives > 66000, 2, 1) ) Else Natives.Growth = 0 EndIf EndSub Sub GrowthReport Local fd := FreeFile() Local fn := "Grow_p" & My.Race$ & ".txt" Local line Open fn For Output As #fd Print #fd, "Population Growth Report for ", My.Race.Full, " (Turn ", Turn, ")" Print "Printing growth report in " & fn ForEach Planet Do If Owner$=My.Race$ Then Print #fd, "" Print #fd, Name, ": ", Temp$, " degrees; Colonists taxed at ", Colonists.Tax, "%, Natives taxed at ", Natives.Tax, "%" line := Colonists.Had & " colonists grew to " & Colonists line := line & " (Expected " & If(Colonists.Growth>0, "+") & If(IsEmpty(Colonists.Growth), 0, Colonists.Growth) line := line & ", Actual " & If(Colonists > Colonists.Had, "+") & (If(IsEmpty(Colonists), 0, Colonists) - If(IsEmpty(Colonists.Had), 0, Colonists.Had)) & ')' Print #fd, line If Natives Then line := Natives.Had & " " & Natives.Race & " grew to " & Natives line := line & " (Expected " & If(Natives.Growth>0, "+") & If(IsEmpty(Natives.Growth), 0, Natives.Growth) line := line & ", Actual " & If(Natives > Natives.Had, "+") & (If(IsEmpty(Natives), 0, Natives) - If(IsEmpty(Natives.Had), 0, Natives.Had)) & ')' Print #fd, line EndIf EndIf Next Close #fd EndSub