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 /***************************************************************************** 00024 * name: l_libvar.c 00025 * 00026 * desc: bot library variables 00027 * 00028 * $Archive: /MissionPack/code/botlib/l_libvar.c $ 00029 * 00030 *****************************************************************************/ 00031 00032 #include "../game/q_shared.h" 00033 #include "l_memory.h" 00034 #include "l_libvar.h" 00035 00036 //list with library variables 00037 libvar_t *libvarlist; 00038 00039 //=========================================================================== 00040 // 00041 // Parameter: - 00042 // Returns: - 00043 // Changes Globals: - 00044 //=========================================================================== 00045 float LibVarStringValue(char *string) 00046 { 00047 int dotfound = 0; 00048 float value = 0; 00049 00050 while(*string) 00051 { 00052 if (*string < '0' || *string > '9') 00053 { 00054 if (dotfound || *string != '.') 00055 { 00056 return 0; 00057 } //end if 00058 else 00059 { 00060 dotfound = 10; 00061 string++; 00062 } //end if 00063 } //end if 00064 if (dotfound) 00065 { 00066 value = value + (float) (*string - '0') / (float) dotfound; 00067 dotfound *= 10; 00068 } //end if 00069 else 00070 { 00071 value = value * 10.0 + (float) (*string - '0'); 00072 } //end else 00073 string++; 00074 } //end while 00075 return value; 00076 } //end of the function LibVarStringValue 00077 //=========================================================================== 00078 // 00079 // Parameter: - 00080 // Returns: - 00081 // Changes Globals: - 00082 //=========================================================================== 00083 libvar_t *LibVarAlloc(char *var_name) 00084 { 00085 libvar_t *v; 00086 00087 v = (libvar_t *) GetMemory(sizeof(libvar_t) + strlen(var_name) + 1); 00088 Com_Memset(v, 0, sizeof(libvar_t)); 00089 v->name = (char *) v + sizeof(libvar_t); 00090 strcpy(v->name, var_name); 00091 //add the variable in the list 00092 v->next = libvarlist; 00093 libvarlist = v; 00094 return v; 00095 } //end of the function LibVarAlloc 00096 //=========================================================================== 00097 // 00098 // Parameter: - 00099 // Returns: - 00100 // Changes Globals: - 00101 //=========================================================================== 00102 void LibVarDeAlloc(libvar_t *v) 00103 { 00104 if (v->string) FreeMemory(v->string); 00105 FreeMemory(v); 00106 } //end of the function LibVarDeAlloc 00107 //=========================================================================== 00108 // 00109 // Parameter: - 00110 // Returns: - 00111 // Changes Globals: - 00112 //=========================================================================== 00113 void LibVarDeAllocAll(void) 00114 { 00115 libvar_t *v; 00116 00117 for (v = libvarlist; v; v = libvarlist) 00118 { 00119 libvarlist = libvarlist->next; 00120 LibVarDeAlloc(v); 00121 } //end for 00122 libvarlist = NULL; 00123 } //end of the function LibVarDeAllocAll 00124 //=========================================================================== 00125 // 00126 // Parameter: - 00127 // Returns: - 00128 // Changes Globals: - 00129 //=========================================================================== 00130 libvar_t *LibVarGet(char *var_name) 00131 { 00132 libvar_t *v; 00133 00134 for (v = libvarlist; v; v = v->next) 00135 { 00136 if (!Q_stricmp(v->name, var_name)) 00137 { 00138 return v; 00139 } //end if 00140 } //end for 00141 return NULL; 00142 } //end of the function LibVarGet 00143 //=========================================================================== 00144 // 00145 // Parameter: - 00146 // Returns: - 00147 // Changes Globals: - 00148 //=========================================================================== 00149 char *LibVarGetString(char *var_name) 00150 { 00151 libvar_t *v; 00152 00153 v = LibVarGet(var_name); 00154 if (v) 00155 { 00156 return v->string; 00157 } //end if 00158 else 00159 { 00160 return ""; 00161 } //end else 00162 } //end of the function LibVarGetString 00163 //=========================================================================== 00164 // 00165 // Parameter: - 00166 // Returns: - 00167 // Changes Globals: - 00168 //=========================================================================== 00169 float LibVarGetValue(char *var_name) 00170 { 00171 libvar_t *v; 00172 00173 v = LibVarGet(var_name); 00174 if (v) 00175 { 00176 return v->value; 00177 } //end if 00178 else 00179 { 00180 return 0; 00181 } //end else 00182 } //end of the function LibVarGetValue 00183 //=========================================================================== 00184 // 00185 // Parameter: - 00186 // Returns: - 00187 // Changes Globals: - 00188 //=========================================================================== 00189 libvar_t *LibVar(char *var_name, char *value) 00190 { 00191 libvar_t *v; 00192 v = LibVarGet(var_name); 00193 if (v) return v; 00194 //create new variable 00195 v = LibVarAlloc(var_name); 00196 //variable string 00197 v->string = (char *) GetMemory(strlen(value) + 1); 00198 strcpy(v->string, value); 00199 //the value 00200 v->value = LibVarStringValue(v->string); 00201 //variable is modified 00202 v->modified = qtrue; 00203 // 00204 return v; 00205 } //end of the function LibVar 00206 //=========================================================================== 00207 // 00208 // Parameter: - 00209 // Returns: - 00210 // Changes Globals: - 00211 //=========================================================================== 00212 char *LibVarString(char *var_name, char *value) 00213 { 00214 libvar_t *v; 00215 00216 v = LibVar(var_name, value); 00217 return v->string; 00218 } //end of the function LibVarString 00219 //=========================================================================== 00220 // 00221 // Parameter: - 00222 // Returns: - 00223 // Changes Globals: - 00224 //=========================================================================== 00225 float LibVarValue(char *var_name, char *value) 00226 { 00227 libvar_t *v; 00228 00229 v = LibVar(var_name, value); 00230 return v->value; 00231 } //end of the function LibVarValue 00232 //=========================================================================== 00233 // 00234 // Parameter: - 00235 // Returns: - 00236 // Changes Globals: - 00237 //=========================================================================== 00238 void LibVarSet(char *var_name, char *value) 00239 { 00240 libvar_t *v; 00241 00242 v = LibVarGet(var_name); 00243 if (v) 00244 { 00245 FreeMemory(v->string); 00246 } //end if 00247 else 00248 { 00249 v = LibVarAlloc(var_name); 00250 } //end else 00251 //variable string 00252 v->string = (char *) GetMemory(strlen(value) + 1); 00253 strcpy(v->string, value); 00254 //the value 00255 v->value = LibVarStringValue(v->string); 00256 //variable is modified 00257 v->modified = qtrue; 00258 } //end of the function LibVarSet 00259 //=========================================================================== 00260 // 00261 // Parameter: - 00262 // Returns: - 00263 // Changes Globals: - 00264 //=========================================================================== 00265 qboolean LibVarChanged(char *var_name) 00266 { 00267 libvar_t *v; 00268 00269 v = LibVarGet(var_name); 00270 if (v) 00271 { 00272 return v->modified; 00273 } //end if 00274 else 00275 { 00276 return qfalse; 00277 } //end else 00278 } //end of the function LibVarChanged 00279 //=========================================================================== 00280 // 00281 // Parameter: - 00282 // Returns: - 00283 // Changes Globals: - 00284 //=========================================================================== 00285 void LibVarSetNotModified(char *var_name) 00286 { 00287 libvar_t *v; 00288 00289 v = LibVarGet(var_name); 00290 if (v) 00291 { 00292 v->modified = qfalse; 00293 } //end if 00294 } //end of the function LibVarSetNotModified
1.3.9.1