coding the game

I'm interested in making my own RTS/TBS game, sort of like Alpha Centauri. So I am wondering is you guys (Stardock) can give me some tips. I have a licensed 3D engine so I don't really need any advice in terms of graphics code. I want to know how you do the game database and game/database editor. Also, can you tell me how you create save game files and how you restore game from those files?
Do you use a script engine?

So far I got a simple landscape editor and a soldier, here's a screeny: http://64.60.177.194/screen.bmp
I'm using hexagon tiles. Everything is 3D.
347 views 24 replies
Reply #1 Top
We use lex & yacc to parse our input files. O'Reilly publishes a good book on the language if you're not familiar with it. We try to keep all in-game text in text files to make translating easier.

For save game files, we basically dump everything out to text files. If you want to make sure that your saved games are backwards compatible, the easiest way to do it (the way I did it for one of our other games, LightWeightNinja) was to use WritePrivateProfileString to write to a .ini file and GetPrivateProfileString and GetPrivateProfileInt to read them from the file. The limitation for this is that for Windows 9x and ME, you have to keep the files under 64K. Otherwise, C has several two output to file functions, fprintf and fwrite. fwrite can write arrays or structures to a file, and fprintf is a formatted print to a file.

For pathfinding, we use a modified version of the AStar algorithm.

www.gameinstitute.org has several on-line courses in game programming which you might find useful.
Reply #2 Top
that URL isn't working

Anyway I know a few good places myself:
www.gamedev.net
www.flipcode.com
www.ai-depot.com

For save game files I just dump everything in binary. And I got a special function to convert pointers into something writable and restorable. It works, except that when I add or remove variables I have to lose the save file or add special case checks.
Right now I need to work on movement. The path finding algorithm will need to work with different terrain types that effect movement, and I haven't even come up with all the terrain types I want to have. heh
Reply #3 Top
My suggestion is learn the data-application-ui model of prgramming. This allows AI's to be a "UI" and allows the AI to use the helper routines that players get and also allows a multiplayer option to be an addon later.

THis is how I've designed my 4X game to be if i ever get around to it.
Reply #4 Top
I'm also gonna go with something like that. First I make the game without AI and then just make AI play thru the regular player interface
Reply #5 Top
If you really want to be bleeding edge you can always look at using XML for save games, game options etc. XML can be used to Marshall and UnMarshall objects (class instances). This is now part of the java spec not sure about C++ as I mainly work with Java.
Reply #6 Top
and how would that deal with pointers?

I don't care for "bleeding edge" or "good efficiency" right now. It's hard enough just to make the sh*t work and do what I want it to do :-)
Reply #7 Top
totally off topic )but it gives u a bump ML :-)

where is stardock timezone wise etc - it is currently 12.30 after midnight in UK

s
Reply #8 Top
What 3d engine is that?
Reply #9 Top
steefodeevo,

SD is in the ET, that is -5 from GMT on standard time, -4 on daylight savings.
Reply #10 Top
I'm using www.powerrender.com

It's a 1 man project, but he's a real genius and real workaholic. The guy actually used to work on the Unreal engine before. And his stuff is pretty cheap.
Reply #11 Top
ML, I assume you were wondering how XML handles pointers. The useless but entirely correct answer is however you want it to.

XML is a relatively standard way of presenting data in a context sensitive manner. If you are familiar with the HTML file format, you know about 85% of what there is to know about XML.

Since you would be defining the format of the XML tags in your XML document, the handling of pointers is entirely at your discretion. Typically you can handle a pointer as either a nested set of tags, a back reference, or a forward reference.

There should be several XML readers/writers that you can find for C++ both comercial and open-source. I'm personally not real fond of XML (it seems very bloated by nature), but I can't think of a better alternative and it seems to be becoming an industry standard.
Reply #12 Top
what sort of advantage XML has over C++ implementation? I get the idea XML is getting more and more popular, but I'm reluctant to spend time learning things I don't really need. heh
My goal is to make an RTS game, the way I see it, it can be done entirely in C++. I know many games use scripting engines, but I don't see any big reasons for it. Just seems like extra hassle to me.
Reply #13 Top
XML is just a way of representing data.
The current GCTech.tech could be XML.

This is how one entry looks
//------------------------------------------------------------------------
TECH 1 UniversalTranslator
//------------------------------------------------------------------------
Name "Universal Translator"
Model ""
Tech_Requirement "CommunicationTheory"
Research_Cost 25
Overview "Dr. Edmund Phrinck, a professor of linguistics has a theory that the commonalities in all known languages can be synthesized into a complex set of equations that will enable humanity to almost instanteously translate all languages including those of any alien races. The 'Universal Translator' as he calls it will allow us to understand what other civilizations are saying, and communicate with them."
Description "Our scientists have been working long and hard on some method of communicating with the other races in this galaxy. The signals we have been receiving leave no doubt that they are aware of us. Communications with these civilizations has become a top priority.

It has been clear that our understanding of language structure does not apply to these non-human races' 'languages.' This translator is based on the belief that certain concepts are fundamental to any intelligent life form. By monitoring the electromagnetic and electrochemical activity of an individual, we should be able to translate at least certain basic concepts.

Critics contend that the basic assumptions for this device are too risky. Dr. Phrinck, from the Partners Research Center in New Capital City, believes that Terrans may be unique in having a central brain structure. 'It is arrogant presumption to assume all intelligent creatures store all their 'eggs' in one basket.' Dr. Phrinck said. 'For example, they may have their intelligence distributed throughout their body and not just in a certain area. Moreover, we can't assume that these beings are even humanoid. If these races are vastly different from us then this device will be useless. The odds of them being humanoid are pretty slim."
Tech_Category 4
Ability "Diplomacy"
ENDTECH

This is one way it could look in XML



Universal Translator
CommunicationTheory
25
Dr. Edmund Phrinck, a professor of linguistics has a theory that the commonalities in all known languages can be synthesized into a complex set of equations that will enable humanity to almost instanteously translate all languages including those of any alien races. The 'Universal Translator' as he calls it will allow us to understand what other civilizations are saying, and communicate with them.

Our scientists have been working long and hard on some
method of communicating with the other races in this
galaxy. The signals we have been receiving leave no doubt
that they are aware of us. Communications with these
civilizations has become a top priority. It has been clear
that our understanding of language structure does not apply
to these non-human races' 'languages.' This translator is
based on the belief that certain concepts are fundamental
to any intelligent life form. By monitoring the
electromagnetic and electrochemical activity of an
individual, we should be able to translate at least certain
basic concepts.

Critics contend that the basic assumptions for this device
are too risky. Dr. Phrinck, from the Partners Research
Center in New Capital City, believes that Terrans may be
unique in having a central brain structure. 'It is arrogant
presumption to assume all intelligent creatures store all
their 'eggs' in one basket.' Dr. Phrinck said. 'For
example, they may have their intelligence distributed
throughout their body and not just in a certain area.
Moreover, we can't assume that these beings are even
humanoid. If these races are vastly different from us then
this device will be useless. The odds of them being
humanoid are pretty slim.

4
Diplomacy



C++ has a lot of XML parsers available.
Microsoft supply one and there is an open source implemntation at http://xml.apache.org/xerces-c/index.html
The advantage is that you can describe a schema that you can use to validate the document. Also there are many XML editors that will use the schema so you can edit the document and be sure it is in the right format.

It just a neat way of representing data that is reasonable human readable.



Reply #14 Top
Ugh it messed up my xml :D

Lets see if this does better
<TECHS>
<TECH id="1" idName="UniversalTranslator">
<Name>Universal Translator</Name>
<Tech_Requirement>CommunicationTheory</Tech_Requirement>
<Research_Cost>25</Research_Cost>
<Overview>Dr. Edmund Phrinck, a professor of linguistics has a theory that the commonalities in all known languages can be synthesized into a complex set of equations that will enable humanity to almost instanteously translate all languages including those of any alien races. The 'Universal Translator' as he calls it will allow us to understand what other civilizations are saying, and communicate with them.</Overview>
<Description>
Our scientists have been working long and hard on some
method of communicating with the other races in this
galaxy. The signals we have been receiving leave no doubt
that they are aware of us. Communications with these
civilizations has become a top priority. It has been clear
that our understanding of language structure does not apply
to these non-human races' 'languages.' This translator is
based on the belief that certain concepts are fundamental
to any intelligent life form. By monitoring the
electromagnetic and electrochemical activity of an
individual, we should be able to translate at least certain
basic concepts.

