% % Simple Turn Checker % % Load your game into PCC and use the command `Check' to locate % (possible) errors in your turn. They'll be reported to the console. % What to be an error worth reporting can be configured with the % `Check.WarnLevel' variable; with `Check.Correct' set, this % program will also attempt to fix some of the errors. The preferred % way to set those variables is by placing appropriate assignment % statements in your autoexec script: % Load "checker.q" % Check.WarnLevel := 2 % Note that these assignments only work after the script was loaded. % % To check only a single object, go to its control screen and do % `RunHook CheckShip' or `RunHook CheckPlanet', respectively. % % To add your own checks, write appropriate subroutines and make % them known to the checker framework using `On CheckShip Do...' etc. % % Configuration variable: only emit warnings at this level or higher % 0 = omissions (not really serious) % 1 = mistakes (might be dangerous) % 2 = errors (probably dangerous) % 3 = red errors (will be detected as cheats) Shared Check.WarnLevel = 0 % Configuration variable: if enabled, auto-correct some errors Shared Check.Correct = False Shared Check.CurObj % internal: current object or EMPTY % 03/Dec/2001 Initial version % 20/May/2001 Modified to use hooks (-> extensibility) % More checks/fixes % 05/Jun/2001 some fixes Print "[checker.q 05/Jun/2001]" % % Emit a warning at the specified level % Sub Check.Warn (LEVEL, TEXT) If LEVEL < Check.WarnLevel Then Return If Not IsEmpty(Check.CurObj) Then Print Check.CurObj, ":" Check.CurObj := Z(0) EndIf Print " ", TEXT EndSub % % Log that a problem has been corrected. TEXT, if specified, % says what was done. % Sub Check.LogCorrect (Optional TEXT) Print " -- corrected", " (" # TEXT # ")" EndSub % % Check current object (ship or planet) % Sub Check.CheckObject If FCode=String(3, Left(FCode, 1)) Then Check.Warn 1, "Silly FCode" EndIf EndSub % % Check current planet % Sub Check.CheckPlanet Local d If FCode="ATT" Or FCode="NUK" Then d := If(Defense.Base, Defense.Base, 0) If Defense + d < 10 Then Check.Warn 1, "`" & FCode & "' used on weak planet" EndIf If Colonists=0 Then Check.Warn 2, "orphaned planet" If Colonists.Happy$ + Colonists.Change$ <= 40 Then Check.Warn 2, "colonists overtaxed" EndIf If Natives.Happy$ + Natives.Change$ <= 40 Then Check.Warn 2, "natives overtaxed" EndIf EndSub % % Check current ship % Sub Check.CheckShip Local i % Movement order If FCode="HYP" And InStr(Hull.Special, "H")<>0 Then If Speed$=0 Or Waypoint.Dist<=20 Then Check.Warn 2, "Hyperdrive not really activated" If Speed$=0 And Waypoint.Dist>20 And Check.Correct Then SetSpeed 2 Check.LogCorrect "set to warp 2" EndIf If Cargo.N < 50 Then Check.Warn 2, "Not enough fuel for hyperjump" If (Waypoint.Dist<340) Or (Waypoint.Dist>360) Then Check.Warn 0, "No exact waypoint set" Else If Speed$=0 And Waypoint.Dist Then Check.Warn 2, "Waypoint set but no speed" If Speed$ 1 Then Check.Warn 2, "Could move faster" If Check.Correct And Fleet$=0 Then % Do not mess with fleet members. Fleet members/leaders have % to care for other members, and player probably already % did the Right Thing(tm). Do i := Speed$+1 SetSpeed i Loop While (Move.Eta > 1) And (Speed$ < Engine$) And (Speed$ = i) Check.LogCorrect "set to warp " & Speed$ EndIf EndIf EndIf If Speed$>Engine$ Then Check.Warn 1, "Overdriven" EndIf If Cargo.N < Move.Fuel Then Check.Warn 2, "Not enough fuel" EndIf % Cargo room If (Cargo.Free < 0) Or (Cargo.N > Cargo.MaxFuel) Or (Cargo.Money > 10000) Then Check.Warn 3, "Overloaded ship" % Damagedness If (Damage<>0) Or (Crew3) And (Mission$<>9 Or My.Race.Id<>7) And (Left(FCode,2)='md' Or Left(FCode,2)='mi') Then Check.Warn 1, "Mine-laying fcode but not `Lay Mines' mission" EndIf % Miscellaneous If Mission$=0 Then Check.Warn 0, "No mission set" If Check.Correct Then SetMission 1 Check.LogCorrect "set to `explore'" EndIf EndIf EndSub % % Check current base % Sub Check.CheckBase If FCode="dmp" Then If (System.Host$<>2) And Build.YesNo Then Check.Warn 1, "`dmp' will cancel build order" If (Storage.Hulls(0)+Storage.Engines(0)+Storage.Launchers(0)+Storage.Beams(0)=0) Then Check.Warn 1, "`dmp' used though no parts in storage" EndIf If IsEmpty(Build) Then Check.Warn 0, "Starbase has no build order" If StrCase(FCode>="PB0" And FCode<="PB9") Then Check.Warn 1, "Unneeded priority FCode" EndIf If Damage<>0 Then Check.Warn 0, "Starbase is damaged" If Fighters>60 Then Check.Warn 3, "Too many fighters in starbase" If Defense.Base=0 Then Check.Warn 1, "No starbase defense" If Fighters=0 Then Check.Warn 0, "No starbase fighters" EndSub % % Main routine % Sub Check ForEach Ship Do If Owner$=My.Race$ Then Check.CurObj := "Ship #" & Id RunHook CheckShip EndIf Next ForEach Planet Do If Owner$=My.Race$ Then Check.CurObj := "Planet #" & Id RunHook CheckPlanet EndIf Next EndSub On CheckShip Do Check.CheckObject On CheckShip Do Check.CheckShip On CheckPlanet Do Check.CheckObject On CheckPlanet Do Check.CheckPlanet On CheckPlanet Do If Base.YesNo Then Check.CheckBase