Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

aas_cfg.c

Go to the documentation of this file.
00001 /*
00002 ===========================================================================
00003 Copyright (C) 1999-2005 Id Software, Inc.
00004 
00005 This file is part of Quake III Arena source code.
00006 
00007 Quake III Arena source code is free software; you can redistribute it
00008 and/or modify it under the terms of the GNU General Public License as
00009 published by the Free Software Foundation; either version 2 of the License,
00010 or (at your option) any later version.
00011 
00012 Quake III Arena source code is distributed in the hope that it will be
00013 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 GNU General Public License for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Foobar; if not, write to the Free Software
00019 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00020 ===========================================================================
00021 */
00022 
00023 #include "qbsp.h"
00024 #include "float.h"
00025 #include "../botlib/aasfile.h"
00026 #include "aas_store.h"
00027 #include "aas_cfg.h"
00028 #include "../botlib/l_precomp.h"
00029 #include "../botlib/l_struct.h"
00030 #include "../botlib/l_libvar.h"
00031 
00032 //structure field offsets
00033 #define BBOX_OFS(x) (int)&(((aas_bbox_t *)0)->x)
00034 #define CFG_OFS(x) (int)&(((cfg_t *)0)->x)
00035 
00036 //bounding box definition
00037 fielddef_t bbox_fields[] =
00038 {
00039     {"presencetype", BBOX_OFS(presencetype), FT_INT},
00040     {"flags", BBOX_OFS(flags), FT_INT},
00041     {"mins", BBOX_OFS(mins), FT_FLOAT|FT_ARRAY, 3},
00042     {"maxs", BBOX_OFS(maxs), FT_FLOAT|FT_ARRAY, 3},
00043     {NULL, 0, 0, 0}
00044 };
00045 
00046 fielddef_t cfg_fields[] =
00047 {
00048     {"phys_gravitydirection", CFG_OFS(phys_gravitydirection), FT_FLOAT|FT_ARRAY, 3},
00049     {"phys_friction", CFG_OFS(phys_friction), FT_FLOAT},
00050     {"phys_stopspeed", CFG_OFS(phys_stopspeed), FT_FLOAT},
00051     {"phys_gravity", CFG_OFS(phys_gravity), FT_FLOAT},
00052     {"phys_waterfriction", CFG_OFS(phys_waterfriction), FT_FLOAT},
00053     {"phys_watergravity", CFG_OFS(phys_watergravity), FT_FLOAT},
00054     {"phys_maxvelocity", CFG_OFS(phys_maxvelocity), FT_FLOAT},
00055     {"phys_maxwalkvelocity", CFG_OFS(phys_maxwalkvelocity), FT_FLOAT},
00056     {"phys_maxcrouchvelocity", CFG_OFS(phys_maxcrouchvelocity), FT_FLOAT},
00057     {"phys_maxswimvelocity", CFG_OFS(phys_maxswimvelocity), FT_FLOAT},
00058     {"phys_walkaccelerate", CFG_OFS(phys_walkaccelerate), FT_FLOAT},
00059     {"phys_airaccelerate", CFG_OFS(phys_airaccelerate), FT_FLOAT},
00060     {"phys_swimaccelerate", CFG_OFS(phys_swimaccelerate), FT_FLOAT},
00061     {"phys_maxstep", CFG_OFS(phys_maxstep), FT_FLOAT},
00062     {"phys_maxsteepness", CFG_OFS(phys_maxsteepness), FT_FLOAT},
00063     {"phys_maxwaterjump", CFG_OFS(phys_maxwaterjump), FT_FLOAT},
00064     {"phys_maxbarrier", CFG_OFS(phys_maxbarrier), FT_FLOAT},
00065     {"phys_jumpvel", CFG_OFS(phys_jumpvel), FT_FLOAT},
00066     {"phys_falldelta5", CFG_OFS(phys_falldelta5), FT_FLOAT},
00067     {"phys_falldelta10", CFG_OFS(phys_falldelta10), FT_FLOAT},
00068     {"rs_waterjump", CFG_OFS(rs_waterjump), FT_FLOAT},
00069     {"rs_teleport", CFG_OFS(rs_teleport), FT_FLOAT},
00070     {"rs_barrierjump", CFG_OFS(rs_barrierjump), FT_FLOAT},
00071     {"rs_startcrouch", CFG_OFS(rs_startcrouch), FT_FLOAT},
00072     {"rs_startgrapple", CFG_OFS(rs_startgrapple), FT_FLOAT},
00073     {"rs_startwalkoffledge", CFG_OFS(rs_startwalkoffledge), FT_FLOAT},
00074     {"rs_startjump", CFG_OFS(rs_startjump), FT_FLOAT},
00075     {"rs_rocketjump", CFG_OFS(rs_rocketjump), FT_FLOAT},
00076     {"rs_bfgjump", CFG_OFS(rs_bfgjump), FT_FLOAT},
00077     {"rs_jumppad", CFG_OFS(rs_jumppad), FT_FLOAT},
00078     {"rs_aircontrolledjumppad", CFG_OFS(rs_aircontrolledjumppad), FT_FLOAT},
00079     {"rs_funcbob", CFG_OFS(rs_funcbob), FT_FLOAT},
00080     {"rs_startelevator", CFG_OFS(rs_startelevator), FT_FLOAT},
00081     {"rs_falldamage5", CFG_OFS(rs_falldamage5), FT_FLOAT},
00082     {"rs_falldamage10", CFG_OFS(rs_falldamage10), FT_FLOAT},
00083     {"rs_maxjumpfallheight", CFG_OFS(rs_maxjumpfallheight), FT_FLOAT},
00084     {NULL, 0, 0, 0}
00085 };
00086 
00087 structdef_t bbox_struct =
00088 {
00089     sizeof(aas_bbox_t), bbox_fields
00090 };
00091 structdef_t cfg_struct =
00092 {
00093     sizeof(cfg_t), cfg_fields
00094 };
00095 
00096 //global cfg
00097 cfg_t cfg;
00098 
00099 //===========================================================================
00100 // the default Q3A configuration
00101 //
00102 // Parameter:           -
00103 // Returns:             -
00104 // Changes Globals:     -
00105 //===========================================================================
00106 void DefaultCfg(void)
00107 {
00108     int i;
00109 
00110     // default all float values to infinite
00111     for (i = 0; cfg_fields[i].name; i++)
00112     {
00113         if ((cfg_fields[i].type & FT_TYPE) == FT_FLOAT)
00114             *(float *)( ((char*)&cfg) + cfg_fields[i].offset ) = FLT_MAX;
00115     } //end for
00116     //
00117     cfg.numbboxes = 2;
00118     //bbox 0
00119     cfg.bboxes[0].presencetype = PRESENCE_NORMAL;
00120     cfg.bboxes[0].flags = 0;
00121     cfg.bboxes[0].mins[0] = -15;
00122     cfg.bboxes[0].mins[1] = -15;
00123     cfg.bboxes[0].mins[2] = -24;
00124     cfg.bboxes[0].maxs[0] = 15;
00125     cfg.bboxes[0].maxs[1] = 15;
00126     cfg.bboxes[0].maxs[2] = 32;
00127     //bbox 1
00128     cfg.bboxes[1].presencetype = PRESENCE_CROUCH;
00129     cfg.bboxes[1].flags = 1;
00130     cfg.bboxes[1].mins[0] = -15;
00131     cfg.bboxes[1].mins[1] = -15;
00132     cfg.bboxes[1].mins[2] = -24;
00133     cfg.bboxes[1].maxs[0] = 15;
00134     cfg.bboxes[1].maxs[1] = 15;
00135     cfg.bboxes[1].maxs[2] = 16;
00136     //
00137     cfg.allpresencetypes = PRESENCE_NORMAL|PRESENCE_CROUCH;
00138     cfg.phys_gravitydirection[0]    = 0;
00139     cfg.phys_gravitydirection[1]    = 0;
00140     cfg.phys_gravitydirection[2]    = -1;
00141     cfg.phys_maxsteepness           = 0.7;
00142 } //end of the function DefaultCfg
00143 //===========================================================================
00144 //
00145 // Parameter:           -
00146 // Returns:             -
00147 // Changes Globals:     -
00148 //===========================================================================
00149 char    * QDECL va( char *format, ... )
00150 {
00151     va_list     argptr;
00152     static char     string[2][32000];   // in case va is called by nested functions
00153     static int      index = 0;
00154     char    *buf;
00155 
00156     buf = string[index & 1];
00157     index++;
00158 
00159     va_start (argptr, format);
00160     vsprintf (buf, format,argptr);
00161     va_end (argptr);
00162 
00163     return buf;
00164 } //end of the function va
00165 //===========================================================================
00166 //
00167 // Parameter:           -
00168 // Returns:             -
00169 // Changes Globals:     -
00170 //===========================================================================
00171 void SetCfgLibVars(void)
00172 {
00173     int i;
00174     float value;
00175 
00176     for (i = 0; cfg_fields[i].name; i++)
00177     {
00178         if ((cfg_fields[i].type & FT_TYPE) == FT_FLOAT)
00179         {
00180             value = *(float *)(((char*)&cfg) + cfg_fields[i].offset);
00181             if (value != FLT_MAX)
00182             {
00183                 LibVarSet(cfg_fields[i].name, va("%f", value));
00184             } //end if
00185         } //end if
00186     } //end for
00187 } //end of the function SetCfgLibVars
00188 //===========================================================================
00189 //
00190 // Parameter:           -
00191 // Returns:             -
00192 // Changes Globals:     -
00193 //===========================================================================
00194 int LoadCfgFile(char *filename)
00195 {
00196     source_t *source;
00197     token_t token;
00198     int settingsdefined;
00199 
00200     source = LoadSourceFile(filename);
00201     if (!source)
00202     {
00203         Log_Print("couldn't open cfg file %s\n", filename);
00204         return false;
00205     } //end if
00206 
00207     settingsdefined = false;
00208     memset(&cfg, 0, sizeof(cfg_t));
00209 
00210     while(PC_ReadToken(source, &token))
00211     {
00212         if (!stricmp(token.string, "bbox"))
00213         {
00214             if (cfg.numbboxes >= AAS_MAX_BBOXES)
00215             {
00216                 SourceError(source, "too many bounding box volumes defined");
00217             } //end if
00218             if (!ReadStructure(source, &bbox_struct, (char *) &cfg.bboxes[cfg.numbboxes]))
00219             {
00220                 FreeSource(source);
00221                 return false;
00222             } //end if
00223             cfg.allpresencetypes |= cfg.bboxes[cfg.numbboxes].presencetype;
00224             cfg.numbboxes++;
00225         } //end if
00226         else if (!stricmp(token.string, "settings"))
00227         {
00228             if (settingsdefined)
00229             {
00230                 SourceWarning(source, "settings already defined\n");
00231             } //end if
00232             settingsdefined = true;
00233             if (!ReadStructure(source, &cfg_struct, (char *) &cfg))
00234             {
00235                 FreeSource(source);
00236                 return false;
00237             } //end if
00238         } //end else if
00239     } //end while
00240     if (VectorLength(cfg.phys_gravitydirection) < 0.9 || VectorLength(cfg.phys_gravitydirection) > 1.1)
00241     {
00242         SourceError(source, "invalid gravity direction specified");
00243     } //end if
00244     if (cfg.numbboxes <= 0)
00245     {
00246         SourceError(source, "no bounding volumes specified");
00247     } //end if
00248     FreeSource(source);
00249     SetCfgLibVars();
00250     Log_Print("using cfg file %s\n", filename);
00251     return true;
00252 } //end of the function LoadCfgFile

Generated on Thu Aug 25 12:37:13 2005 for Quake III Arena by  doxygen 1.3.9.1