Author Topic: Game Code That Removes idDebris  (Read 1362 times)

0 Members and 1 Guest are viewing this topic.

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Game Code That Removes idDebris
« on: June 17, 2017, 03:40:59 PM »
I'm looking through the game code for where entities that are considered idDebris are removed so that I can add in an exception. Would anyone know where this is?

Phrozo

  • Mr. Phrozo
  • Jr. Member
  • **
  • Posts: 89
  • Karma: +15/-1
  • :3
    • View Profile
    • Mod Page
Re: Game Code That Removes idDebris
« Reply #1 on: June 18, 2017, 12:55:34 PM »
I don't believe the game code looks for the class type info idDebris specifically when removing entities, only when spawning them. What are you trying to do exactly?

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Re: Game Code That Removes idDebris
« Reply #2 on: June 18, 2017, 01:25:55 PM »
I'm trying to disable the removal of barrelpiece, barrelpiece2, barreltop, and barreltop2 which are all idDebris that are created when an exploding barrel explodes, and then the "fuse" value in moveable.def for it decides how long until it's removed. Commenting out line 1012 in Moveable.cpp stops the burnaway effect on those 4 debris pieces, but they're still removed, and trying to work backwards by looking for where fuse is mentioned in the code has me stuck.

I do have Entity.cpp up in another tab which seems like the place where removal of entities might occur but fuse isn't mentioned in it at all.
« Last Edit: June 18, 2017, 01:27:28 PM by spamclark15 »

The Happy Friar

  • Happy Happy Joy Joy
  • Administrator
  • Hero Member
  • *****
  • Posts: 900
  • Karma: +42/-4
  • Semi-Newbie.
    • View Profile
    • EarthQuake
Re: Game Code That Removes idDebris
« Reply #3 on: June 18, 2017, 08:32:03 PM »
You would need to change the debris from idDebris to idMovable in the code.  The wile loop @ line 1013 in movables.cpp contains the declariation of idDebris.

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Re: Game Code That Removes idDebris
« Reply #4 on: June 18, 2017, 08:50:42 PM »
Code: [Select]
while ( kv ) {
const idDict *debris_args = gameLocal.FindEntityDefDict( kv->GetValue(), false );
if ( debris_args ) {
idEntity *ent;
idVec3 dir;
idDebris *debris;
//if ( first ) {
dir = physicsObj.GetAxis()[1];
// first = false;
//} else {
dir.x += gameLocal.random.CRandomFloat() * 4.0f;
dir.y += gameLocal.random.CRandomFloat() * 4.0f;
//dir.z = gameLocal.random.RandomFloat() * 8.0f;
//}
dir.Normalize();

gameLocal.SpawnEntityDef( *debris_args, &ent, false );
if ( !ent || !ent->IsType( idDebris::Type ) ) {
gameLocal.Error( "'projectile_debris' is not an idDebris" );
}

debris = static_cast<idDebris *>(ent);
debris->Create( this, physicsObj.GetOrigin(), dir.ToMat3() );
debris->Launch();
//                 debris->GetRenderEntity()->shaderParms[ SHADERPARM_TIME_OF_DEATH ] = ( gameLocal.time + 1500 ) * 0.001f;
debris->UpdateVisuals();

}
kv = spawnArgs.MatchPrefix( "def_debris", kv );
}

Is replacing all instances of idDebris in the loop enough?

Phrozo

  • Mr. Phrozo
  • Jr. Member
  • **
  • Posts: 89
  • Karma: +15/-1
  • :3
    • View Profile
    • Mod Page
Re: Game Code That Removes idDebris
« Reply #5 on: June 19, 2017, 12:04:59 AM »
In that code snippet yes, at least it's worth a try. You should also change the "spawnclass" value to "idMoveable" as well for all the debris in the .def file if you do.

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Re: Game Code That Removes idDebris
« Reply #6 on: June 19, 2017, 05:15:40 AM »
Changed loop to the following:

