Index: src/game/g_spawn.c =================================================================== --- src/game/g_spawn.c (revision 875) +++ src/game/g_spawn.c (working copy) @@ -327,6 +327,10 @@ //check buildable spawn functions if( ( buildable = BG_FindBuildNumForEntityName( ent->classname ) ) != BA_NONE ) { + // don't spawn built-in buildings if we are using a custom layout + if( level.layout[ 0 ] ) + return qtrue; + if( buildable == BA_A_SPAWN || buildable == BA_H_SPAWN ) { ent->s.angles[ YAW ] += 180.0f; Index: src/game/g_svcmds.c =================================================================== --- src/game/g_svcmds.c (revision 875) +++ src/game/g_svcmds.c (working copy) @@ -475,9 +475,75 @@ //FIXME: tremulise this } +/* +=================== +Svcmd_LayoutSave_f + +layoutsave +=================== +*/ +void Svcmd_LayoutSave_f( void ) +{ + char str[ MAX_QPATH ]; + char str2[ MAX_QPATH - 4 ]; + char *s; + int i = 0; + + if( trap_Argc( ) != 2 ) + { + G_Printf( "usage: layoutsave LAYOUTNAME\n" ); + return; + } + trap_Argv( 1, str, sizeof( str ) ); + + // sanitize name + s = &str[ 0 ]; + while( *s && i < sizeof( str2 ) - 1 ) + { + if( ( *s >= '0' && *s <= '9' ) || + ( *s >= 'a' && *s <= 'z' ) || + ( *s >= 'A' && *s <= 'Z' ) ) + { + str2[ i++ ] = *s; + str2[ i ] = '\0'; + } + s++; + } + + if( !str2[ 0 ] ) + { + G_Printf("layoutsave: invalid name \"%s\"\n", str ); + return; + } + + G_LayoutSave( str2 ); +} + char *ConcatArgs( int start ); /* +=================== +Svcmd_LayoutLoad_f + +layoutload [ [ [biteam = built->s.modelindex2 = BG_FindTeamForBuildable( buildable ); BG_FindBBoxForBuildable( buildable, built->r.mins, built->r.maxs ); + + // detect the buildable's normal vector + if( !builder->client ) + { + // initial base layout created by server + + if( builder->s.origin2[ 0 ] + || builder->s.origin2[ 1 ] + || builder->s.origin2[ 2 ] ) + { + VectorCopy( builder->s.origin2, normal ); + } + else + { + VectorSet( normal, 0.0f, 0.0f, 1.0f ); + } + } + else + { + // in-game building by a player + + if( builder->client->ps.stats[ STAT_STATE ] & SS_WALLCLIMBING ) + { + if( builder->client->ps.stats[ STAT_STATE ] & SS_WALLCLIMBINGCEILING ) + VectorSet( normal, 0.0f, 0.0f, -1.0f ); + else + VectorCopy( builder->client->ps.grapplePoint, normal ); + + //gently nudge the buildable onto the surface :) + VectorScale( normal, -50.0f, built->s.pos.trDelta ); + } + else + { + VectorSet( normal, 0.0f, 0.0f, 1.0f ); + } + } + + // when building the initial layout, spawn the entity slightly off its + // target surface so that it can be "dropped" onto it + if( !builder->client ) + VectorMA( origin, 1.0f, normal, origin ); + + // gently nudge the buildable onto the surface :) + VectorScale( normal, -50.0f, built->s.pos.trDelta ); + + // set turret angles + VectorCopy( builder->s.angles2, built->s.angles2 ); + built->health = 1; built->splashDamage = BG_FindSplashDamageForBuildable( buildable ); @@ -2853,19 +2901,6 @@ built->physicsBounce = BG_FindBounceForBuildable( buildable ); built->s.groundEntityNum = -1; - if( builder->client && builder->client->ps.stats[ STAT_STATE ] & SS_WALLCLIMBING ) - { - if( builder->client->ps.stats[ STAT_STATE ] & SS_WALLCLIMBINGCEILING ) - VectorSet( normal, 0.0f, 0.0f, -1.0f ); - else - VectorCopy( builder->client->ps.grapplePoint, normal ); - - //gently nudge the buildable onto the surface :) - VectorScale( normal, -50.0f, built->s.pos.trDelta ); - } - else - VectorSet( normal, 0.0f, 0.0f, 1.0f ); - built->s.generic1 = (int)( ( (float)built->health / (float)BG_FindHealthForBuildable( buildable ) ) * B_HEALTH_SCALE ); @@ -3023,7 +3058,12 @@ built->s.generic1 |= B_SPAWNED_TOGGLEBIT; // drop to floor - if( buildable != BA_NONE && BG_FindTrajectoryForBuildable( buildable ) == TR_BUOYANCY ) + if( built->s.origin2[ 0 ] || built->s.origin2[ 1 ] || built->s.origin2[ 2 ] ) + { + VectorScale( built->s.origin2, -4096.0f, dest ); + VectorAdd( dest, built->s.origin, dest ); + } + else if( buildable != BA_NONE && BG_FindTrajectoryForBuildable( buildable ) == TR_BUOYANCY ) VectorSet( dest, built->s.origin[ 0 ], built->s.origin[ 1 ], built->s.origin[ 2 ] + 4096 ); else VectorSet( dest, built->s.origin[ 0 ], built->s.origin[ 1 ], built->s.origin[ 2 ] - 4096 ); @@ -3067,3 +3107,232 @@ ent->nextthink = level.time + FRAMETIME * 2; ent->think = FinishSpawningBuildable; } + +/* +============ +G_LayoutSave + +============ +*/ +void G_LayoutSave( char *name ) +{ + char map[ MAX_CVAR_VALUE_STRING ]; + char fileName[ MAX_OSPATH ]; + fileHandle_t f; + int len; + int i; + gentity_t *ent; + char *s; + + trap_Cvar_VariableStringBuffer( "mapname", map, sizeof( map ) ); + if( !map[ 0 ] ) + { + G_Printf( "LayoutSave( ): no map is loaded\n" ); + return; + } + Com_sprintf( fileName, sizeof( fileName ), "layouts/%s/%s.dat", map, name ); + + len = trap_FS_FOpenFile( fileName, &f, FS_WRITE ); + if( len < 0 ) + { + G_Printf( "layoutsave: could not open %s\n", fileName ); + return; + } + + G_Printf("layoutsave: saving layout to %s\n", fileName ); + + for( i = MAX_CLIENTS; i < level.num_entities; i++ ) + { + ent = &level.gentities[ i ]; + if( ent->s.eType != ET_BUILDABLE ) + continue; + + s = va( "%i %f %f %f %f %f %f %f %f %f %f %f %f\n", + ent->s.modelindex, + ent->s.pos.trBase[ 0 ], + ent->s.pos.trBase[ 1 ], + ent->s.pos.trBase[ 2 ], + ent->s.angles[ 0 ], + ent->s.angles[ 1 ], + ent->s.angles[ 2 ], + ent->s.origin2[ 0 ], + ent->s.origin2[ 1 ], + ent->s.origin2[ 2 ], + ent->s.angles2[ 0 ], + ent->s.angles2[ 1 ], + ent->s.angles2[ 2 ] ); + trap_FS_Write( s, strlen( s ), f ); + } + trap_FS_FCloseFile( f ); +} + +#define MAX_LAYOUT_FILES 32 +/* +============ +G_LayoutSelect + +set level.layout based on g_layouts or g_layoutAuto +============ +*/ +void G_LayoutSelect( void ) +{ + char fileName[ MAX_OSPATH ]; + char layouts[ MAX_CVAR_VALUE_STRING ]; + char layouts2[ MAX_CVAR_VALUE_STRING ]; + char *l; + char map[ MAX_CVAR_VALUE_STRING ]; + char *s; + int cnt = 0; + int layoutNum; + + Q_strncpyz( layouts, g_layouts.string, sizeof( layouts ) ); + trap_Cvar_VariableStringBuffer( "mapname", map, sizeof( map ) ); + + // one time use cvar + trap_Cvar_Set( "g_layouts", "" ); + + // pick an included layout at random if no list has been provided + if( !layouts[ 0 ] && g_layoutAuto.integer ) + { + char fileList[ ( MAX_QPATH + 1 ) * MAX_LAYOUT_FILES ] = {""}; + int numFiles, i, fileLen = 0; + char *filePtr; + + numFiles = trap_FS_GetFileList( va( "layouts/%s", map ), ".dat", + fileList, sizeof( fileList ) ); + filePtr = fileList; + for( i = 0; i < numFiles; i++, filePtr += fileLen + 1 ) + { + fileLen = strlen( filePtr ); + Q_strcat( layouts, sizeof( layouts ), filePtr ); + + // strip extenstion and add space delimiter + layouts[ strlen( layouts ) - 4 ] = ' '; + layouts[ strlen( layouts ) - 3 ] = '\0'; + } + } + + if( !layouts[ 0 ] ) + return; + + Q_strncpyz( layouts2, layouts, sizeof( layouts2 ) ); + l = &layouts2[ 0 ]; + layouts[ 0 ] = '\0'; + s = COM_ParseExt( &l, qfalse ); + while( *s ) + { + Com_sprintf( fileName, sizeof( fileName ), "layouts/%s/%s.dat", map, s ); + if( trap_FS_FOpenFile( fileName, NULL, FS_READ ) > 0 ) + { + Q_strcat( layouts, sizeof( layouts ), s ); + Q_strcat( layouts, sizeof( layouts ), " " ); + cnt++; + } + else + G_Printf( S_COLOR_YELLOW "WARNING: layout \"%s\" does not exist\n", s ); + s = COM_ParseExt( &l, qfalse ); + } + if( !cnt ) + { + G_Printf( S_COLOR_RED "ERROR: none of the specified layouts could be " + "found, using map default\n" ); + return; + } + layoutNum = ( rand( ) & ( cnt - 1 ) ) + 1; + cnt = 0; + + Q_strncpyz( layouts2, layouts, sizeof( layouts2 ) ); + l = &layouts2[ 0 ]; + s = COM_ParseExt( &l, qfalse ); + while( *s ) + { + Q_strncpyz( level.layout, s, sizeof( level.layout ) ); + cnt++; + if( cnt >= layoutNum ) + break; + s = COM_ParseExt( &l, qfalse ); + } + G_Printf("using layout \"%s\" from list ( %s)\n", level.layout, layouts ); +} + +static void G_LayoutBuildItem( buildable_t buildable, vec3_t origin, + vec3_t angles, vec3_t origin2, vec3_t angles2 ) +{ + gentity_t *builder; + + builder = G_Spawn( ); + builder->client = 0; + VectorCopy( origin, builder->s.pos.trBase ); + VectorCopy( angles, builder->s.angles ); + VectorCopy( origin2, builder->s.origin2 ); + VectorCopy( angles2, builder->s.angles2 ); + G_SpawnBuildable( builder, buildable ); +} + +/* +============ +G_LayoutLoad + +load the layout .dat file indicated by level.layout and spawn buildables +as if a builder was creating them +============ +*/ +void G_LayoutLoad( void ) +{ + fileHandle_t f; + int len; + char *layout; + char map[ MAX_CVAR_VALUE_STRING ]; + int buildable = BA_NONE; + vec3_t origin = { 0.0f, 0.0f, 0.0f }; + vec3_t angles = { 0.0f, 0.0f, 0.0f }; + vec3_t origin2 = { 0.0f, 0.0f, 0.0f }; + vec3_t angles2 = { 0.0f, 0.0f, 0.0f }; + char line[ MAX_STRING_CHARS ]; + int i = 0; + + if( !level.layout[ 0 ] ) + return; + + trap_Cvar_VariableStringBuffer( "mapname", map, sizeof( map ) ); + len = trap_FS_FOpenFile( va( "layouts/%s/%s.dat", map, level.layout ), + &f, FS_READ ); + if( len < 0 ) + { + G_Printf( "ERROR: layout %s could not be opened\n", level.layout ); + return; + } + layout = G_Alloc( len + 1 ); + trap_FS_Read( layout, len, f ); + *( layout + len ) = '\0'; + trap_FS_FCloseFile( f ); + while( *layout ) + { + if( i >= sizeof( line ) - 1 ) + { + G_Printf( S_COLOR_RED "ERROR: line overflow in %s before \"%s\"\n", + va( "layouts/%s/%s.dat", map, level.layout ), line ); + return; + } + line[ i++ ] = *layout; + line[ i ] = '\0'; + if( *layout == '\n' ) + { + i = 0; + sscanf( line, "%d %f %f %f %f %f %f %f %f %f %f %f %f\n", + &buildable, + &origin[ 0 ], &origin[ 1 ], &origin[ 2 ], + &angles[ 0 ], &angles[ 1 ], &angles[ 2 ], + &origin2[ 0 ], &origin2[ 1 ], &origin2[ 2 ], + &angles2[ 0 ], &angles2[ 1 ], &angles2[ 2 ] ); + + if( buildable > BA_NONE && buildable < BA_NUM_BUILDABLES ) + G_LayoutBuildItem( buildable, origin, angles, origin2, angles2 ); + else + G_Printf( S_COLOR_YELLOW "WARNING: bad buildable number (%d) in " + " layout. skipping\n", buildable ); + } + layout++; + } +} + Index: src/game/g_main.c =================================================================== --- src/game/g_main.c (revision 875) +++ src/game/g_main.c (working copy) @@ -120,6 +120,9 @@ vmCvar_t g_mapConfigs; vmCvar_t g_chatTeamPrefix; +vmCvar_t g_layouts; +vmCvar_t g_layoutAuto; + vmCvar_t g_admin; vmCvar_t g_adminLog; vmCvar_t g_adminParseSay; @@ -234,6 +237,9 @@ { &g_mapConfigs, "g_mapConfigs", "", CVAR_ARCHIVE, 0, qfalse }, { NULL, "g_mapConfigsLoaded", "0", CVAR_ROM, 0, qfalse }, + { &g_layouts, "g_layouts", "", CVAR_LATCH, 0, qfalse }, + { &g_layoutAuto, "g_layoutAuto", "1", CVAR_ARCHIVE, 0, qfalse }, + { &g_admin, "g_admin", "admin.dat", CVAR_ARCHIVE, 0, qfalse }, { &g_adminLog, "g_adminLog", "admin.log", CVAR_ARCHIVE, 0, qfalse }, { &g_adminParseSay, "g_adminParseSay", "1", CVAR_ARCHIVE, 0, qfalse }, @@ -590,9 +596,15 @@ trap_SetConfigstring( CS_INTERMISSION, "0" ); + // test to see if a custom buildable layout will be loaded + G_LayoutSelect( ); + // parse the key/value pairs and spawn gentities G_SpawnEntitiesFromString( ); + // load up a custom building layout if there is one + G_LayoutLoad( ); + // the map might disable some things BG_InitAllowedGameElements( ); Index: src/game/g_weapon.c =================================================================== --- src/game/g_weapon.c (revision 875) +++ src/game/g_weapon.c (working copy) @@ -779,6 +779,9 @@ // don't want it bigger than 32k if( ent->client->ps.stats[ STAT_MISC ] > 30000 ) ent->client->ps.stats[ STAT_MISC ] = 30000; + + if( g_cheats.integer) + ent->client->ps.stats[ STAT_MISC ] = 0; } return; } Index: src/game/g_maprotation.c =================================================================== --- src/game/g_maprotation.c (revision 875) +++ src/game/g_maprotation.c (working copy) @@ -52,6 +52,19 @@ if( !Q_stricmp( token, "}" ) ) return qtrue; //reached the end of this command section + if( !Q_stricmp( token, "layouts" ) ) + { + token = COM_ParseExt( text_p, qfalse ); + mre->layouts[ 0 ] = '\0'; + while( token && token[ 0 ] != 0 ) + { + Q_strcat( mre->layouts, sizeof( mre->layouts ), token ); + Q_strcat( mre->layouts, sizeof( mre->layouts ), " " ); + token = COM_ParseExt( text_p, qfalse ); + } + continue; + } + Q_strncpyz( mre->postCmds[ mre->numCmds ], token, sizeof( mre->postCmds[ 0 ] ) ); Q_strcat( mre->postCmds[ mre->numCmds ], sizeof( mre->postCmds[ 0 ] ), " " ); @@ -476,6 +489,14 @@ int map = G_GetCurrentMap( rotation ); char cmd[ MAX_TOKEN_CHARS ]; + // allow a manually defined g_layouts setting to override the maprotation + if( !g_layouts.string[ 0 ] && + mapRotations.rotations[ rotation ].maps[ map ].layouts[ 0 ] ) + { + trap_Cvar_Set( "g_layouts", + mapRotations.rotations[ rotation ].maps[ map ].layouts ); + } + trap_SendConsoleCommand( EXEC_APPEND, va( "map %s\n", mapRotations.rotations[ rotation ].maps[ map ].name ) ); Index: src/game/g_cmds.c =================================================================== --- src/game/g_cmds.c (revision 875) +++ src/game/g_cmds.c (working copy) @@ -1776,9 +1776,10 @@ G_Damage( traceEnt, ent, ent, forward, tr.endpos, 10000, 0, MOD_SUICIDE ); else G_FreeEntity( traceEnt ); - - ent->client->ps.stats[ STAT_MISC ] += - BG_FindBuildDelayForWeapon( ent->s.weapon ) >> 2; + + if( !g_cheats.integer ) + ent->client->ps.stats[ STAT_MISC ] += + BG_FindBuildDelayForWeapon( ent->s.weapon ) >> 2; } } }