Programming
From PlanetsWiki
This page is dedicated to the development of 3rd party applications for use with VGA Planets 4.
Contents |
[edit] Overview
VGA Planets 4 is written in Power Basic by Tim Wisseman. Tim's site has some information on this topic here. He provides some sample code for Visual Basic 5.
When faced with the challenge of writing a tool for this software first you need to decide what programming language that you want to write it in. The simple approach would be to use the same language and version that Tim has to make sure that there are no incompatibilities or extra conversion steps that you will have to go through. You can program in other languages and hopefully you will find support for those here. Diplomat is written in Visual Basic 6. VGAP4Assistant is written in C.
[edit] V4Face2.dll
The V4Face2.dll gives you access to the ship (.spk) and race (.rce) files so that you can pull out their statistics and even their graphics.
[edit] CSV-Files
The Planets4 client allows to export the current data of a game as CSV Files.
[edit] VCR Files
You may want to have a look on the data format of VCR Files.
[edit] Ship Groups File
Private Type GroupType
nm As String40
Log As String40
count As Long
flag1 As Long 'Unused
flag2(1 To 200) As Long 'Unused
Item(1 To 500) As Long 'Object ID; 1 To 5000 in Planets Client v66
itemSerNum(1 To 500) As Long 'Object Serial number; 1 To 5000 in Planets Client v66
End Type
Private m_group(1 To 90) As GroupType
Public Sub SaveGroupData()
Dim sDir As String
Dim i As Long
Dim sA As String
Dim f1 As Long
sDir = exepath & "groups\s" & Trim$(Str$(fileList.GameSlot)) & "x" & Trim$(Str$(WAR.pNum)) & "\"
For i = 1 To 90
sA = sDir & "group" & Trim$(Str$(i)) & ".grp"
If m_booActive(i) Then
f1 = FreeFile
Open sA For Binary As #f1
Put #f1, 1, m_group(i)
Close #f1
End If
Next i
End Sub
[edit] Map File
1 to 96 Header info First 22 bytes = "VGA Planets 4 Map File"
97 To 100 File Version (ASCII NUM)
101 LONG Count of Number of Planets
105 LONG Pointer to start of (X,Y,STAR)
109 LONG Pointer to start of NAME LIST
a$ = "VGA Planets 4 Map File"
a$ = LEFT$(a$ + head$, 96) + " "
x1map = 150
x1name = x1map + 50 + count * 6
f2 = FREEFILE
OPEN outfile FOR BINARY AS #f2
PUT #f2, 1, a$
a$ = "0001"
PUT #f2, 97, a$
PUT #f2, 101, count
PUT #f2, 105, x1map
PUT #f2, 109, x1name
pt = x1map
FOR i = 1 TO count
PUT #f2, pt, xPlanet(i)
pt = pt + 2
PUT #f2, pt, yPlanet(i)
pt = pt + 2
PUT #f2, pt, starPlanet(i)
pt = pt + 2
NEXT i
pt = x1name
FOR i = 1 TO count
x1 = (i - 1) * 40 + 1
GET #f1, x1, nmPlanet
PUT #f2, pt, nmPlanet
pt = pt + 40
NEXT i
CLOSE #f2
[edit] Source Code
Many VGAP programmers have released their source code to the public. This code contains a wealth of information about how to interact with game files. The code can also be a big time saver for new projects, since effective libraries for manipulating game data have already been developed and can be reused.
The following projects have made their source code available to the public:
- Diplomat
- Web Site: http://www.furfur.demon.co.uk/geop/diplomat.htm
- Source Code: Request from author
- Language: Visual Basic 6
- Reusable Code: ?
- Author's Notes: Diplomat is a combat simulator. It writes a script based on the user's choices, then runs Tim's programs Master.exe to create a customised mini-game with all the ships etc in one spot, runs Host.exe to resolve battles, and VCR.exe to show you the results. Inspecting the code would give you examples of how to use Tim's DLL's to extract race and hull info from files; how to call external programs like Master.exe; and probably how NOT to write VB! It's only the second program I ever wrote in VB, to teach myself, and people kept suggesting features. As a result it grew organically and is poorly structured spaghetti! The source code comprises about 20 forms, 4 modules, 3 classes, or to put it another way, almost 2MB. The code has been inspected and improved by several others already, notably Declan O'Connor. Most contributors change one to three modules and send them back to me. I control the master copy to avoid diverging threads, but I have deposited backup copies with a couple of folk lest I disappear. The code is heavily commented with tips from Tim and my own thoughts, and this could provide insights into how Tim's own code works. Diplomat updates are rare these days as it does everything I need now, but I am currently tinkering with a couple of minor things that no longer match the latest game rules, like the ground assault simulator.
- ScriptZ0r
- Web Site: http://webpages.charter.net/kgnorris/ScriptZ0r.html
- Source Code: http://webpages.charter.net/kgnorris/scriptz0rsource.zip
- Language: Visual C++ 6, using MFC
- Reusable Code: Interacting with v4face2.dll, possibly script parsing/generating code
- Author's Notes: It's ugly! It's unsupported! Beware!
- VidiVici
- Web Site: http://webpages.charter.net/kgnorris/vidivici.htm
- Source Code: http://webpages.charter.net/kgnorris/VidiViciSource.zip
- Language: C# (.NET version 1.1)
- Reusable Code: Interacting with v4face2.dll, parsing CSV files
- Author's Notes: I was very focused on reuse when designing many of the classes in this project, so there should be lots of easy-to-use stuff in there (provided you can find it :)). I'm happy to provide assistance/examples if needed.
- VGAP4Grp
- Web Site: VGA Planets 4 Ship Group Editor
- Source Code: VGA Planets 4 Ship Group Editor
- Language: C
- Reusable Code: ?
- Author's Notes: The objective was a very simple and quick command line interface. It could be used as sample code, if nothing else.
