% % Revive PCC % % This script attempts to save and restore the current status of % PCC between sessions. Hence you can exit PCC, do something else, % and when you start PCC again, you'll be where you left off last % time. % % In addition, this script provides a hook "NewTurn" which is run % when a new turn has started. % % This script is far from complete. % % Usage: put `Load "revive.q"' in your autoexec/gameinit script. The % rest is automatic. By default, this will also load the saved status % when the turn number changed. If you don't want it to do that, % do `Revive.LoadOldTurn := False' after the load instruction. % % History: % + 22/Aug/2001 basic infrastructure % + 15/Dec/2001 save starchart position % + 08/Dec/2002 save selection % + 11/Dec/2002 "NewTurn" % % Note 15/Feb/2005: the NewTurn hook is now provided by the PCC core. % You do no longer need this module to use that hook. However, PCC's % core.q contains provisions that these two do not interfere (it % makes sure the hook is called only once during each load). % Print "[revive.q 11/Dec/2002]" If Not System.GUI Then Print "Revive: not loading; not in GUI mode" Return EndIf Shared Revive.LoadOldTurn = True Sub Revive.Save Local fd Print "Revive: saving status..." Try fd := FreeFile() Open System.GameDirectory & "status" & My.Race$ & ".cc" For Output As #fd Print #fd, "%" Print #fd, "% File written by `revive.q' for turn ", Turn, " (", Turn.Date, ", ", Turn.Time, ")" Print #fd, "%" Print #fd Print #fd, "Revive.CheckTurn '", Turn.Date, Turn.Time, "'" Print #fd Print #fd, "Chart.X := ", Chart.X Print #fd, "Chart.Y := ", Chart.Y Print #fd, "If 0 Then % BEGIN-SELECTION" SelectionSave fd Print #fd, "}" Print #fd, "EndIf" Print #fd, "Revive.LoadSelection" Close #fd Else Messagebox "Could not save status.", "Error" Try Close fd EndTry EndSub % This is a hack. Instead of making two files, we store the selection % directly in the status.cc file, and "comment it out" using an If. % I guess this will not work in PCC II. Sub Revive.LoadSelection Local fd := FreeFile(), s Try Open System.GameDirectory & "status" & My.Race$ & ".cc" For Input As #fd Do Input fd, s Loop While Instr(s, "BEGIN-SELECTION") = 0 SelectionLoad fd, "at" EndTry Try Close fd EndSub Sub Revive.Load Local Revive.RunHook := False % Note that this must be a multiline Try, one-line Try doesn't work % here in 1.1.3 and below :-( Try Load System.GameDirectory & "status" & My.Race$ & ".cc" EndTry If Revive.RunHook Then Print "Revive: new turn has started..." RunHook NewTurn EndIf EndSub Sub Revive.CheckTurn (ts) If ts <> Turn.Date & Turn.Time Then Revive.RunHook := True If (Not Revive.LoadOldTurn) Then Print "Revive: not restoring status from `", ts, "'" Abort "-" EndIf EndIf Print "Revive: restoring status..." EndSub On Load Do Revive.Load On Exit Do Revive.Save