⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 specialfx.cpp

📁 this keik game source
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	)
	{
   byte sendflags;
   int  modelindex;
   sendflags = 0;

   // encode sendflags
   if (origin[0] || origin[1] || origin[2])
      sendflags |= TM_ORIGIN;
   if (angles[0] || angles[1] || angles[2])
      sendflags |= TM_ANGLES;
   if (anim)
      sendflags |= TM_ANIM;
   if (scale != 1.0f)
      sendflags |= TM_SCALE;
   if (flags != 0)
      sendflags |= TM_FLAGS;
   if (life != 0.1f)
      sendflags |= TM_LIFE;
   if (parent)
      sendflags |= TM_OWNER;
   if (alpha != 1.0f)
      sendflags |= TM_ALPHA;

   modelindex = gi.modelindex( modelname );
   //
   // send the stuff out
   //
	gi.WriteByte( svc_temp_entity );
	gi.WriteByte( TE_TEMPMODEL );
	gi.WriteByte( sendflags );
   if (sendflags & TM_ORIGIN)
	   gi.WritePosition( origin.vec3() );
   if (sendflags & TM_ANGLES)
	   gi.WritePosition( angles.vec3() );
   if (sendflags & TM_ANIM)
	   gi.WriteByte( anim );
   if (sendflags & TM_SCALE)
	   gi.WriteShort( scale*256 );
   if (sendflags & TM_ALPHA)
	   gi.WriteByte( alpha*255 );
   if (sendflags & TM_FLAGS)
	   gi.WriteByte( flags );
   if (sendflags & TM_OWNER)
	   gi.WriteShort( parent->entnum );
   if (sendflags & TM_LIFE)
	   gi.WriteShort( life*1000.0f );
   gi.WriteShort( modelindex );
   if (parent)
      {
	   gi.multicast( parent->worldorigin.vec3(), MULTICAST_ALL );
      }
   else
      {
	   gi.multicast( origin.vec3(), MULTICAST_ALL );
      }
	}

/*
================
TesselateModel
================
*/
void TesselateModel
	(
   Entity * ent,
   int min_size,
   int max_size,
   Vector dir,
   float power,
   float percentage,
   int thickness,
   Vector origin,
   int type,
   int lightstyle
   )
   {
   short sendflags;

   sendflags = 0;

   if (power > 255) power = 255;
   if (power < 0) power = 0;
   if (thickness > 255 ) thickness = 255;
   if (thickness < 0 ) thickness = 0;
   if (percentage < 0) percentage = 0;
   if (percentage > 1) percentage = 1;
   if (min_size > 255) min_size = 255;
   if (min_size < 0) min_size = 0;
   if (max_size > 255) max_size = 255;
   if (max_size < 0) max_size = 0;
   
   // encode sendflags
   if ( origin[0] || origin[1] || origin[2] )
      sendflags |= TESS_ORIGIN;
   if ( dir[0] || dir[1] || dir[2] )
      sendflags |= TESS_DIR;
   if ( ent && ent->edict )
      sendflags |= TESS_ENTNUM;
   if ( min_size != TESS_DEFAULT_MIN_SIZE )
      sendflags |= TESS_MINSIZE;
   if ( max_size != TESS_DEFAULT_MAX_SIZE )
      sendflags |= TESS_MAXSIZE;
   if ( power != TESS_DEFAULT_POWER )
      sendflags |= TESS_POWER;
   if ( percentage != TESS_DEFAULT_PERCENT )
      sendflags |= TESS_PERCENT;
   if ( thickness != min_size )
      sendflags |= TESS_THICK;
   if (lightstyle != TESS_DEFAULT_LIGHTSTYLE) 
      sendflags |= TESS_LIGHTSTYLE;
   if (type != TESS_DEFAULT_TYPE) 
      sendflags |= TESS_TYPE;
   
   //
   // send the stuff out
   //
	gi.WriteByte( svc_temp_entity );
	gi.WriteByte( TE_TESSELATE );
	gi.WriteShort( sendflags );
   if (sendflags & TESS_ORIGIN)
	   gi.WritePosition( origin.vec3() );
   if (sendflags & TESS_DIR)
	   gi.WriteDir( dir.vec3() );
   if (sendflags & TESS_ENTNUM)
	   gi.WriteShort( ent->entnum );
   if (sendflags & TESS_MINSIZE)
	   gi.WriteByte( min_size );
   if (sendflags & TESS_MAXSIZE)
	   gi.WriteByte( max_size );
   if (sendflags & TESS_POWER)
	   gi.WriteByte( power );
   if (sendflags & TESS_PERCENT)
	   gi.WriteByte( percentage * 255.0f );
   if (sendflags & TESS_THICK)
	   gi.WriteByte( thickness );
   if (sendflags & TESS_LIGHTSTYLE)
	   gi.WriteByte( lightstyle );
   if (sendflags & TESS_TYPE)
	   gi.WriteByte( type );

   if (ent)
      {
      if (gi.IsModel( ent->edict->s.modelindex ))
	      gi.multicast( ((ent->absmax+ent->absmin)*0.5).vec3(), MULTICAST_PVS );
      else
	      gi.multicast( ent->worldorigin.vec3(), MULTICAST_ALL );
      }
   else
      {
	   gi.multicast( origin.vec3(), MULTICAST_ALL );
      }
	}

