| 1 | /* ------------------------------------------------------------------------------- |
| 2 | |
| 3 | Copyright (C) 1999-2013 id Software, Inc. and contributors. |
| 4 | For a list of contributors, see the accompanying CONTRIBUTORS file. |
| 5 | |
| 6 | This file is part of GtkRadiant. |
| 7 | |
| 8 | GtkRadiant is free software; you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation; either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | GtkRadiant is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with GtkRadiant; if not, write to the Free Software |
| 20 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 21 | |
| 22 | ---------------------------------------------------------------------------------- |
| 23 | |
| 24 | This code has been altered significantly from its original form, to support |
| 25 | several games based on the Quake III Arena engine, in the form of "Q3Map2." |
| 26 | |
| 27 | ------------------------------------------------------------------------------- */ |
| 28 | |
| 29 | |
| 30 | |
| 31 | /* marker */ |
| 32 | #define EXPORTENTS_C |
| 33 | |
| 34 | |
| 35 | |
| 36 | /* dependencies */ |
| 37 | #include "q3map2.h" |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | /* ------------------------------------------------------------------------------- |
| 43 | |
| 44 | this file contains code that exports entities to a .ent file. |
| 45 | |
| 46 | ------------------------------------------------------------------------------- */ |
| 47 | |
| 48 | /* |
| 49 | ExportEntities() |
| 50 | exports the entities to a text file (.ent) |
| 51 | */ |
| 52 | |
| 53 | void ExportEntities( void ){ |
| 54 | char filename[ 1024 ]; |
| 55 | FILE *file; |
| 56 | |
| 57 | /* note it */ |
| 58 | Sys_FPrintf( SYS_VRB, "--- ExportEntities ---\n" ); |
| 59 | |
| 60 | /* do some path mangling */ |
| 61 | strcpy( filename, source ); |
| 62 | StripExtension( filename ); |
| 63 | strcat( filename, ".ent" ); |
| 64 | |
| 65 | /* sanity check */ |
| 66 | if ( bspEntData == NULL || bspEntDataSize == 0 ) { |
| 67 | Sys_FPrintf( SYS_WRN, "WARNING: No BSP entity data. aborting...\n" ); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | /* write it */ |
| 72 | Sys_Printf( "Writing %s\n", filename ); |
| 73 | Sys_FPrintf( SYS_VRB, "(%d bytes)\n", bspEntDataSize ); |
| 74 | file = fopen( filename, "w" ); |
| 75 | |
| 76 | if ( file == NULL ) { |
| 77 | Error( "Unable to open %s for writing", filename ); |
| 78 | } |
| 79 | |
| 80 | fprintf( file, "%s\n", bspEntData ); |
| 81 | fclose( file ); |
| 82 | } |
| 83 | |
| 84 | |
| 85 | |
| 86 | /* |
| 87 | ExportEntitiesMain() |
| 88 | exports the entities to a text file (.ent) |
| 89 | */ |
| 90 | |
| 91 | int ExportEntitiesMain( int argc, char **argv ){ |
| 92 | /* arg checking */ |
| 93 | if ( argc < 2 ) { |
| 94 | Sys_Printf( "Usage: q3map -exportents [-v] <mapname>\n" ); |
| 95 | return 0; |
| 96 | } |
| 97 | |
| 98 | /* do some path mangling */ |
| 99 | strcpy( source, ExpandArg( argv[ argc - 1 ] ) ); |
| 100 | StripExtension( source ); |
| 101 | DefaultExtension( source, ".bsp" ); |
| 102 | |
| 103 | /* load the bsp */ |
| 104 | Sys_Printf( "Loading %s\n", source ); |
| 105 | LoadBSPFile( source ); |
| 106 | |
| 107 | /* export the lightmaps */ |
| 108 | ExportEntities(); |
| 109 | |
| 110 | /* return to sender */ |
| 111 | return 0; |
| 112 | } |