Code: [Select]
while ( kv ) {
const idDict *debris_args = gameLocal.FindEntityDefDict( kv->GetValue(), false );
if ( debris_args ) {
idEntity *ent;
idVec3 dir;
//RPS idDebris *debris;
idMoveable *debris;
//if ( first ) {
dir = physicsObj.GetAxis()[1];
// first = false;
//} else {
dir.x += gameLocal.random.CRandomFloat() * 4.0f;
dir.y += gameLocal.random.CRandomFloat() * 4.0f;
//dir.z = gameLocal.random.RandomFloat() * 8.0f;
//}
dir.Normalize();

gameLocal.SpawnEntityDef( *debris_args, &ent, false );
//RPS if ( !ent || !ent->IsType( idDebris::Type ) ) {
if ( !ent || !ent->IsType( idMoveable::Type ) ) {
gameLocal.Error( "'projectile_debris' is not an idDebris" );
}

//RPS debris = static_cast<idDebris *>(ent);
debris = static_cast<idMoveable *>(ent);
debris->Create( this, physicsObj.GetOrigin(), dir.ToMat3() );
debris->Launch();
//RPS debris->GetRenderEntity()->shaderParms[ SHADERPARM_TIME_OF_DEATH ] = ( gameLocal.time + 1500 ) * 0.001f;
debris->UpdateVisuals();

}
kv = spawnArgs.MatchPrefix( "def_debris", kv );
}

physicsObj.PutToRest();
CancelEvents( &EV_Explode );
CancelEvents( &EV_Activate );

f = spawnArgs.GetFloat( "respawn" );
if ( f > 0.0f ) {
PostEventSec( &EV_Respawn, f );
} else {
PostEventMS( &EV_Remove, 5000 );
}

if ( spawnArgs.GetBool( "triggerTargets" ) ) {
ActivateTargets( this );
}
}

It produces errors upon trying to build though:

Error    3   error C2039: 'Create' : is not a member of 'idMoveable'   1013   1   Game
Error    4   error C2039: 'Launch' : is not a member of 'idMoveable'   1014   1   Game

Phrozo

  • Mr. Phrozo
  • Jr. Member
  • **
  • Posts: 89
  • Karma: +15/-1
  • :3
    • View Profile
    • Mod Page
Re: Game Code That Removes idDebris
« Reply #7 on: June 19, 2017, 05:45:44 AM »
Ahh shoot. I shouldn't have assumed it would have been that easy. Apparently idMoveable doesn't have those methods defined. It is also missing members idDebris needs for it's effects. It's going to be a little bit more complicated than copying and pasting idDebris code into idMoveable. You'll have to declare and define these methods:

Code: [Select]
void Spawn( void );
Code: [Select]
void Create( idEntity *owner, const idVec3 &start, const idMat3 &axis );
Code: [Select]
void Launch( void );
Code: [Select]
void Fizzle( void );
You'll also have to add these data members from idDebris to idMovable:

Code: [Select]
idEntityPtr<idEntity> owner;
idPhysics_RigidBody physicsObj;
const idDeclParticle * smokeFly;
int smokeFlyTime;
const idSoundShader * sndBounce;

And you'll also have refactor some of idMovable's methods idDebris has as well, like Think() for instance.
Code: [Select]
/*
================
idDebris::Think
================
*/
void idDebris::Think( void ) {

// run physics
RunPhysics();
Present();

if ( smokeFly && smokeFlyTime ) {
if ( !gameLocal.smokeParticles->EmitSmoke( smokeFly, smokeFlyTime, gameLocal.random.CRandomFloat(), GetPhysics()->GetOrigin(), GetPhysics()->GetAxis() ) ) {
smokeFlyTime = 0;
}
}
}

versus

Code: [Select]
/*
================
idMoveable::Think
================
*/
void idMoveable::Think( void ) {
if ( thinkFlags & TH_THINK ) {
if ( !FollowInitialSplinePath() ) {
BecomeInactive( TH_THINK );
}
}
idEntity::Think();
}

It may be better to find out what causes debris to be removed so quickly then to refactor all of that. Perhaps set owner to NULL or to world object?

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Re: Game Code That Removes idDebris
« Reply #8 on: June 19, 2017, 08:05:59 AM »
Thanks for the help. I replaced the code for think, but where do the other parts go?