CLASS_DECLARATION( Entity, Bubble, NULL )

Event EV_Bubble_Think( "think" );

ResponseDef Bubble::Responses[] =
	{
	   { &EV_Bubble_Think,	( Response )Bubble::Think },
		//{ &EV_Touch,			( Response )Bubble::Touch },
		{ NULL, NULL }
	};

EXPORT_FROM_DLL void Bubble::Touch
	(
	Event *ev
	)

	{
	edict->s.scale *= 0.8f;
	velocity[ 0 ] = G_CRandom( 30 );
	velocity[ 1 ] = G_CRandom( 30 );
	velocity[ 2 ] = -G_Random( 30 );
	}

EXPORT_FROM_DLL void Bubble::Think
	(
	Event *ev
	)

	{
	velocity[ 0 ] *= 0.8f;
	velocity[ 1 ] *= 0.8f;
	velocity[ 2 ] += 10;

	if ( ( edict->s.scale > 0.2f ) || ( edict->s.scale < 0.02f ) || !waterlevel )
		{
		PostEvent( EV_Remove, 0 );
		return;
		}

	PostEvent( EV_Bubble_Think, 0.1 );
	}

void Bubble::Setup
	(
	Vector pos
	)

	{
	setSolidType( SOLID_NOT );
	setMoveType( MOVETYPE_FLY );

	setModel( "sprites/bubble.spr" );
	setOrigin( pos );
	worldorigin.copyTo( edict->s.old_origin );
	mass = 0;

	watertype = gi.pointcontents( worldorigin.vec3() );

	PostEvent( EV_Bubble_Think, 0.1 );

	velocity[ 0 ] = G_CRandom( 30 );
	velocity[ 1 ] = G_CRandom( 30 );
	velocity[ 2 ] = -G_Random( 30 );

	edict->s.scale = 0.05f + G_CRandom( 0.04f );
	}

CLASS_DECLARATION( ScriptSlave, FuncBeam, "func_beam" );

Event EV_FuncBeam_Activate( "activate" );
Event EV_FuncBeam_Deactivate( "deactivate" );
Event EV_FuncBeam_Diameter( "diameter" );
Event EV_FuncBeam_Lightstyle( "beamstyle" );
Event EV_FuncBeam_Maxoffset( "maxoffset" );
Event EV_FuncBeam_Minoffset( "minoffset" );
Event EV_FuncBeam_Color( "color" );
Event EV_FuncBeam_SetTarget( "settarget" );

ResponseDef FuncBeam::Responses[] =
	{
      { &EV_Activate,               ( Response )FuncBeam::Activate },
      { &EV_FuncBeam_Activate,      ( Response )FuncBeam::Activate },
      { &EV_FuncBeam_Deactivate,    ( Response )FuncBeam::Deactivate },
      { &EV_FuncBeam_Diameter,      ( Response )FuncBeam::SetDiameter },
      { &EV_FuncBeam_Lightstyle,    ( Response )FuncBeam::SetLightstyle },
      { &EV_FuncBeam_Maxoffset,     ( Response )FuncBeam::SetMaxoffset },
      { &EV_FuncBeam_Minoffset,     ( Response )FuncBeam::SetMinoffset },
      { &EV_FuncBeam_Color,         ( Response )FuncBeam::SetColor },
      { &EV_FuncBeam_SetTarget,     ( Response )FuncBeam::SetTarget },
		{ NULL, NULL }
	};

