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

l_bsp_ent.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 "l_cmd.h"
00024 #include "l_math.h"
00025 #include "l_mem.h"
00026 #include "l_log.h"
00027 #include "../botlib/l_script.h"
00028 #include "l_bsp_ent.h"
00029 
00030 #define MAX_KEY     32
00031 #define MAX_VALUE   1024
00032 
00033 int num_entities;
00034 entity_t    entities[MAX_MAP_ENTITIES];
00035 
00036 void StripTrailing(char *e)
00037 {
00038     char    *s;
00039 
00040     s = e + strlen(e)-1;
00041     while (s >= e && *s <= 32)
00042     {
00043         *s = 0;
00044         s--;
00045     }
00046 }
00047 
00048 /*
00049 =================
00050 ParseEpair
00051 =================
00052 */
00053 epair_t *ParseEpair(script_t *script)
00054 {
00055     epair_t *e;
00056     token_t token;
00057 
00058     e = GetMemory(sizeof(epair_t));
00059     memset (e, 0, sizeof(epair_t));
00060     
00061     PS_ExpectAnyToken(script, &token);
00062     StripDoubleQuotes(token.string);
00063     if (strlen(token.string) >= MAX_KEY-1)
00064         Error ("ParseEpair: token %s too long", token.string);
00065     e->key = copystring(token.string);
00066     PS_ExpectAnyToken(script, &token);
00067     StripDoubleQuotes(token.string);
00068     if (strlen(token.string) >= MAX_VALUE-1)
00069         Error ("ParseEpair: token %s too long", token.string);
00070     e->value = copystring(token.string);
00071 
00072     // strip trailing spaces
00073     StripTrailing(e->key);
00074     StripTrailing(e->value);
00075 
00076     return e;
00077 } //end of the function ParseEpair
00078 
00079 
00080 /*
00081 ================
00082 ParseEntity
00083 ================
00084 */
00085 qboolean    ParseEntity(script_t *script)
00086 {
00087     epair_t *e;
00088     entity_t    *mapent;
00089     token_t token;
00090 
00091     if (!PS_ReadToken(script, &token))
00092         return false;
00093 
00094     if (strcmp(token.string, "{"))
00095         Error ("ParseEntity: { not found");
00096     
00097     if (num_entities == MAX_MAP_ENTITIES)
00098         Error ("num_entities == MAX_MAP_ENTITIES");
00099 
00100     mapent = &entities[num_entities];
00101     num_entities++;
00102 
00103     do
00104     {
00105         if (!PS_ReadToken(script, &token))
00106             Error ("ParseEntity: EOF without closing brace");
00107         if (!strcmp(token.string, "}") )
00108             break;
00109         PS_UnreadLastToken(script);
00110         e = ParseEpair(script);
00111         e->next = mapent->epairs;
00112         mapent->epairs = e;
00113     } while (1);
00114     
00115     return true;
00116 } //end of the function ParseEntity
00117 
00118 void PrintEntity (entity_t *ent)
00119 {
00120     epair_t *ep;
00121     
00122     printf ("------- entity %p -------\n", ent);
00123     for (ep=ent->epairs ; ep ; ep=ep->next)
00124     {
00125         printf ("%s = %s\n", ep->key, ep->value);
00126     }
00127 
00128 }
00129 
00130 void    SetKeyValue (entity_t *ent, char *key, char *value)
00131 {
00132     epair_t *ep;
00133     
00134     for (ep=ent->epairs ; ep ; ep=ep->next)
00135         if (!strcmp (ep->key, key) )
00136         {
00137             FreeMemory(ep->value);
00138             ep->value = copystring(value);
00139             return;
00140         }
00141     ep = GetMemory(sizeof(*ep));
00142     ep->next = ent->epairs;
00143     ent->epairs = ep;
00144     ep->key = copystring(key);
00145     ep->value = copystring(value);
00146 }
00147 
00148 char    *ValueForKey (entity_t *ent, char *key)
00149 {
00150     epair_t *ep;
00151     
00152     for (ep=ent->epairs ; ep ; ep=ep->next)
00153         if (!strcmp (ep->key, key) )
00154             return ep->value;
00155     return "";
00156 }
00157 
00158 vec_t   FloatForKey (entity_t *ent, char *key)
00159 {
00160     char    *k;
00161     
00162     k = ValueForKey (ent, key);
00163     return atof(k);
00164 }
00165 
00166 void    GetVectorForKey (entity_t *ent, char *key, vec3_t vec)
00167 {
00168     char    *k;
00169     double  v1, v2, v3;
00170 
00171     k = ValueForKey (ent, key);
00172 // scanf into doubles, then assign, so it is vec_t size independent
00173     v1 = v2 = v3 = 0;
00174     sscanf (k, "%lf %lf %lf", &v1, &v2, &v3);
00175     vec[0] = v1;
00176     vec[1] = v2;
00177     vec[2] = v3;
00178 }
00179 
00180 

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