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

be_aas_bspq3.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 /*****************************************************************************
00024  * name:        be_aas_bspq3.c
00025  *
00026  * desc:        BSP, Environment Sampling
00027  *
00028  * $Archive: /MissionPack/code/botlib/be_aas_bspq3.c $
00029  *
00030  *****************************************************************************/
00031 
00032 #include "../game/q_shared.h"
00033 #include "l_memory.h"
00034 #include "l_script.h"
00035 #include "l_precomp.h"
00036 #include "l_struct.h"
00037 #include "aasfile.h"
00038 #include "../game/botlib.h"
00039 #include "../game/be_aas.h"
00040 #include "be_aas_funcs.h"
00041 #include "be_aas_def.h"
00042 
00043 extern botlib_import_t botimport;
00044 
00045 //#define TRACE_DEBUG
00046 
00047 #define ON_EPSILON      0.005
00048 //#define DEG2RAD( a ) (( a * M_PI ) / 180.0F)
00049 
00050 #define MAX_BSPENTITIES     2048
00051 
00052 typedef struct rgb_s
00053 {
00054     int red;
00055     int green;
00056     int blue;
00057 } rgb_t;
00058 
00059 //bsp entity epair
00060 typedef struct bsp_epair_s
00061 {
00062     char *key;
00063     char *value;
00064     struct bsp_epair_s *next;
00065 } bsp_epair_t;
00066 
00067 //bsp data entity
00068 typedef struct bsp_entity_s
00069 {
00070     bsp_epair_t *epairs;
00071 } bsp_entity_t;
00072 
00073 //id Sofware BSP data
00074 typedef struct bsp_s
00075 {
00076     //true when bsp file is loaded
00077     int loaded;
00078     //entity data
00079     int entdatasize;
00080     char *dentdata;
00081     //bsp entities
00082     int numentities;
00083     bsp_entity_t entities[MAX_BSPENTITIES];
00084 } bsp_t;
00085 
00086 //global bsp
00087 bsp_t bspworld;
00088 
00089 
00090 #ifdef BSP_DEBUG
00091 typedef struct cname_s
00092 {
00093     int value;
00094     char *name;
00095 } cname_t;
00096 
00097 cname_t contentnames[] =
00098 {
00099     {CONTENTS_SOLID,"CONTENTS_SOLID"},
00100     {CONTENTS_WINDOW,"CONTENTS_WINDOW"},
00101     {CONTENTS_AUX,"CONTENTS_AUX"},
00102     {CONTENTS_LAVA,"CONTENTS_LAVA"},
00103     {CONTENTS_SLIME,"CONTENTS_SLIME"},
00104     {CONTENTS_WATER,"CONTENTS_WATER"},
00105     {CONTENTS_MIST,"CONTENTS_MIST"},
00106     {LAST_VISIBLE_CONTENTS,"LAST_VISIBLE_CONTENTS"},
00107 
00108     {CONTENTS_AREAPORTAL,"CONTENTS_AREAPORTAL"},
00109     {CONTENTS_PLAYERCLIP,"CONTENTS_PLAYERCLIP"},
00110     {CONTENTS_MONSTERCLIP,"CONTENTS_MONSTERCLIP"},
00111     {CONTENTS_CURRENT_0,"CONTENTS_CURRENT_0"},
00112     {CONTENTS_CURRENT_90,"CONTENTS_CURRENT_90"},
00113     {CONTENTS_CURRENT_180,"CONTENTS_CURRENT_180"},
00114     {CONTENTS_CURRENT_270,"CONTENTS_CURRENT_270"},
00115     {CONTENTS_CURRENT_UP,"CONTENTS_CURRENT_UP"},
00116     {CONTENTS_CURRENT_DOWN,"CONTENTS_CURRENT_DOWN"},
00117     {CONTENTS_ORIGIN,"CONTENTS_ORIGIN"},
00118     {CONTENTS_MONSTER,"CONTENTS_MONSTER"},
00119     {CONTENTS_DEADMONSTER,"CONTENTS_DEADMONSTER"},
00120     {CONTENTS_DETAIL,"CONTENTS_DETAIL"},
00121     {CONTENTS_TRANSLUCENT,"CONTENTS_TRANSLUCENT"},
00122     {CONTENTS_LADDER,"CONTENTS_LADDER"},
00123     {0, 0}
00124 };
00125 
00126 void PrintContents(int contents)
00127 {
00128     int i;
00129 
00130     for (i = 0; contentnames[i].value; i++)
00131     {
00132         if (contents & contentnames[i].value)
00133         {
00134             botimport.Print(PRT_MESSAGE, "%s\n", contentnames[i].name);
00135         } //end if
00136     } //end for
00137 } //end of the function PrintContents
00138 
00139 #endif // BSP_DEBUG
00140 //===========================================================================
00141 // traces axial boxes of any size through the world
00142 //
00143 // Parameter:               -
00144 // Returns:                 -
00145 // Changes Globals:     -
00146 //===========================================================================
00147 bsp_trace_t AAS_Trace(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int passent, int contentmask)
00148 {
00149     bsp_trace_t bsptrace;
00150     botimport.Trace(&bsptrace, start, mins, maxs, end, passent, contentmask);
00151     return bsptrace;
00152 } //end of the function AAS_Trace
00153 //===========================================================================
00154 // returns the contents at the given point
00155 //
00156 // Parameter:               -
00157 // Returns:                 -
00158 // Changes Globals:     -
00159 //===========================================================================
00160 int AAS_PointContents(vec3_t point)
00161 {
00162     return botimport.PointContents(point);
00163 } //end of the function AAS_PointContents
00164 //===========================================================================
00165 //
00166 // Parameter:               -
00167 // Returns:                 -
00168 // Changes Globals:     -
00169 //===========================================================================
00170 qboolean AAS_EntityCollision(int entnum,
00171                     vec3_t start, vec3_t boxmins, vec3_t boxmaxs, vec3_t end,
00172                                 int contentmask, bsp_trace_t *trace)
00173 {
00174     bsp_trace_t enttrace;
00175 
00176     botimport.EntityTrace(&enttrace, start, boxmins, boxmaxs, end, entnum, contentmask);
00177     if (enttrace.fraction < trace->fraction)
00178     {
00179         Com_Memcpy(trace, &enttrace, sizeof(bsp_trace_t));
00180         return qtrue;
00181     } //end if
00182     return qfalse;
00183 } //end of the function AAS_EntityCollision
00184 //===========================================================================
00185 // returns true if in Potentially Hearable Set
00186 //
00187 // Parameter:               -
00188 // Returns:                 -
00189 // Changes Globals:     -
00190 //===========================================================================
00191 qboolean AAS_inPVS(vec3_t p1, vec3_t p2)
00192 {
00193     return botimport.inPVS(p1, p2);
00194 } //end of the function AAS_InPVS
00195 //===========================================================================
00196 // returns true if in Potentially Visible Set
00197 //
00198 // Parameter:               -
00199 // Returns:                 -
00200 // Changes Globals:     -
00201 //===========================================================================
00202 qboolean AAS_inPHS(vec3_t p1, vec3_t p2)
00203 {
00204     return qtrue;
00205 } //end of the function AAS_inPHS
00206 //===========================================================================
00207 //
00208 // Parameter:               -
00209 // Returns:                 -
00210 // Changes Globals:     -
00211 //===========================================================================
00212 void AAS_BSPModelMinsMaxsOrigin(int modelnum, vec3_t angles, vec3_t mins, vec3_t maxs, vec3_t origin)
00213 {
00214     botimport.BSPModelMinsMaxsOrigin(modelnum, angles, mins, maxs, origin);
00215 } //end of the function AAS_BSPModelMinsMaxs
00216 //===========================================================================
00217 // unlinks the entity from all leaves
00218 //
00219 // Parameter:               -
00220 // Returns:                 -
00221 // Changes Globals:     -
00222 //===========================================================================
00223 void AAS_UnlinkFromBSPLeaves(bsp_link_t *leaves)
00224 {
00225 } //end of the function AAS_UnlinkFromBSPLeaves
00226 //===========================================================================
00227 //
00228 // Parameter:               -
00229 // Returns:                 -
00230 // Changes Globals:     -
00231 //===========================================================================
00232 bsp_link_t *AAS_BSPLinkEntity(vec3_t absmins, vec3_t absmaxs, int entnum, int modelnum)
00233 {
00234     return NULL;
00235 } //end of the function AAS_BSPLinkEntity
00236 //===========================================================================
00237 //
00238 // Parameter:               -
00239 // Returns:                 -
00240 // Changes Globals:     -
00241 //===========================================================================
00242 int AAS_BoxEntities(vec3_t absmins, vec3_t absmaxs, int *list, int maxcount)
00243 {
00244     return 0;
00245 } //end of the function AAS_BoxEntities
00246 //===========================================================================
00247 //
00248 // Parameter:           -
00249 // Returns:             -
00250 // Changes Globals:     -
00251 //===========================================================================
00252 int AAS_NextBSPEntity(int ent)
00253 {
00254     ent++;
00255     if (ent >= 1 && ent < bspworld.numentities) return ent;
00256     return 0;
00257 } //end of the function AAS_NextBSPEntity
00258 //===========================================================================
00259 //
00260 // Parameter:           -
00261 // Returns:             -
00262 // Changes Globals:     -
00263 //===========================================================================
00264 int AAS_BSPEntityInRange(int ent)
00265 {
00266     if (ent <= 0 || ent >= bspworld.numentities)
00267     {
00268         botimport.Print(PRT_MESSAGE, "bsp entity out of range\n");
00269         return qfalse;
00270     } //end if
00271     return qtrue;
00272 } //end of the function AAS_BSPEntityInRange
00273 //===========================================================================
00274 //
00275 // Parameter:           -
00276 // Returns:             -
00277 // Changes Globals:     -
00278 //===========================================================================
00279 int AAS_ValueForBSPEpairKey(int ent, char *key, char *value, int size)
00280 {
00281     bsp_epair_t *epair;
00282 
00283     value[0] = '\0';
00284     if (!AAS_BSPEntityInRange(ent)) return qfalse;
00285     for (epair = bspworld.entities[ent].epairs; epair; epair = epair->next)
00286     {
00287         if (!strcmp(epair->key, key))
00288         {
00289             strncpy(value, epair->value, size-1);
00290             value[size-1] = '\0';
00291             return qtrue;
00292         } //end if
00293     } //end for
00294     return qfalse;
00295 } //end of the function AAS_FindBSPEpair
00296 //===========================================================================
00297 //
00298 // Parameter:               -
00299 // Returns:                 -
00300 // Changes Globals:     -
00301 //===========================================================================
00302 int AAS_VectorForBSPEpairKey(int ent, char *key, vec3_t v)
00303 {
00304     char buf[MAX_EPAIRKEY];
00305     double v1, v2, v3;
00306 
00307     VectorClear(v);
00308     if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
00309     //scanf into doubles, then assign, so it is vec_t size independent
00310     v1 = v2 = v3 = 0;
00311     sscanf(buf, "%lf %lf %lf", &v1, &v2, &v3);
00312     v[0] = v1;
00313     v[1] = v2;
00314     v[2] = v3;
00315     return qtrue;
00316 } //end of the function AAS_VectorForBSPEpairKey
00317 //===========================================================================
00318 //
00319 // Parameter:               -
00320 // Returns:                 -
00321 // Changes Globals:     -
00322 //===========================================================================
00323 int AAS_FloatForBSPEpairKey(int ent, char *key, float *value)
00324 {
00325     char buf[MAX_EPAIRKEY];
00326     
00327     *value = 0;
00328     if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
00329     *value = atof(buf);
00330     return qtrue;
00331 } //end of the function AAS_FloatForBSPEpairKey
00332 //===========================================================================
00333 //
00334 // Parameter:               -
00335 // Returns:                 -
00336 // Changes Globals:     -
00337 //===========================================================================
00338 int AAS_IntForBSPEpairKey(int ent, char *key, int *value)
00339 {
00340     char buf[MAX_EPAIRKEY];
00341     
00342     *value = 0;
00343     if (!AAS_ValueForBSPEpairKey(ent, key, buf, MAX_EPAIRKEY)) return qfalse;
00344     *value = atoi(buf);
00345     return qtrue;
00346 } //end of the function AAS_IntForBSPEpairKey
00347 //===========================================================================
00348 //
00349 // Parameter:           -
00350 // Returns:             -
00351 // Changes Globals:     -
00352 //===========================================================================
00353 void AAS_FreeBSPEntities(void)
00354 {
00355     int i;
00356     bsp_entity_t *ent;
00357     bsp_epair_t *epair, *nextepair;
00358 
00359     for (i = 1; i < bspworld.numentities; i++)
00360     {
00361         ent = &bspworld.entities[i];
00362         for (epair = ent->epairs; epair; epair = nextepair)
00363         {
00364             nextepair = epair->next;
00365             //
00366             if (epair->key) FreeMemory(epair->key);
00367             if (epair->value) FreeMemory(epair->value);
00368             FreeMemory(epair);
00369         } //end for
00370     } //end for
00371     bspworld.numentities = 0;
00372 } //end of the function AAS_FreeBSPEntities
00373 //===========================================================================
00374 //
00375 // Parameter:           -
00376 // Returns:             -
00377 // Changes Globals:     -
00378 //===========================================================================
00379 void AAS_ParseBSPEntities(void)
00380 {
00381     script_t *script;
00382     token_t token;
00383     bsp_entity_t *ent;
00384     bsp_epair_t *epair;
00385 
00386     script = LoadScriptMemory(bspworld.dentdata, bspworld.entdatasize, "entdata");
00387     SetScriptFlags(script, SCFL_NOSTRINGWHITESPACES|SCFL_NOSTRINGESCAPECHARS);//SCFL_PRIMITIVE);
00388 
00389     bspworld.numentities = 1;
00390 
00391     while(PS_ReadToken(script, &token))
00392     {
00393         if (strcmp(token.string, "{"))
00394         {
00395             ScriptError(script, "invalid %s\n", token.string);
00396             AAS_FreeBSPEntities();
00397             FreeScript(script);
00398             return;
00399         } //end if
00400         if (bspworld.numentities >= MAX_BSPENTITIES)
00401         {
00402             botimport.Print(PRT_MESSAGE, "too many entities in BSP file\n");
00403             break;
00404         } //end if
00405         ent = &bspworld.entities[bspworld.numentities];
00406         bspworld.numentities++;
00407         ent->epairs = NULL;
00408         while(PS_ReadToken(script, &token))
00409         {
00410             if (!strcmp(token.string, "}")) break;
00411             epair = (bsp_epair_t *) GetClearedHunkMemory(sizeof(bsp_epair_t));
00412             epair->next = ent->epairs;
00413             ent->epairs = epair;
00414             if (token.type != TT_STRING)
00415             {
00416                 ScriptError(script, "invalid %s\n", token.string);
00417                 AAS_FreeBSPEntities();
00418                 FreeScript(script);
00419                 return;
00420             } //end if
00421             StripDoubleQuotes(token.string);
00422             epair->key = (char *) GetHunkMemory(strlen(token.string) + 1);
00423             strcpy(epair->key, token.string);
00424             if (!PS_ExpectTokenType(script, TT_STRING, 0, &token))
00425             {
00426                 AAS_FreeBSPEntities();
00427                 FreeScript(script);
00428                 return;
00429             } //end if
00430             StripDoubleQuotes(token.string);
00431             epair->value = (char *) GetHunkMemory(strlen(token.string) + 1);
00432             strcpy(epair->value, token.string);
00433         } //end while
00434         if (strcmp(token.string, "}"))
00435         {
00436             ScriptError(script, "missing }\n");
00437             AAS_FreeBSPEntities();
00438             FreeScript(script);
00439             return;
00440         } //end if
00441     } //end while
00442     FreeScript(script);
00443 } //end of the function AAS_ParseBSPEntities
00444 //===========================================================================
00445 //
00446 // Parameter:               -
00447 // Returns:                 -
00448 // Changes Globals:     -
00449 //===========================================================================
00450 int AAS_BSPTraceLight(vec3_t start, vec3_t end, vec3_t endpos, int *red, int *green, int *blue)
00451 {
00452     return 0;
00453 } //end of the function AAS_BSPTraceLight
00454 //===========================================================================
00455 //
00456 // Parameter:               -
00457 // Returns:                 -
00458 // Changes Globals:     -
00459 //===========================================================================
00460 void AAS_DumpBSPData(void)
00461 {
00462     AAS_FreeBSPEntities();
00463 
00464     if (bspworld.dentdata) FreeMemory(bspworld.dentdata);
00465     bspworld.dentdata = NULL;
00466     bspworld.entdatasize = 0;
00467     //
00468     bspworld.loaded = qfalse;
00469     Com_Memset( &bspworld, 0, sizeof(bspworld) );
00470 } //end of the function AAS_DumpBSPData
00471 //===========================================================================
00472 // load an bsp file
00473 //
00474 // Parameter:               -
00475 // Returns:                 -
00476 // Changes Globals:     -
00477 //===========================================================================
00478 int AAS_LoadBSPFile(void)
00479 {
00480     AAS_DumpBSPData();
00481     bspworld.entdatasize = strlen(botimport.BSPEntityData()) + 1;
00482     bspworld.dentdata = (char *) GetClearedHunkMemory(bspworld.entdatasize);
00483     Com_Memcpy(bspworld.dentdata, botimport.BSPEntityData(), bspworld.entdatasize);
00484     AAS_ParseBSPEntities();
00485     bspworld.loaded = qtrue;
00486     return BLERR_NOERROR;
00487 } //end of the function AAS_LoadBSPFile

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