void FuncBeam::SetColor
   (
   Event *ev
   )

   {
   Vector color = ev->GetVector( 1 );
   edict->s.color_r = color[0];
   edict->s.color_g = color[1];
   edict->s.color_b = color[2];
   }

void FuncBeam::SetMaxoffset
   (
   Event *ev
   )

   {
   edict->s.frame = ev->GetFloat( 1 );
   }

void FuncBeam::SetMinoffset
   (
   Event *ev
   )

   {
   edict->s.radius = ev->GetFloat( 1 );
   }

void FuncBeam::SetDiameter
   (
   Event *ev
   )

   {
   edict->s.frame = ev->GetFloat( 1 );
   }

void FuncBeam::SetLightstyle
   (
   Event *ev
   )

   {
   edict->s.skinnum = ev->GetInteger( 1 );
   }

void FuncBeam::Deactivate
   (
   Event *ev
   )

   {
   hideModel();

   // Cancel all of the events to activate
   CancelEventsOfType( EV_FuncBeam_Activate );
   CancelEventsOfType( EV_Activate );
   }

void FuncBeam::Shoot
   (
   Vector start,
   Vector end,
   int radius
   )

   {
   trace_t  trace;
   Vector   dir;
   Vector   b1=vec_zero, b2=vec_zero;
   
   dir = end - start;

   if ( edict->s.effects & EF_BEAMEFFECT )
      {
      b1 = Vector( -radius, -radius, -radius );
      b2 = Vector( radius, radius, radius );
      }
   
   trace = G_FullTrace( start, b1, b2, end, radius, this, MASK_SHOT, "FuncBeam::Activate" );

   if ( trace.ent->entity && trace.ent->entity->takedamage )
      {
      if ( trace.intersect.valid )
         {
   		// We hit a valid group so send in location based damage
         trace.ent->entity->Damage( this,
                                    this,
                                    damage,
                                    trace.endpos,
                                    dir,
                                    trace.plane.normal,
                                    0,
                                    0,
                                    MOD_BEAM,
                                    trace.intersect.parentgroup,
                                    -1,
                                    trace.intersect.damage_multiplier );
         }
      else
         {
         // We didn't hit any groups, so send in generic damage
   		trace.ent->entity->Damage( this,
                                    this,
                                    damage,
                                    trace.endpos,
                                    dir,
                                    trace.plane.normal,
                                    0,
                                    0,
                                    MOD_BEAM,
                                    -1,
                                    -1,
                                    1 );
         }
      }
   }

void FuncBeam::Activate
   (
   Event *ev
   )

   {
   Vector      forward,endpoint;
   trace_t     trace;

   showModel();   

   // An entity is targeted
   if ( end )
      {
      VectorCopy( end->origin, edict->s.old_origin );
      }
   else
      {
      worldangles.AngleVectors( &forward, NULL, NULL );
      endpoint = forward * 8192;     
      trace = G_Trace( origin, vec_zero, vec_zero, endpoint, this, MASK_SOLID, "FuncBeam::Activate" );
      VectorCopy( trace.endpos, edict->s.old_origin );
      }

   if ( damage )
      Shoot( origin, edict->s.old_origin, edict->s.frame );

   
   // If life is set, then post a deactivate message
   if ( life > 0 && !EventPending( EV_FuncBeam_Deactivate ) )
      {
      PostEvent( EV_FuncBeam_Deactivate, life );
      return;
      }

   // Shoot beam and cause damage
   PostEvent( EV_Activate, 0.1 );
   }

void FuncBeam::SetTarget
   (
   Event *ev
   )

   {
   const char  *target;
   int         num;

   // Set the end position if there is a target set.
   target = Target();
   if ( target && strlen( target ) )
      {
      if ( num = G_FindTarget( 0, target ) )
         {
         end = G_GetEntity( num );
         assert( end );
         VectorCopy( end->origin.vec3(), edict->s.old_origin );   
         }
      }
   }

/*****************************************************************************/
/*SINED func_beam (0 .8 .5) (-8 -8 -8) (8 8 8) START_ON ANIMATE FAST ROLL RANDSTART ELECTRIC RANDALPHA 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -