From 6309be1a9c63e1ad9eb2c48ac52be173f9183dbb Mon Sep 17 00:00:00 2001 From: Paweł Redman Date: Wed, 1 Apr 2020 00:02:13 +0200 Subject: Building anarchy --- src/game/g_buildable.c | 224 +------------------------------------------------ 1 file changed, 4 insertions(+), 220 deletions(-) diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c index 9fd6f1e..d5c6ad6 100644 --- a/src/game/g_buildable.c +++ b/src/game/g_buildable.c @@ -3362,231 +3362,15 @@ Checks to see if a buildable can be built itemBuildError_t G_CanBuild( gentity_t *ent, buildable_t buildable, int distance, vec3_t origin ) { vec3_t angles; - vec3_t entity_origin, normal; - vec3_t mins, maxs, nbmins, nbmaxs; - vec3_t nbVect; - trace_t tr1, tr2, tr3; - int i; - itemBuildError_t reason = IBE_NONE; - gentity_t *tempent; - float minNormal; - qboolean invert; - int contents; + vec3_t entity_origin; + vec3_t mins, maxs; + trace_t tr1; playerState_t *ps = &ent->client->ps; - gentity_t *tmp; - itemBuildError_t tempReason; - - // Stop all buildables from interacting with traces - G_SetBuildableLinkState( qfalse ); BG_FindBBoxForBuildable( buildable, mins, maxs ); - BG_PositionBuildableRelativeToPlayer( ps, mins, maxs, trap_Trace, entity_origin, angles, &tr1 ); - - trap_Trace( &tr2, entity_origin, mins, maxs, entity_origin, ent->s.number, MASK_PLAYERSOLID ); - trap_Trace( &tr3, ps->origin, NULL, NULL, entity_origin, ent->s.number, MASK_PLAYERSOLID ); - VectorCopy( entity_origin, origin ); - - VectorCopy( tr1.plane.normal, normal ); - minNormal = BG_FindMinNormalForBuildable( buildable ); - invert = BG_FindInvertNormalForBuildable( buildable ); - - //can we build at this angle? - if( !( normal[ 2 ] >= minNormal || ( invert && normal[ 2 ] <= -minNormal ) ) ) - reason = IBE_NORMAL; - - if( tr1.entityNum != ENTITYNUM_WORLD ) - reason = IBE_NORMAL; - - contents = trap_PointContents( entity_origin, -1 ); - - //check if we are near a nobuild marker, if so, can't build here... - for( i = 0; i < MAX_GENTITIES; i++ ) - { - tmp = &g_entities[ i ]; - - if( !tmp->noBuild.isNB ) - continue; - - nbVect[0] = tmp->noBuild.Area; - nbVect[1] = tmp->noBuild.Area; - nbVect[2] = tmp->noBuild.Height; - - VectorSubtract( origin, nbVect, nbmins ); - VectorAdd( origin, nbVect, nbmaxs ); - - if( trap_EntityContact( nbmins, nbmaxs, tmp ) ) - reason = IBE_PERMISSION; - - } - if( ent->client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS ) - { - //alien criteria - - if( buildable == BA_A_HOVEL ) - { - vec3_t builderMins, builderMaxs; - - //this assumes the adv builder is the biggest thing that'll use the hovel - BG_FindBBoxForClass( PCL_ALIEN_BUILDER0_UPG, builderMins, builderMaxs, NULL, NULL, NULL ); - - if( APropHovel_Blocked( origin, angles, normal, ent ) ) - reason = IBE_HOVELEXIT; - } - - //check there is creep near by for building on - if( BG_FindCreepTestForBuildable( buildable ) ) - { - if( !G_IsCreepHere( entity_origin ) ) - reason = IBE_NOCREEP; - } - - //check permission to build here - if( tr1.surfaceFlags & SURF_NOALIENBUILD || tr1.surfaceFlags & SURF_NOBUILD || - contents & CONTENTS_NOALIENBUILD || contents & CONTENTS_NOBUILD ) - reason = IBE_PERMISSION; - - //look for an Overmind - for ( i = 1, tempent = g_entities + i; i < level.num_entities; i++, tempent++ ) - { - if( tempent->s.eType != ET_BUILDABLE ) - continue; - if( tempent->s.modelindex == BA_A_OVERMIND && tempent->spawned && - tempent->health > 0 ) - break; - } - - //if none found... - if( i >= level.num_entities && buildable != BA_A_OVERMIND ) - reason = IBE_NOOVERMIND; - - //can we only have one of these? - if( BG_FindUniqueTestForBuildable( buildable ) ) - { - for ( i = 1, tempent = g_entities + i; i < level.num_entities; i++, tempent++ ) - { - if( tempent->s.eType != ET_BUILDABLE ) - continue; - - if( tempent->s.modelindex == buildable && !tempent->deconstruct ) - { - switch( buildable ) - { - case BA_A_OVERMIND: - reason = IBE_OVERMIND; - break; - - case BA_A_HOVEL: - reason = IBE_HOVEL; - break; - - default: - Com_Error( ERR_FATAL, "No reason for denying build of %d\n", buildable ); - break; - } - - break; - } - } - } - } - else if( ent->client->ps.stats[ STAT_PTEAM ] == PTE_HUMANS ) - { - //human criteria - if( !G_IsPowered( entity_origin ) ) - { - //tell player to build a repeater to provide power - if( buildable != BA_H_REACTOR && buildable != BA_H_REPEATER ) - reason = IBE_REPEATER; - } - - //this buildable requires a DCC - if( BG_FindDCCTestForBuildable( buildable ) && !G_IsDCCBuilt( ) ) - reason = IBE_NODCC; - - //check that there is a parent reactor when building a repeater - if( buildable == BA_H_REPEATER ) - { - for ( i = 1, tempent = g_entities + i; i < level.num_entities; i++, tempent++ ) - { - if( tempent->s.eType != ET_BUILDABLE ) - continue; - - if( tempent->s.modelindex == BA_H_REACTOR ) - break; - } - - if( i >= level.num_entities ) - { - //no reactor present - - //check for other nearby repeaters - for ( i = 1, tempent = g_entities + i; i < level.num_entities; i++, tempent++ ) - { - if( tempent->s.eType != ET_BUILDABLE ) - continue; - - if( tempent->s.modelindex == BA_H_REPEATER && - Distance( tempent->s.origin, entity_origin ) < REPEATER_BASESIZE ) - { - reason = IBE_RPTWARN2; - break; - } - } - - if( reason == IBE_NONE ) - reason = IBE_RPTWARN; - } - else if( G_IsPowered( entity_origin ) ) - reason = IBE_RPTWARN2; - } - - //check permission to build here - if( tr1.surfaceFlags & SURF_NOHUMANBUILD || tr1.surfaceFlags & SURF_NOBUILD || - contents & CONTENTS_NOHUMANBUILD || contents & CONTENTS_NOBUILD ) - reason = IBE_PERMISSION; - - //can we only build one of these? - if( BG_FindUniqueTestForBuildable( buildable ) ) - { - for ( i = 1, tempent = g_entities + i; i < level.num_entities; i++, tempent++ ) - { - if( tempent->s.eType != ET_BUILDABLE ) - continue; - - if( tempent->s.modelindex == BA_H_REACTOR && !tempent->deconstruct ) - { - reason = IBE_REACTOR; - break; - } - } - } - } - - if( ( tempReason = G_SufficientBPAvailable( buildable, origin ) ) != IBE_NONE ) - reason = tempReason; - - // Relink buildables - G_SetBuildableLinkState( qtrue ); - - //check there is enough room to spawn from (presuming this is a spawn) - if( reason == IBE_NONE ) - { - G_SetBuildableMarkedLinkState( qfalse ); - if( G_CheckSpawnPoint( ENTITYNUM_NONE, origin, normal, buildable, NULL ) != NULL ) - reason = IBE_NORMAL; - G_SetBuildableMarkedLinkState( qtrue ); - } - - //this item does not fit here - if( reason == IBE_NONE && ( tr2.fraction < 1.0 || tr3.fraction < 1.0 ) ) - return IBE_NOROOM; - - if( reason != IBE_NONE ) - level.numBuildablesForRemoval = 0; - - return reason; + return IBE_NONE; } /* -- cgit