error C2275: 'CWorld' : illegal use of this type

Grab your favourite IDE and tinker with the innards of game engines

error C2275: 'CWorld' : illegal use of this type

Postby nanoxax on Mon Apr 01, 2013 9:42 pm

I'm trying to make a grenade that explodes when it touches the world. When I use this bit of code:

Code: Select all
//-----------------------------------------------------------------------------
// Purpose: On touch explode
//-----------------------------------------------------------------------------
void CGrenadeDynamite::BounceTouch( CBaseEntity *pOther )
{
   if ( pOther = CWorld )
   {
      Detonate();
   }
}


I get this:

Code: Select all
1>c:\osd\src\game\server\grenade_dynamite.cpp(159) : error C2275: 'CWorld' : illegal use of this type as an expression
1>        c:\osd\src\game\server\world.h(15) : see declaration of 'CWorld'



How can I fix this? Do I have to write something else or is the world not going to work in this case?

Also, an even better fix world be so that when it comes into contact with any entity it detonates. Maybe instead of

Code: Select all
   if ( pOther = CWorld )

it'd be something like
Code: Select all
   if ( pOther = CBaseEntity )


Or something like that. I know that it's not right but that's just to get the idea across. Thanks in advance.
nanoxax
Member
Member
 
Joined: Tue Oct 18, 2011 8:14 pm

Re: error C2275: 'CWorld' : illegal use of this type

Postby LordDz on Mon Apr 01, 2013 9:51 pm

Check how the Smg grenade explodes when it hits the ground and copy that ?
User avatar
LordDz
May Contain Skills
May Contain Skills
 
Joined: Mon Sep 01, 2008 12:28 pm
Location: Hammer Crash Logs

Re: error C2275: 'CWorld' : illegal use of this type

Postby nanoxax on Mon Apr 01, 2013 11:14 pm

I'm stumped. I have this so far:
Code: Select all
//-----------------------------------------------------------------------------
// Purpose: On touch explode
//-----------------------------------------------------------------------------
void CGrenadeDynamite::BounceTouch( CBaseEntity *pOther )
{
   Assert( pOther );
   if ( !pOther->IsSolid() )
   {
      Detonate();
   }
}


It looks like it should work but for whatever reason it doesn't. It's copied directly from the smg grenade code.

I just don't know how the game is supposed to know when to fire, I know that it needs to when it collides with a solid object. All I see is an action labled "BounceTouch" with a entity tied to it.
nanoxax
Member
Member
 
Joined: Tue Oct 18, 2011 8:14 pm

Re: error C2275: 'CWorld' : illegal use of this type

Postby nanoxax on Mon Apr 01, 2013 11:20 pm

Code: Select all
void CGrenadeAR2::GrenadeAR2Touch( CBaseEntity *pOther )
{
   Assert( pOther );
   if ( !pOther->IsSolid() )
      return;

   // If I'm live go ahead and blow up
   if (m_bIsLive)
   {
      Detonate();
   }
   else
   {
      // If I'm not live, only blow up if I'm hitting an chacter that
      // is not the owner of the weapon
      CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pOther );
      if (pBCC && GetThrower() != pBCC)
      {
         m_bIsLive = true;
         Detonate();
      }
   }
}


There is the smg coding, it says ar2 because I switched it over. The coding is all the same though and it works with ar2 just as it should.
nanoxax
Member
Member
 
Joined: Tue Oct 18, 2011 8:14 pm

Re: error C2275: 'CWorld' : illegal use of this type

Postby nanoxax on Tue Apr 02, 2013 6:27 am

Alright, I got it to work but only with brush entities, npcs, and physics props.

Code: Select all
//-----------------------------------------------------------------------------
// Purpose: On touch explode
//-----------------------------------------------------------------------------
void CGrenadeDynamite::BounceTouch( CBaseEntity *pOther )
{
   Assert( pOther );
   if ( !pOther->IsSolid() )
      return;

   // If I'm live go ahead and blow up
   if (m_bIsLive)
   {
      Detonate();
   }
   else
   {
      // If I'm not live, only blow up if I'm hitting an chacter that
      // is not the owner of the weapon
      CBaseCombatCharacter *pBCC = ToBaseCombatCharacter( pOther );
      if (pBCC && GetThrower() != pBCC)
      {
         m_bIsLive = true;
         Detonate();
      }
   }
}
void CGrenadeDynamite::Detonate(void)
{
   if (!m_bIsLive)
   {
      return;
   }
   m_bIsLive      = false;
   m_takedamage   = DAMAGE_NO;   

   CPASFilter filter( GetAbsOrigin() );

   te->Explosion( filter, 0.0,
      &GetAbsOrigin(),
      g_sModelIndexFireball,
      2.0,
      15,
      TE_EXPLFLAG_NONE,
      m_DmgRadius,
      m_flDamage );

   Vector vecForward = GetAbsVelocity();
   VectorNormalize(vecForward);
   trace_t      tr;
   UTIL_TraceLine ( GetAbsOrigin(), GetAbsOrigin() + 60*vecForward, MASK_SHOT,
      this, COLLISION_GROUP_NONE, &tr);


   if ((tr.m_pEnt != GetWorldEntity()) || (tr.hitbox != 0))
   {
      // non-world needs smaller decals
      if( tr.m_pEnt && !tr.m_pEnt->IsNPC() )
      {
         UTIL_DecalTrace( &tr, "SmallScorch" );
      }
   }
   else
   {
      UTIL_DecalTrace( &tr, "Scorch" );
   }

   UTIL_ScreenShake( GetAbsOrigin(), 25.0, 150.0, 1.0, 750, SHAKE_START );

   RadiusDamage ( CTakeDamageInfo( this, GetThrower(), m_flDamage, DMG_BLAST ), GetAbsOrigin(), m_DmgRadius, CLASS_NONE, NULL );

   UTIL_Remove( this );
}


That's what I have currently and I have changed the "IsSolid()" part to almost everything that exists in the engine and none work.

Are the world and static/dynamic props not considered entities in this case? This is all that I can think of.
nanoxax
Member
Member
 
Joined: Tue Oct 18, 2011 8:14 pm

Re: error C2275: 'CWorld' : illegal use of this type

Postby zombie@computer on Tue Apr 02, 2013 5:14 pm

Did you do this in the spawn:
Code: Select all
SetSolid( SOLID_BBOX );
   SetMoveType( MOVETYPE_FLYGRAVITY, MOVECOLLIDE_FLY_BOUNCE );

   // Hits everything but debris
   SetCollisionGroup( COLLISION_GROUP_PROJECTILE );

also, see the Think() function which detonates the grenade if speed is 0 or the grenade is resting on the ground.

On a related note:
Code: Select all
//-----------------------------------------------------------------------------
// Purpose: On touch explode
//-----------------------------------------------------------------------------
void CGrenadeDynamite::BounceTouch( CBaseEntity *pOther )
{
   if ( pOther = CWorld )
   {
      Detonate();
   }
}
if (pOther = CWorld) is wrong for three reasons:
1) = is assigning, == is comparison.
2) class CWorld cannot be compared to class CBaseEntity (you need to cast it)
3) if you want to check if something is a certain class, you need to utilise custom properties, ie GetClassname()
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Return to Programming

Who is online

Users browsing this forum: No registered users