Critics contend that the basic assumptions for this device
are too risky. Dr. Phrinck, from the Partners Research
Center in New Capital City, believes that Terrans may be
unique in having a central brain structure. 'It is arrogant
presumption to assume all intelligent creatures store all
their 'eggs' in one basket.' Dr. Phrinck said. 'For
example, they may have their intelligence distributed
throughout their body and not just in a certain area.
Moreover, we can't assume that these beings are even
humanoid. If these races are vastly different from us then
this device will be useless. The odds of them being
humanoid are pretty slim.
</Description>
<Tech_Category>4</Tech_Category>
<Ability>Diplomacy</Ability>
</TECH>
</TECHS>
Reply #16 Top
XML is a file format.
C++ is a programming language.

XML by itself does nothing, it is just a way of presenting data. XML is not a scripting language, it is used as a standard format for serializing data due to the structured layout of a properly laid out XML file.

Your implentation of the game should be done in a high level language (i.e. C++, Java, C#). C++ is currently the standard language for programming games, though there are people starting to develop them in Java and C#.

Since your question was dealing with things related to data serialization, you may want to spend the 5-10 minutes to get an overview of XML to determine if that is right for you.
Reply #17 Top
ok, I read about it, looks interesting. But this kind of stuff is more suited for large text databases rather than a game database. There are efficiency issues. Too much hassle to use XML in RTS game. heh
Reply #18 Top
The point of XML is that you don't have to hand parse it--XML parsing tools and built-in XML serialization features mean that you can quickly read object state data in and out without writing your own field-at-time input/output code. In .Net, you can serialize objects to XML practically without writing any code at all! And if you think about it, a text database is exactly what you want. And XML is not really going to be any slower than any other method of reading and writing info to and from the disk, especially if is restricted to reading in at program launch and reading out when the user chooses to save their game.

Having said that, I work with .Net everyday, and I'm not sure it is up to the kind of critical performance that a real-time strategy game may require, mainly due to the overhead of "managed code" error-checking and the garbage collector. You could use non-managed code (which allows stuff like pointer arithmetic and doesn't use the GC), but you lose the best features of the .Net environment. And there is yet no way to interface with DirectX, though that is supposedly coming.

For similar reasons, Java is probably equally ill-suited for this kind of game, even with a compiler.

So, sadly, C++ is probably the only way to go, but look into what XML parsing tools allow you to do before rejecting it based on one look.

Also, XML-based web services (where, again, with the right tools, object serialization is basically free), would be a great way to add multi-player capabilities to your game without building your own network protocol.

-Robert
Reply #19 Top
Also XML would only be used for configuration, load/save games. This is not really critical code performance wise. By that I do not mean that performance does not matter but that you do not need to get into hand optimization that you can need in the main processing loop when the game is running.
Reply #20 Top
From my first look at XML, I didn't find any links to XML processor tools or API. I just read something about DOM being the processor but not how I'm supposed to integrate it with my C++ code.
Reply #21 Top
Java is too slow for games
Reply #22 Top
This is the programming guide for Xerces.
http://xml.apache.org/xerces-c/program.html

Microsoft have a similar guide for there XML parser.
Search msdn.microsoft.com

Basically you can create a Document Object Model (DOM) that represents the XML file. Then use variuos methods to access the DOM to read particular data.


Reply #23 Top
looks interesting. Maybe I'll try use XML in future projects. Right now I just don't want to spend time learning it and then rewriting my current methods.
Reply #24 Top
'Java is too slow for games'

Not necessarily. It depends on what sort of game you're trying to make.

For a 4X game, it almost certainly would be, but it would work almost perfectly for board games like chess, or for Roguelikes, or any of a number of other games.