add trigger_teleport, trigger_changelevel and a few helper methods

This commit is contained in:
Marco Cawthorne 2022-11-14 19:03:57 -08:00
parent 59d7be34d4
commit f4d3a47448
Signed by: eukara
GPG key ID: CE2032F0A2882A22
9 changed files with 134 additions and 14 deletions

10
src/entities/info_null.qc Normal file
View file

@ -0,0 +1,10 @@
class idNull:idEntity {
void idNull( void );
};
void idNull::idNull( void ) {
}
LINK_ENTITY_TO_CLASS(info_null, idNull)
LINK_ENTITY_TO_CLASS(info_teleport_destination, idNull)

View file

@ -14,9 +14,7 @@ idEntity idPlayerStart::MovePlayerToStart( idPlayer player ) {
idEntity point = g_idEngine.Find( world, ::classname, "idPlayerStart" );
if ( point ) {
player.SetOrigin( point.GetOrigin() );
player.SetAngles( point.GetAngles() );
player.ForceUpdateClientAngle();
player.Transport( point.GetOrigin(), point.GetAngles() );
return point;
} else {
g_idEngine.Error( "Cannot find idPlayerStart on level." );

View file

@ -1,5 +1,9 @@
#includelist
worldspawn.qc
info_player_start.qc
func_wall.qc
info_null.qc
info_player_start.qc
light.qc
trigger_changelevel.qc
trigger_teleport.qc
worldspawn.qc
#endlist

View file

@ -0,0 +1,27 @@
/* we need to register and track this entity field. */
.string map;
class idTriggerChangelevel:idEntity {
void idTriggerChangelevel( void );
nonvirtual string GetNextLevel( void );
nonvirtual void ChangelevelTouched( idEntity );
};
void idTriggerChangelevel::idTriggerChangelevel( void ) {
InitTrigger();
SetTouchCallback( ChangelevelTouched );
}
string idTriggerChangelevel::GetNextLevel( void )
{
return map;
}
void idTriggerChangelevel::ChangelevelTouched( idEntity toucher ) {
if ( toucher.IsPlayer() ) {
g_idEngine.ChangeLevel( GetNextLevel() );
}
}
LINK_ENTITY_TO_CLASS(trigger_changelevel, idTriggerChangelevel)

View file

@ -0,0 +1,22 @@
class idTriggerTeleport:idEntity {
void idTriggerTeleport( void );
nonvirtual void TeleporterTouched( idEntity );
};
void idTriggerTeleport::idTriggerTeleport( void ) {
InitTrigger();
SetTouchCallback(TeleporterTouched);
}
void idTriggerTeleport::TeleporterTouched( idEntity toucher ) {
if ( toucher.IsPlayer() ) {
idEntity destination = FindFirstTarget();
if ( destination ) {
toucher.Transport( destination.GetOrigin(), destination.GetAngles() );
}
}
}
LINK_ENTITY_TO_CLASS(trigger_teleport, idTriggerTeleport)

View file

@ -1,15 +1,15 @@
class worldspawn {
void worldspawn( void );
class idWorldspawn {
void idWorldspawn( void );
nonvirtual void InitLight( void );
};
void worldspawn::worldspawn( void ) {
void idWorldspawn::idWorldspawn( void ) {
g_idEngine.Precache_Model( "progs/player.mdl" );
InitLight();
}
void worldspawn::InitLight( void ) {
void idWorldspawn::InitLight( void ) {
g_idEngine.LightStyle( 0, "m" );
g_idEngine.LightStyle( 1, "mmnmmommommnonmmonqnmmo" );
g_idEngine.LightStyle( 2, "abcdefghijklmnopqrstuvwxyzyxwvutsrqponmlkjihgfedcba" );
@ -24,7 +24,4 @@ void worldspawn::InitLight( void ) {
g_idEngine.LightStyle( 11, "abcdefghijklmnopqrrqponmlkjihgfedcba" );
}
void worldspawn( void )
{
spawnfunc_worldspawn();
}
LINK_ENTITY_TO_CLASS(worldspawn, idWorldspawn)

View file

@ -65,4 +65,6 @@ class idEngine {
idEngine g_idEngine;
#define LINK_ENTITY_TO_CLASS(cname,classa) void cname(void) { spawnfunc_##classa(); }
#define LINK_ENTITY_TO_CLASS(cname,classa) void cname(void) { spawnfunc_##classa(); }
.void( idEntity ) TouchCallback;

View file

@ -211,6 +211,17 @@ void idEntity::SetNoiseValue4( string value ) {
noise3 = value;
}
void idEntity::SetTouchCallback( void( idEntity ) callback ) {
/* give this entity a touch, this is for the engine only */
touch = _TouchWrapper;
/* this is the touch function we'll be calling whenever the entity really gets touched */
TouchCallback = callback;
}
void idEntity::_TouchWrapper( void ) {
TouchCallback(other);
}
/* get functions */
float idEntity::GetModelindex( void ) {
@ -384,3 +395,41 @@ string idEntity::GetNoiseValue3( void ) {
string idEntity::GetNoiseValue4( void ) {
return noise3;
}
bool idEntity::IsPlayer( void ) {
return HasFlag(FL_CLIENT);
}
bool idEntity::IsMonster( void ) {
return HasFlag(FL_MONSTER);
}
bool idEntity::IsWorld( void ) {
if (this == world)
return TRUE;
else
return FALSE;
}
/* misc helper methods */
void idEntity::InitTrigger( void ) {
SetSolid(SOLID_TRIGGER);
SetModel(GetModel());
SetMovetype(MOVETYPE_NONE);
SetModelindex(0);
}
void idEntity::Transport( vector new_pos, vector new_ang ) {
float flSpeed = vlen(this.GetVelocity());
g_idEngine.MakeVectors(new_ang);
SetVelocity(v_forward * flSpeed);
SetOrigin(new_pos);
SetAngles(new_ang);
ForceUpdateClientAngle();
}
idEntity idEntity::FindFirstTarget( void ) {
return g_idEngine.Find(world, ::targetname, target);
}

View file

@ -102,6 +102,9 @@ class idEntity {
nonvirtual void SetNoiseValue3( string );
nonvirtual void SetNoiseValue4( string );
nonvirtual void SetTouchCallback( void( idEntity ) callback );
nonvirtual void _TouchWrapper( void );
/** Returns the model id of the entity. */
nonvirtual float GetModelindex( void );
/** Returns the movetype of the entity. */
@ -184,4 +187,12 @@ class idEntity {
nonvirtual string GetNoiseValue2( void );
nonvirtual string GetNoiseValue3( void );
nonvirtual string GetNoiseValue4( void );
nonvirtual bool IsPlayer( void );
nonvirtual bool IsMonster( void );
nonvirtual bool IsWorld( void );
nonvirtual void InitTrigger( void );
nonvirtual void Transport( vector, vector );
nonvirtual idEntity FindFirstTarget( void );
};