View Single Post
koraXs XML/INI/CFG parser for your bot
Old
  (#1)
koraX
Member
 
koraX's Avatar
 
Status: Offline
Posts: 145
Join Date: Jan 2004
Location: Slovak Republic
Default koraXs XML/INI/CFG parser for your bot - 29-07-2004

Well I made some nice program which I will use in my bot for CS, so why not to share it with you

koraXs parser is program which enables you to work with XML, INI and CFG files, easily retrieve and edit parameters, add new ones and export them to XML, CFG or INI

note : If it's not obvious, this is for bot coders, not players

Supporting INI files like ones in Unreal tournament, CFG files like ones in Half-life, and XML 1.0 specification. Both import and export
  • free. Licensed under GNU/GPL
  • you will only need ANSI C++ compliant compiler (tested under GCC, MSVC 6.0, MSVC .NET)
  • detailed online documentation

Features :
  • Import/Export from/to XML, INI or CFG
  • Powerful query search
  • Woking quickly in bot (tested in CS), has no problem with big xml files (over megabyte)
  • Creating new elements and attributes
  • Deleting elements and attributes
  • Changing elements/attributes properties : name, value and comment
  • Special fuctions : Copying, moving and swaping elements/attributes
  • WYSIWYG editor included, supporting most features of koraXs parser

Very easy usage :

Imagine we have following XML file :

Code:
<?xml version="1.0"?>
<kxbot version="1.0" date="07.21.2004">
	<!-- first bot, very ghey -->
	<bot>
		<name>Frodo</name>
		<mod>CS</mod>
		<skill>
			<easy>10</easy>
			<medium>20</medium>
			<hard>30</hard>
		</skill>
		<skin>
			5
			<T>1</T>
			<CT>2</CT>
		</skin>
		<meta version="1.3" date="12.02.1995"/>
	</bot>
	<!-- this bot is slow -->
	<bot>
		<name>Sam</name>
		<mod>CS</mod>
		<skill>
			<easy>20</easy>
			<medium>20</medium>
			<hard>60</hard>
		</skill>
		<skin>
			5
			<T>3</T>
			<CT>3</CT>
		</skin>
		<meta version="1.0" date="12.03.1995"/>
	</bot>
	<game version="1.5"/>
</kxbot>
Just load 2 source files into your project and you can fully use koraXs parser. Example of simple program using koraXs parser :

PHP Code:
#include "params.h"

using namespace std;

int main() 
{
    
Par::CParams par;

    
// load XML file into the memory
    
if(par.loadXML("xml-example-1.xml")==false)
    return -
1;

    
// This will return name of the first bot in list
    
cout << par.getval("bot/name") << endl// Frodo

    
return 0;


C friendly :

You don't know C++ well ? No problem, you can easily use koraXs parser with your C skills. The previous example in C friendly way :

PHP Code:
#include "params.h"

int main() 
{
    
Par::CParams par;

    
// load XML file into the memory
    
if(!par.loadXML("xml-example-1.xml"))
    return -
1;

    
// This will return name of the first bot in list
    
printf("%s\n",par.getval("bot/name").c_str()); // Frodo

    // NOTE if you are not using STL, you can retrieve 
    // simple char * strings by .c_str() function like shown above

    
return 0;


Load file on begining of session or when bot spawns (if you have separate configuration files for each bot), and then you can easily access contents of this file with get() functions. No need to create your own variables for each parameter. All content of file is already in memory.


Powerful search :

You want to search in xml file for name of bot, who has skill 10 and does not have skin 3 or 5 ? You can do it in one function :
PHP Code:
// C
char name[1000];
strcpy(name,par.getval("bot/skill/easy='10'^^skin/CT!='3'|'5'^^name").c_str());

// or nicer in C++
string name=par("bot/skill/easy='10'^^skin/CT!='3'|'5'^^name"); 
You can learn more about query searching in online documentation, where you can also find complete reference, examples an much more

Info and download :

Right here (900kB)



If you have any questions, ask here, on my forum or e-mail me


kXBot
koraX's utils
- see my homepage for other projects (OpenGL CSG Editor, FAT16 Sim, NNetwork Sim, ...)

Last edited by koraX; 29-07-2004 at 19:31.. Reason: updating
  
Reply With Quote