Phrozo

  • Mr. Phrozo
  • Jr. Member
  • **
  • Posts: 89
  • Karma: +15/-1
  • :3
    • View Profile
    • Mod Page
Re: Game Code That Removes idDebris
« Reply #9 on: June 20, 2017, 04:44:16 AM »
The new methods and data members need to be added to where idMoveable is declared in Movable.h. Put the method definitions in Moveable.cpp.
Note that copying idDebris code into idMoveable might inadvertently change the behavior of all idMoveables so this isn't advised unless you add code to remedy the differences.

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Re: Game Code That Removes idDebris
« Reply #10 on: June 20, 2017, 07:45:46 AM »
Error   582   error LNK2005: "public: virtual void __thiscall idDebris::Think(void)" (?Think@idDebris@@UAEXXZ) already defined in Moveable.obj Projectile.obj
Error   583   error LNK2001: unresolved external symbol "public: virtual void __thiscall idMoveable::Think(void)" (?Think@idMoveable@@UAEXXZ) Moveable.obj
Error   584   error LNK1120: 1 unresolved externals gamex86.dll



Phrozo

  • Mr. Phrozo
  • Jr. Member
  • **
  • Posts: 89
  • Karma: +15/-1
  • :3
    • View Profile
    • Mod Page
Re: Game Code That Removes idDebris
« Reply #11 on: June 20, 2017, 01:24:31 PM »
Make sure there aren't multiple definitions of idDebris::Think, especially if you aren't going to being using idDebris anymore. The second error means idMoveable::Think was declared but never defined. That shouldn't happen as it already is defined in source code. Check your code.

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Re: Game Code That Removes idDebris
« Reply #12 on: June 20, 2017, 02:32:30 PM »
Commented out copy in Projectile.cpp. The second error I'll show you the files for.
« Last Edit: June 20, 2017, 02:47:42 PM by spamclark15 »

Phrozo

  • Mr. Phrozo
  • Jr. Member
  • **
  • Posts: 89
  • Karma: +15/-1
  • :3
    • View Profile
    • Mod Page
Re: Game Code That Removes idDebris
« Reply #13 on: June 21, 2017, 03:12:24 AM »
at line 405 in Moveable.cpp, you defined Think for idDebris, not idMoveable. idDebris::Think is being defined twice here and in projectile.cpp

Change this:
Code: [Select]
void idDebris::Think( void ) { //RPS

// run physics
RunPhysics();
Present();

if ( smokeFly && smokeFlyTime ) {
if ( !gameLocal.smokeParticles->EmitSmoke( smokeFly, smokeFlyTime, gameLocal.random.CRandomFloat(), GetPhysics()->GetOrigin(), GetPhysics()->GetAxis() ) ) {
smokeFlyTime = 0;
}
}
}

to this
Code: [Select]
void idMoveable::Think( void ) { // HERE -Phrozo

// run physics
RunPhysics();
Present();

if ( smokeFly && smokeFlyTime ) {
if ( !gameLocal.smokeParticles->EmitSmoke( smokeFly, smokeFlyTime, gameLocal.random.CRandomFloat(), GetPhysics()->GetOrigin(), GetPhysics()->GetAxis() ) ) {
smokeFlyTime = 0;
}
}
}

spamclark15

  • id Enthusiast
  • Jr. Member
  • **
  • Posts: 97
  • Karma: +10/-3
  • A missile-launching skyscraper with goat legs.
    • View Profile
Re: Game Code That Removes idDebris
« Reply #14 on: June 21, 2017, 07:45:15 AM »
Sorry about that.  :-[ It builds now. When I destroy the barrel I get:

Code: [Select]
loaded collision model models/mapobjects/fuel_barrel/exp_barrel2c.lwo
script\weapon_fists.script : weapon_fists::Fire
script\weapon_fists.script : weapon_fists::Fire
<NO FUNCTION>
--------- Game Map Shutdown ----------
--------------------------------------
********************
ERROR: script\weapon_fists.script(64): Thread 'thread_7': 'projectile_debris'
is not an idDebris

********************

I changed debris_barrelpiece, debris_barrelpiece2, debris_barreltop, and debris_barreltop2 spawnclass to idMoveable in moveable.def.