qcs

development status
stability
access

overview

This is the base-class for mbotbase, which is the base for all the AI classes. Most of the nasty stuff in this class is hidden by funcions in mbotbase, but you should be familiar with some the the member functions/variables:
serverinfo info
This contains usefull stuff like .maxPlayers. Its description is in the other section.

qentity entities[ QCS_MAX_ENTITIES ]
This array contains information about every entity in the game (note that only the currently visible ones get updates). Information about visibility and entity-type is available from mbotbase in the form of the mbotbase::isVisible(), mbotbase::isAmmo(), etc. functions. The description of qentity is in other, but the most useful members are .origin, .velocity and .facing which are all vectors.

All of the virtual functions
These functions should all be overriden somewhere (they are all overriden already, but if you write your own AI classes, instead of using my skeletons, you will have to be aware of where they are overriden). Their funtions are pretty self-explanatory (i.e. qcs::updateEntity())

options opts
This is a hash table for easy flag addition. opts.get("mikeBot-flag") returns an integer, while opts.set( "mikeBot-flag", 123 ) sets a flag to an (integer) value. Zero (0) is returned if a flag doesn't exist (hasn't been .set).

member variables

class qcs
{

private:
  qsocket  * sock;
  char currentServerIP[ Q_MAX_STRING ];


protected:

  options opts;

  char qcs_botName[ 80 ];
  int qcs_botPants;
  int qcs_botShirt;
  char * qcs_lastrule;

  qproxy * proxy;

  FILE * demoFP;
  int demoPauseState;

  char qcs_message[ 4096 ];

  vector facing;
  vector fireParticle, navParticle;
  
  qpacket inPacket;
  qpacket outPacket;
  qpacket * fragments;
  qpacket prespawns1;
  qpacket prespawns2;
  qpacket prespawns3;

  int outgoingUnreliable;
  int outgoingReliable;		
  int incomingReliable;		
  int incomingUnreliable;	

  int haveConnection;	

  qack ackQueue;

  serverInfo info;		
  char * result;		

  float newTimestamp;
  float oldTimestamp;
  int signonLevel;	
  int myEntityNumber;	

 
  char * modeltable[ QCS_MAX_MODELS ]; 
  char * soundtable[ QCS_MAX_SOUNDS ]; 
  char m_modeltypes[ QCS_MAX_MODELS ]; 
  char modeltypes[ QCS_MAX_MODELS ];   
  char m_soundtypes[ QCS_MAX_SOUNDS ];
  char soundtypes[ QCS_MAX_SOUNDS ];    

  qentity entities[ QCS_MAX_ENTITIES ];
  qplayer players[ QCS_MAX_PLAYERS ];	


public:

};
sock
NULL if the socket is invalid. All packets are sent through here.
currentServerIP
The address/name of the current server (i.e. 127.0.0.1 or quake.server.ca)
opts
A hash-table of integer values accessed with strings (i.e. opts.get( "flag-name" ))
qcs_botName, qcs_botPants, qcs_botShirt
Current values for name, shirt and pants colour.
qcs_lastrule
Used for getting the rules from a server when not connected. Use qcs::printRules()
proxy
The listen/update class for any observers.
demoFP
If non-NULL, all server-to-client packets are written to this, formatted appropriatly. If demoPauseState is TRUE, the packet is not written.
demoPauseState
Pauses/unpauses a demo recording, without the need to start a new file.
qcs_message
This message is appended as a center-printed message to every packet before being written to a file. Very useful for putting status/debugging information into your .DEMos. Any classs below qcs can write into this.
facing
The facing to write to demo packets, and the facing which observers are locked to by default. Set this in mbfire, for example, to lock the .DEMo and observer view to mbfire's
fireParticle, navParticle
These origins will emit particles in .DEMos. I use them to mark fire and nav targets, but you can do whatever you want with them.
inPacket, outPacket
To cut down on qpacket constructor/destructor calls, these packets are used for outgoing and incomming packets, respectivly.
fragments
This is a packet big enough to hold a few. Use to assemble qpacket::reliableFragments before decoding.
prespawns1, prespawns2, prespawns3
fragments is copied into these if it contains a SIGNON command. These packets are used to start recording part-way through a level, and for connecting observers.
outgoingUnreliable, outgoingReliable, incomingReliable, incomingUnreliable
These are packet counts in order to reject late incomming packets and properly number outgoing packets.
haveConnection
TRUE if the server has sent an ACCEPT control packet. Doesn't reflect the signon level.
ackQueue
This handles waiting for outgoing reliable packet acknowledges, and resending unacknowledged packets.
info
Holds information about the current level/players. It is updated by both qcs::decodeControl and qcs::decodeMessages.
result
Holds the string for the last result of a connect request. If it is NULL, the last message was an accept (if haveConnection is TRUE). Use qcs::connect() to connect, however.
newTimestamp, oldTimestamp
newTimestamp holds the last timestamp received from the server. Warnings are issued if oldTimestamp > newTimestamp, but packets are not discarded (I think they should be...)
signonLevel
Reflects how far along the signon process is. If signonLevel == 3, you should be sending unreliable client-to-server updates. (mbot does this for you)
modeltable, soundtable
Holds the file names for precached models and sounds. Send during signon 1.
m_modeltypes, m_soundtypes
major model/sound types (i.e. Ammo, Health, etc)
modeltypes, soundtypes
minor model/sound types (i.e. nailGunAmmo, 15% health, etc.)
entities
Tracks all the entities in the game. Only visible entities receive updates, but the positions for stationary entities like health (should) always be valid.
players
Info. on all players in the game. Only entries up to info.maxPlayers-1 are valid.

