% % TARGETx.DAT I/O % % This (silly?) script creates TARGETx.DAT files. Note that this does % not directly affect display in PCC. % % + `tgt.ReadFile "name"' loads a target file into memory (i.e. % TARGET3.DAT) % + `tgt.Generate' generates targets for all ships seen on the map. % + `tgt.WriteFile "name"' writes a target file. % + `tgt.Clear' clears working space. % + `tgt.Merge' merges all targets from all players. % % Possible uses: % tgt.ReadFile 'my\ally\target1.dat' % tgt.Generate % tgt.WriteFile dir & 'target' & My.Race$ & '.dat' % creates a file containing all the ships from your turn, and those % which your ally sees. When you exit and reload PCC, you'll see them % all. % For i:=1 To 11 Do % Try tgt.ReadFile dir & 'target' & i & '.dat' % Next % tgt.WriteFile dir & 'target' & My.Race$ & '.dat' % snarfs all targets from the other players into your file. `tgt.Merge' % does approximately this. % % (note that in the above examples, `dir' should be % `System.GameDirectory'). % Print "[target.q 17/Aug/2001]" CreateShipProperty TargetStr % Read a target file into working space. Sub tgt.ReadFile (name) Local s, count, i, id Open name As #1 For Input Get #1, s, 2 count := GetWord(s, 0) For i:=1 To count Do Get #1, s, 34 % 34 is size of one target id := GetWord(s, 0) Try Ships(id).TargetStr := s % automatically fails on range error Next Close #1 Print count, " targets read from ", name EndSub % Generate targets for ships we're currently seeing. Sub tgt.Generate Local s, i i := 0 ForEach Ship Do If Hull$ Then SetWord s, 0, Id, Owner$, If(IsEmpty(Speed$), 0, Speed$), Loc.X, Loc.Y, Hull$ If Not IsEmpty(Heading$) Then SetWord s, 12, Heading$ Else SetWord s, 12, -1 EndIf SetStr s, 20, 14, Name TargetStr := s i := i+1 EndIf Next Print i, " targets created" EndSub % Clear working space Sub tgt.Clear Local i For i:=1 To 999 Do Ships(i).TargetStr := Z(0) EndSub % Write target file Sub tgt.WriteFile (name) Local id, count = 0, s Open name As #1 For Output SetWord s, 0, 0 Put #1, s, 2 % reserve two bytes For id:=1 To 999 Do If Ships(id).TargetStr Then count := count+1 Put #1, Ships(id).TargetStr, 34 EndIf Next SetWord s, 0, count Seek #1, 0 Put #1, s, 2 Close #1 Print count, " targets written to ", name EndSub Sub tgt.Merge (Optional name) Local i tgt.Clear For i:=1 To 11 Do Try tgt.ReadFile System.GameDirectory & "target" & i & ".dat" Try tgt.ReadFile System.GameDirectory & "target" & i & ".ext" Next tgt.Generate If IsEmpty(name) Then name := System.GameDirectory & "target" & My.Race$ & ".ext" tgt.WriteFile name EndSub