From 1fbd9796e2096b33576c3345dce585f6832092a8 Mon Sep 17 00:00:00 2001 From: Harry Young Date: Mon, 5 Dec 2011 17:12:23 +0100 Subject: [PATCH] Buggy fixes for misc_laser-turret Signed-off-by: Harry Young --- cgame/cg_env.c | 217 +++++++++++++++++++++++++++++++++++++++++++++++ cgame/cg_local.h | 2 + cgame/fx_local.h | 7 ++ game/g_local.h | 3 +- game/g_spawn.c | 2 +- game/g_turrets.c | 22 ++--- game/q_shared.h | 1 + 7 files changed, 241 insertions(+), 13 deletions(-) diff --git a/cgame/cg_env.c b/cgame/cg_env.c index 22cb7ef..0ef2f65 100644 --- a/cgame/cg_env.c +++ b/cgame/cg_env.c @@ -1230,6 +1230,223 @@ void CG_DisruptorFX(centity_t *cent) { // Additional ports from SP by Harry Young +/* +=========================== +Laser + +Create directed laser shot +=========================== +*/ +void CG_SmallSpark( vec3_t origin, vec3_t normal ) +{ + vec3_t dir, direction, start, end, velocity; + float scale; + int numSparks; + + AngleVectors( normal, normal, NULL, NULL ); + + int j; + for ( j = 0; j < 3; j ++ ) + normal[j] = normal[j] + (0.1f * crandom()); + + VectorNormalize( normal ); + + numSparks = 6 + (random() * 4.0f ); + + int i; + for ( i = 0; i < numSparks; i++ ) + { + scale = 0.1f + (random() *0.2f ); + + for ( j = 0; j < 3; j ++ ) + dir[j] = normal[j] + (0.7f * crandom()); + + VectorMA( origin, 0.0f + ( random() * 0.5f ), dir, start ); + VectorMA( start, 1.0f + ( random() * 1.5f ), dir, end ); + + FX_AddLine( start, + end, + 1.0f, + scale, + 0.0f, + 1.0f, + 0.7f, + 4.0f, + cgs.media.sparkShader ); + } + + VectorMA( origin, 1, normal, direction ); + + scale = 2.0f + (random() * 3.0f ); + float alpha = 0.6f + (random() * 0.4f ); + + VectorSet( velocity, crandom() * 2, crandom() * 2, 8 + random() * 4 ); + VectorMA( velocity, 5, normal, velocity ); + + FX_AddSprite( direction, + velocity, + qfalse, + scale, + scale, + alpha, + 0.0f, + random() * 45.0f, + 0.0f, + 1000.0f, + cgs.media.steamShader ); +} + + +void CG_FireLaser( vec3_t start, vec3_t end, vec3_t normal, vec4_t laserRGB, qboolean hit_ent ) +{ + vec3_t dir, right, up, angles, work, pos, + sRGB, lRGB; + float scale = 1.0f, alpha; + int life = 0; + + if ( !(FX_DetailLevel( start, 16, 1200 ) )) + return; + + // Orient the laser spray + VectorSubtract( end, start, dir ); + VectorNormalize( dir ); + alpha = Vector4to3( laserRGB, lRGB ); + + VectorMA( end, 0.5f, normal, pos ); + MakeNormalVectors( normal, right, up ); + + VectorSet( sRGB, 1.0f, 0.8f, 0.8f ); + + FX_AddSprite2( start, NULL, qfalse, + 1.75f, 1.0f, + alpha, 0.0f, + lRGB, lRGB, + 0.0f, + 0.0f, + 200, + cgs.media.waterDropShader ); + + FX_AddLine3( start, end, + 1.0f, + 3.0f, 5.0f, + alpha, 0.0f, + lRGB, lRGB, + 125, + cgs.media.whiteLaserShader ); + + FX_AddLine( start, end, + 1.0f, + 0.3f, 5.0f, + random() * 0.4 + 0.4, 0.1f, + 125, + cgs.media.whiteLaserShader ); + + // Doing all of this extra stuff would look weird if it hits a player ent. + if ( !hit_ent ) + { + FX_AddQuad2( pos, normal, + 3.5f, 1.0f, + alpha, 0.0f, + lRGB, lRGB, + 0.0f, + 200, + cgs.media.waterDropShader ); + int t; + for ( t=0; t < 2; t ++ ) + { + VectorMA( pos, crandom() * 0.5f, right, work ); + VectorMA( work, crandom() * 0.5f, up, work ); + + scale = crandom() * 0.5f + 1.75f; + life = crandom() * 300 + 2100; + + VectorSet( sRGB, 1.0f, 0.7f, 0.2f ); + FX_AddQuad2( work, normal, + scale, -0.1f, + 1.0f, 0.0f, + sRGB, sRGB, + 0, + life, + cgs.media.waterDropShader ); + } + + FX_AddQuad( pos, normal, + scale * 2.5f, 0.0f, + 1.0f, 0.0f, + 0, + life * 2, + cgs.media.smokeShader ); + + vectoangles( normal, angles ); + CG_SmallSpark( end, angles ); + } + else + { + // However, do add a little smoke puff + FX_AddSprite2( pos, NULL, qfalse, + 2.0f, 1.0f, + alpha, 0.0f, + lRGB, lRGB, + 0.0f, + 0.0f, + 200, + cgs.media.waterDropShader ); + + VectorMA( end, 1, normal, dir ); + scale = 1.0f + (random() * 3.0f); + + CG_Smoke( dir, normal, scale, 12.0f ); + } +} + +//------------------------------------------------------------------------------ +void CG_AimLaser( vec3_t start, vec3_t end, vec3_t normal ) +{ + vec3_t lRGB = {1.0,0.0,0.0}; + + // Beam + FX_AddLine3( start, end, + 1.0f, + 5.5f, 5.0f, + random() * 0.2 + 0.2, 0.1f, + lRGB, lRGB, + 150, + cgs.media.whiteLaserShader ); + + FX_AddLine( start, end, + 1.0f, + 0.3f, 5.0f, + random() * 0.4 + 0.4, 0.1f, + 125, + cgs.media.whiteLaserShader ); + + // Flare at the start point + FX_AddSprite( start, NULL, qfalse, + 1.5 + random() * 4, 0.0, + 0.1f,0.0, + 0.0, + 0.0, + 100, + cgs.media.borgEyeFlareShader ); + + // endpoint flare + FX_AddSprite( end, NULL, qfalse, + 2.5 + random() * 4, 0.0, + 0.1f,0.0, + 0.0, + 0.0, + 100, + cgs.media.borgEyeFlareShader ); + + // oriented impact flare + FX_AddQuad( end, normal, + 1.5 + random() * 2, 0.0, + 1.0, 0.0, + 0.0, + 120, + cgs.media.borgEyeFlareShader ); +} + /* ====================== CG_CookingSteam diff --git a/cgame/cg_local.h b/cgame/cg_local.h index 34ffdf8..01114ec 100644 --- a/cgame/cg_local.h +++ b/cgame/cg_local.h @@ -2034,6 +2034,8 @@ void CG_Bolt( centity_t *cent ); void CG_TransporterPad(vec3_t origin); void CG_Drip(centity_t *cent, int killTime ); void CG_Chunks( vec3_t origin, vec3_t dir, float size, material_type_t type ); +void CG_FireLaser( vec3_t start, vec3_t end, vec3_t normal, vec4_t laserRGB, qboolean hit_ent ); +void CG_AimLaser( vec3_t start, vec3_t end, vec3_t normal ); //TiM void CG_FountainSpurt( vec3_t org, vec3_t end ); diff --git a/cgame/fx_local.h b/cgame/fx_local.h index 65b5998..f666068 100644 --- a/cgame/fx_local.h +++ b/cgame/fx_local.h @@ -10,6 +10,8 @@ localEntity_t *FX_AddLine(vec3_t start, vec3_t end, float stScale, float scale, float startalpha, float endalpha, float killTime, qhandle_t shader); localEntity_t *FX_AddLine2(vec3_t start, vec3_t end, float stScale, float width1, float dwidth1, float width2, float dwidth2, float startalpha, float endalpha, vec3_t startRGB, vec3_t endRGB, float killTime, qhandle_t shader); +localEntity_t *FX_AddLine3(vec3_t start, vec3_t end, float stScale, float scale, float dscale, + float startalpha, float endalpha, vec3_t startRGB, vec3_t endRGB, float killTime, qhandle_t shader); localEntity_t *FX_AddOrientedLine(vec3_t start, vec3_t end, vec3_t normal, float stScale, float scale, float dscale, float startalpha, float endalpha, float killTime, qhandle_t shader); localEntity_t *FX_AddTrail( vec3_t origin, vec3_t velocity, qboolean gravity, float length, float dlength, @@ -144,3 +146,8 @@ void FX_qFlash( centity_t* cent, vec3_t org, int timeIndex ); * sin table */ void fxRandCircumferencePos(vec3_t center, vec3_t normal, float radius, vec3_t out); + +/* + * fx-public ports + */ +float FX_DetailLevel( vec3_t origin, float near_clip, float far_clip ); diff --git a/game/g_local.h b/game/g_local.h index 992050c..efcc658 100644 --- a/game/g_local.h +++ b/game/g_local.h @@ -387,7 +387,7 @@ struct gentity_s { qboolean luaEntity; #endif vec4_t startRGBA; - vec4_t endRGBA; + vec4_t finalRGBA; }; /** \enum clientConnected_t @@ -720,6 +720,7 @@ qboolean G_SpawnString( const char *key, const char *defaultString, char **out ) qboolean G_SpawnFloat( const char *key, const char *defaultString, float *out ); qboolean G_SpawnInt( const char *key, const char *defaultString, int *out ); qboolean G_SpawnVector( const char *key, const char *defaultString, float *out ); +qboolean G_SpawnVector4( const char *key, const char *defaultString, float *out ); void G_SpawnEntitiesFromString( void ); char *G_NewString( const char *string ); diff --git a/game/g_spawn.c b/game/g_spawn.c index 79f8b7a..e15b015 100644 --- a/game/g_spawn.c +++ b/game/g_spawn.c @@ -64,7 +64,7 @@ field_t fields[] = { {"luaEntity", FOFS(luaEntity), F_INT}, #endif {"startRGBA", FOFS(startRGBA), F_VECTOR4}, - {"endRGBA", FOFS(endRGBA), F_VECTOR4}, + {"finalRGBA", FOFS(finalRGBA), F_VECTOR4}, {NULL} }; diff --git a/game/g_turrets.c b/game/g_turrets.c index f94d328..4d86165 100644 --- a/game/g_turrets.c +++ b/game/g_turrets.c @@ -6,8 +6,8 @@ //extern cvar_t *g_spskill; //client side shortcut hacks from cg_local.h -//extern void CG_FireLaser( vec3_t start, vec3_t end, vec3_t normal, vec4_t laserRGB, qboolean hit_ent ); -//extern void CG_AimLaser( vec3_t start, vec3_t end, vec3_t normal ); +extern void CG_FireLaser( vec3_t start, vec3_t end, vec3_t normal, vec4_t laserRGB, qboolean hit_ent ); +extern void CG_AimLaser( vec3_t start, vec3_t end, vec3_t normal ); #define ARM_ANGLE_RANGE 60 @@ -808,7 +808,7 @@ void SP_misc_turret (gentity_t *base) } -/*void laser_arm_fire (gentity_t *ent) +void laser_arm_fire (gentity_t *ent) { vec3_t start, end, fwd, rt, up; trace_t trace; @@ -919,7 +919,7 @@ void laser_arm_use (gentity_t *self, gentity_t *other, gentity_t *activator) G_Sound( self->lastEnemy->lastEnemy, G_SoundIndex( "sound/enemies/l_arm/move.wav" ) ); break; } -}*/ +} /*QUAKED misc_laser_arm (1 0 0) (-8 -8 -8) (8 8 8) @@ -941,12 +941,12 @@ What it does when used depends on it's "count" (can be set by a script) "startRGBA" - laser color, Red Green Blue Alpha, range 0 to 1 (default 1.0 0.85 0.15 0.75 = Yellow-Orange) */ -/*void laser_arm_start (gentity_t *base) +void laser_arm_start (gentity_t *base) { vec3_t armAngles; vec3_t headAngles; - base->e_ThinkFunc = thinkF_NULL; + base->think = 0; //We're the base, spawn the arm and head gentity_t *arm = G_Spawn(); gentity_t *head = G_Spawn(); @@ -991,7 +991,7 @@ What it does when used depends on it's "count" (can be set by a script) { base->speed *= FRAMETIME/1000.0f; } - base->e_UseFunc = useF_laser_arm_use; + base->use = laser_arm_use; base->nextthink = level.time + FRAMETIME; //Arm @@ -1021,7 +1021,7 @@ What it does when used depends on it's "count" (can be set by a script) VectorSet( head->r.maxs, 8, 8, 8 ); head->r.contents = CONTENTS_BODY; //FIXME: make an index into an external string table for localization - head->fullName = "Surgical Laser"; + head->message = "Surgical Laser"; trap_LinkEntity(head); //dmg @@ -1053,11 +1053,11 @@ What it does when used depends on it's "count" (can be set by a script) //Link them up base->lastEnemy = arm; arm->lastEnemy = head; - head->owner = arm; + head->parent = arm; arm->nextTrain = head->nextTrain = base; // The head should always think, since it will be either firing a damage laser or just a target laser - head->e_ThinkFunc = thinkF_laser_arm_fire; + head->think = laser_arm_fire; head->nextthink = level.time + FRAMETIME; head->booleanstate = qfalse; // Don't do damage until told to } @@ -1067,4 +1067,4 @@ void SP_laser_arm (gentity_t *base) base->think = laser_arm_start; base->nextthink = level.time + FRAMETIME; } -*/ + diff --git a/game/q_shared.h b/game/q_shared.h index b8578f1..998dcee 100644 --- a/game/q_shared.h +++ b/game/q_shared.h @@ -549,6 +549,7 @@ void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out ); void _VectorCopy( const vec3_t in, vec3_t out ); void _VectorScale( const vec3_t in, float scale, vec3_t out ); void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc ); +float Vector4to3(const vec4_t in, vec3_t out); // returns in[3] unsigned ColorBytes3 (float r, float g, float b); unsigned ColorBytes4 (float r, float g, float b, float a);