//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AAS_DumpBSPData(void) { AAS_FreeBSPEntities(); if (bspworld.dentdata) FreeMemory(bspworld.dentdata); bspworld.dentdata = NULL; bspworld.entdatasize = 0; // bspworld.loaded = qfalse; Com_Memset( &bspworld, 0, sizeof(bspworld) ); } //end of the function AAS_DumpBSPData
/* ======================================================================================================================================= AAS_DumpBSPData ======================================================================================================================================= */ void AAS_DumpBSPData(void) { AAS_FreeBSPEntities(); if (bspworld.dentdata) { FreeMemory(bspworld.dentdata); } bspworld.dentdata = NULL; bspworld.entdatasize = 0; bspworld.loaded = qfalse; memset(&bspworld, 0, sizeof(bspworld)); }
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AAS_ParseBSPEntities( void ) { script_t *script; token_t token; bsp_entity_t *ent; bsp_epair_t *epair; byte *buffer, *buftrav; int bufsize; // RF, modified this, so that it first gathers up memory requirements, then allocates a single chunk, // and places the strings all in there bspworld.ebuffer = NULL; script = LoadScriptMemory( bspworld.dentdata, bspworld.entdatasize, "entdata" ); SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS ); //SCFL_PRIMITIVE); bufsize = 0; while ( PS_ReadToken( script, &token ) ) { if ( strcmp( token.string, "{" ) ) { ScriptError( script, "invalid %s\n", token.string ); AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if if ( bspworld.numentities >= MAX_BSPENTITIES ) { botimport.Print( PRT_MESSAGE, "too many entities in BSP file\n" ); break; } //end if while ( PS_ReadToken( script, &token ) ) { if ( !strcmp( token.string, "}" ) ) { break; } bufsize += sizeof( bsp_epair_t ); if ( token.type != TT_STRING ) { ScriptError( script, "invalid %s\n", token.string ); AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if StripDoubleQuotes( token.string ); bufsize += strlen( token.string ) + 1; if ( !PS_ExpectTokenType( script, TT_STRING, 0, &token ) ) { AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if StripDoubleQuotes( token.string ); bufsize += strlen( token.string ) + 1; } //end while if ( strcmp( token.string, "}" ) ) { ScriptError( script, "missing }\n" ); AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if } //end while FreeScript( script ); buffer = (byte *)GetClearedHunkMemory( bufsize ); buftrav = buffer; bspworld.ebuffer = buffer; // RF, now parse the entities into memory // RF, NOTE: removed error checks for speed, no need to do them twice script = LoadScriptMemory( bspworld.dentdata, bspworld.entdatasize, "entdata" ); SetScriptFlags( script, SCFL_NOSTRINGWHITESPACES | SCFL_NOSTRINGESCAPECHARS ); //SCFL_PRIMITIVE); bspworld.numentities = 1; while ( PS_ReadToken( script, &token ) ) { ent = &bspworld.entities[bspworld.numentities]; bspworld.numentities++; ent->epairs = NULL; while ( PS_ReadToken( script, &token ) ) { if ( !strcmp( token.string, "}" ) ) { break; } epair = (bsp_epair_t *) buftrav; buftrav += sizeof( bsp_epair_t ); epair->next = ent->epairs; ent->epairs = epair; StripDoubleQuotes( token.string ); epair->key = (char *) buftrav; buftrav += ( strlen( token.string ) + 1 ); strcpy( epair->key, token.string ); if ( !PS_ExpectTokenType( script, TT_STRING, 0, &token ) ) { AAS_FreeBSPEntities(); FreeScript( script ); return; } //end if StripDoubleQuotes( token.string ); epair->value = (char *) buftrav; buftrav += ( strlen( token.string ) + 1 ); strcpy( epair->value, token.string ); } //end while } //end while FreeScript( script ); } //end of the function AAS_ParseBSPEntities
void AAS_AddTeleporterPortals(void) { int j, area2num, facenum, otherareanum; char *target, *targetname, *classname; bsp_entity_t *entities, *ent, *dest; vec3_t origin, destorigin, mins, maxs, end; vec3_t bbmins, bbmaxs; aas_area_t *area; aas_face_t *face; aas_trace_t trace; aas_link_t *areas, *link; entities = AAS_ParseBSPEntities(); for (ent = entities; ent; ent = ent->next) { classname = AAS_ValueForBSPEpairKey(ent, "classname"); if (classname && !strcmp(classname, "misc_teleporter")) { if (!AAS_VectorForBSPEpairKey(ent, "origin", origin)) { botimport.Print(PRT_ERROR, "teleporter (%s) without origin\n", target); continue; } //end if // target = AAS_ValueForBSPEpairKey(ent, "target"); if (!target) { botimport.Print(PRT_ERROR, "teleporter (%s) without target\n", target); continue; } //end if for (dest = entities; dest; dest = dest->next) { classname = AAS_ValueForBSPEpairKey(dest, "classname"); if (classname && !strcmp(classname, "misc_teleporter_dest")) { targetname = AAS_ValueForBSPEpairKey(dest, "targetname"); if (targetname && !strcmp(targetname, target)) { break; } //end if } //end if } //end for if (!dest) { botimport.Print(PRT_ERROR, "teleporter without destination (%s)\n", target); continue; } //end if if (!AAS_VectorForBSPEpairKey(dest, "origin", destorigin)) { botimport.Print(PRT_ERROR, "teleporter destination (%s) without origin\n", target); continue; } //end if destorigin[2] += 24; //just for q2e1m2, the dork has put the telepads in the ground VectorCopy(destorigin, end); end[2] -= 100; trace = AAS_TraceClientBBox(destorigin, end, PRESENCE_CROUCH, -1); if (trace.startsolid) { botimport.Print(PRT_ERROR, "teleporter destination (%s) in solid\n", target); continue; } //end if VectorCopy(trace.endpos, destorigin); area2num = AAS_PointAreaNum(destorigin); //reset all cluster fields for (j = 0; j < aasworld.numareas; j++) { aasworld.areasettings[j].cluster = 0; } //end for // VectorSet(mins, -8, -8, 8); VectorSet(maxs, 8, 8, 24); // AAS_PresenceTypeBoundingBox(PRESENCE_CROUCH, bbmins, bbmaxs); // VectorAdd(origin, mins, mins); VectorAdd(origin, maxs, maxs); //add bounding box size VectorSubtract(mins, bbmaxs, mins); VectorSubtract(maxs, bbmins, maxs); //link an invalid (-1) entity areas = AAS_AASLinkEntity(mins, maxs, -1); // for (link = areas; link; link = link->next_area) { if (!AAS_AreaGrounded(link->areanum)) continue; //add the teleporter portal mark aasworld.areasettings[link->areanum].contents |= AREACONTENTS_CLUSTERPORTAL | AREACONTENTS_TELEPORTAL; } //end for // for (link = areas; link; link = link->next_area) { if (!AAS_AreaGrounded(link->areanum)) continue; //find a non-portal area adjacent to the portal area and flood //the cluster from there area = &aasworld.areas[link->areanum]; for (j = 0; j < area->numfaces; j++) { facenum = abs(aasworld.faceindex[area->firstface + j]); face = &aasworld.faces[facenum]; // if (face->frontarea != link->areanum) otherareanum = face->frontarea; else otherareanum = face->backarea; // if (!otherareanum) continue; // if (aasworld.areasettings[otherareanum].contents & AREACONTENTS_CLUSTERPORTAL) { continue; } //end if // AAS_FloodCluster_r(otherareanum, 1); } //end for } //end for //if the teleport destination IS in the same cluster if (aasworld.areasettings[area2num].cluster) { for (link = areas; link; link = link->next_area) { if (!AAS_AreaGrounded(link->areanum)) continue; //add the teleporter portal mark aasworld.areasettings[link->areanum].contents &= ~(AREACONTENTS_CLUSTERPORTAL | AREACONTENTS_TELEPORTAL); } //end for } //end if } //end if } //end for AAS_FreeBSPEntities(entities); } //end of the function AAS_AddTeleporterPortals
//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== void AAS_ParseBSPEntities(void) { script_t *script; token_t token; bsp_entity_t *ent; bsp_epair_t *epair; script = LoadScriptMemory(bspworld.dentdata, bspworld.entdatasize, "entdata"); SetScriptFlags(script, SCFL_NOSTRINGWHITESPACES|SCFL_NOSTRINGESCAPECHARS);//SCFL_PRIMITIVE); bspworld.numentities = 1; while(PS_ReadToken(script, &token)) { if (strcmp(token.string, "{")) { ScriptError(script, "invalid %s", token.string); AAS_FreeBSPEntities(); FreeScript(script); return; } //end if if (bspworld.numentities >= MAX_BSPENTITIES) { botimport.Print(PRT_MESSAGE, "too many entities in BSP file\n"); break; } //end if ent = &bspworld.entities[bspworld.numentities]; bspworld.numentities++; ent->epairs = NULL; while(PS_ReadToken(script, &token)) { if (!strcmp(token.string, "}")) break; epair = (bsp_epair_t *) GetClearedHunkMemory(sizeof(bsp_epair_t)); epair->next = ent->epairs; ent->epairs = epair; if (token.type != TT_STRING) { ScriptError(script, "invalid %s", token.string); AAS_FreeBSPEntities(); FreeScript(script); return; } //end if StripDoubleQuotes(token.string); epair->key = (char *) GetHunkMemory(strlen(token.string) + 1); strcpy(epair->key, token.string); if (!PS_ExpectTokenType(script, TT_STRING, 0, &token)) { AAS_FreeBSPEntities(); FreeScript(script); return; } //end if StripDoubleQuotes(token.string); epair->value = (char *) GetHunkMemory(strlen(token.string) + 1); strcpy(epair->value, token.string); } //end while if (strcmp(token.string, "}")) { ScriptError(script, "missing }"); AAS_FreeBSPEntities(); FreeScript(script); return; } //end if } //end while FreeScript(script); } //end of the function AAS_ParseBSPEntities