member functions

class qcs
{


private:
  qcs( qcs & ){}


protected:

  int decodeControl( qpacket & );
  int decodeReliable( qpacket & );
  int decodeUnreliable( qpacket & );
  int decodeAcknowledge( qpacket & );
  int decodeQPacket( qpacket & );
  int decodeMessages( qpacket & );

  int send( qpacket & );

  void initTables();	
  void deleteTables();
  void updateTableTypes();


public:

  qcs();
  virtual ~qcs();

  void changePort( int );

  void reinit();

  int sendKeepalive();
  int sendDisconnect();
  virtual int sendMovement();
  int sendConsole( char * );

  int getSignonLevel()

  int update();

  int updateProxy()
  int proxyConnected()
  void sayProxy( char * )
  void proxyDump()
  void proxyKickClient( int )
  void proxyDestroyClient( int )

  int getFD()
  char * connect();
  void disconnect();

  int recordDemo( char * );
  int stopDemo();
  int pauseDemo()
  int unpauseDemo()
  int waitForPacket()

  int server( char * ip, int port = 26000 );
  void name( char * )
  void pants( int )
  void shirt( int )


  int connected()
  int recording()
  
  void printInfo();
  void printPlayerInfo( int );
  void printAllPlayers();	
  void printRules();		
  void printLevel()
  void rankings();

  virtual void changedLevel( char * )
  virtual void consoleCommand( char * )
  virtual void entityUpdated( int )
  virtual void entityChanged( int )
  virtual void timestampChanged( float )
  virtual void playerstateUpdate( int, int )
  virtual void gotSayMessage( char * x )
  virtual void receivedDamage( int, vector & )
  virtual void centerPrint( char * )

  virtual void updateHealth( int )
  virtual void updateArmour( int )
  virtual void updateCells( int ) 
  virtual void updateShells( int )
  virtual void updateRockets( int )
  virtual void updateNails( int )
  virtual void updateWeapon( int )
  virtual void updateItems( int )


};

qcs( qcs & )
There is no copy constructor.
decodeControl, decodeReliable, decodeUnreliable, decodeAcknowledge
Decodes the respective packet types.
decodeQPacket
Calls the appropriate decode function
decodeMessages
This decodes the data part of all Unreliable and Reliable packet types.
send
Sends all types of packets. If the packet is reliable, it inserts it into the reliable queue.
initTables, deleteTables
Readies the m_modeltypes, modeltypes, m_soundtypes, soundtypes, modeltable and soundtable tables.
updateTableTypes
Figures out the types for m_modeltypes, modeltypes, m_soundtypes, soundtypes based on the values in modeltable, soundtable.
qcs, ~qcs
constructor, destructor. Ctor does not try to open a socket; you must use qcs::server()
changePort
Changes the socket port.
reinit
Frees all memory, then reallocates it.
sendKeepalive, sendDisconnect, sendConsole
Send the expected packets to the server. sendConsole needs a newline at the end of the string passed.
sendMovement
This is overriden by mbot, since qcs doesn't have enought information about the bot's facing, etc. This may change
getSignonLevel
Returns the current signon state (1, 2 or 3)
update
Tries to read the socket and decodes any data read.
updateProxy
Allows the proxy to have a go at reading its socket(s)
proxyConnected
Returns the number of connected clients.
sayProxy
Sends the string as a say command to all connected proxys
proxyDump
Prints all connected proxys, their addresses and ports
proxyKickClient
Sends a "disconnect" command to the client. Will not work if the client crashed or stoped sending packets. Also sends a "proxyVision kicked you" message.
proxyDestroyClient
This is the nasty way to disconnect a client; just stops sending packets.
getFD
Returns the filedescriptor used by the socket. Useful for select()ing before calling qcs::update()
connect
Attempts to connect to the server. Tries QCS_MAX_TRIES times, waiting QCS_MAX_TIMEOUT seconds on each attempt. NULL is returned if the connect was succesful, or a string explaining why the connect failed (i.e. "Server full." or "No responce.")
disconnect
Disconnects from server. The dtor calls this.
recordDemo
(Tries to) open the file for recording. You can start recording at any point in the level.
stopDemo, pauseDemo, unpauseDemo
Stops recording, pauses recording and unpauses recording.
waitForPacket
THIS WILL BLOCK FOR QCS_MAX_TIMEOUT SECONDS; it is meant to wait for control packets when querying the server. Don't use it when connected.
server
Changes the server to use. Any address form is valid (i.e. 127.0.0.1 or quake.frag.ca) but address like quake.server.ca:26000 are not; use the port argument instead.
name, pants, shirt
Changes the bot's name, pant colour and shirt colour. These will send console command to change the colours, etc. if connected.
connected, recording
Returns TRUE if connected or recording, respectivly.
printInfo, printPlayerInfo, printAllPlayers, printRules
Sends control packets requesting the information, then prints it. DO NOT USE WHEN CONNECTED.
printLevel
Prints the name of the current level and its filename
rankings
Prints all active players and frags.
virtual functions
These functions should be overriden (they are all overriden in the classes provided here. Most are overriden in mbotbase). They all indicate the event their name describes. See the mbotbase source for more.

This page is copyright
© 1997 Mike Warren
All rights reserved.