00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00033 #define BBOX_OFS(x) (int)&(((aas_bbox_t *)0)->x)
00034 #define CFG_OFS(x) (int)&(((cfg_t *)0)->x)
00035
00036
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
00097 cfg_t cfg;
00098
00099
00100
00101
00102
00103
00104
00105
00106 void DefaultCfg(void)
00107 {
00108 int i;
00109
00110
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 }
00116
00117 cfg.numbboxes = 2;
00118
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
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 }
00143
00144
00145
00146
00147
00148
00149 char * QDECL va( char *format, ... )
00150 {
00151 va_list argptr;
00152 static char string[2][32000];
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 }
00165
00166
00167
00168
00169
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 }
00185 }
00186 }
00187 }
00188
00189
00190
00191
00192
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 }
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 }
00218 if (!ReadStructure(source, &bbox_struct, (char *) &cfg.bboxes[cfg.numbboxes]))
00219 {
00220 FreeSource(source);
00221 return false;
00222 }
00223 cfg.allpresencetypes |= cfg.bboxes[cfg.numbboxes].presencetype;
00224 cfg.numbboxes++;
00225 }
00226 else if (!stricmp(token.string, "settings"))
00227 {
00228 if (settingsdefined)
00229 {
00230 SourceWarning(source, "settings already defined\n");
00231 }
00232 settingsdefined = true;
00233 if (!ReadStructure(source, &cfg_struct, (char *) &cfg))
00234 {
00235 FreeSource(source);
00236 return false;
00237 }
00238 }
00239 }
00240 if (VectorLength(cfg.phys_gravitydirection) < 0.9 || VectorLength(cfg.phys_gravitydirection) > 1.1)
00241 {
00242 SourceError(source, "invalid gravity direction specified");
00243 }
00244 if (cfg.numbboxes <= 0)
00245 {
00246 SourceError(source, "no bounding volumes specified");
00247 }
00248 FreeSource(source);
00249 SetCfgLibVars();
00250 Log_Print("using cfg file %s\n", filename);
00251 return true;
00252 }