Prototypes for momentary_rot_button and momentary_door with some basic input logic to have them interact.

This commit is contained in:
Marco Cawthorne 2020-08-08 02:39:38 +02:00
parent e7f0c358eb
commit 1c8d21da62
4 changed files with 312 additions and 0 deletions

View file

@ -70,6 +70,9 @@ server/env_laser.cpp
server/item_food.cpp
server/speaker.cpp
server/multi_manager.cpp
server/momentarybase.cpp
server/momentary_rot_button.cpp
server/momentary_door.cpp
server/monster_furniture.cpp
server/monster_generic.cpp
server/monstermaker.cpp

View file

@ -0,0 +1,124 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*QUAKED func_wall (0 .5 .8) ?
"targetname" Name
Brush that lets light to pass through it.
On idTech 2 BSPs, it will change texture variants when triggered.
*/
class momentary_door:CBaseMomentary
{
void(void) momentary_door;
virtual void(void) customphysics;
virtual void(void) Respawn;
virtual void(void) SetMovementDirection;
};
void
momentary_door::customphysics(void)
{
entity e = find(world, CBaseEntity::m_strTargetName, m_strTarget);
CBaseMomentary bl = (CBaseMomentary)e;
if (m_eUser != world) {
base_player pl = (base_player)m_eUser;
/* we need to check if the user has changed every frame. */
if (!m_eUser.button5) {
/* clear user */
m_eUser = world;
if (e) {
bl.m_eUser = world;
}
} else {
if (e) {
bl.m_eUser = m_eUser;
}
m_flProgress += frametime;
if (m_flProgress >= 1.0f)
m_flProgress = 1.0f;
}
} else {
m_flProgress = Math_Lerp(m_flProgress, 0.0f, frametime * 0.5);
}
origin[0] = Math_Lerp(m_vecPos1[0], m_vecPos2[0], m_flProgress);
origin[1] = Math_Lerp(m_vecPos1[1], m_vecPos2[1], m_flProgress);
origin[2] = Math_Lerp(m_vecPos1[2], m_vecPos2[2], m_flProgress);
setorigin(this, origin);
/* support for think/nextthink */
if (think && nextthink > 0.0f) {
if (nextthink < time) {
nextthink = 0.0f;
think();
}
}
}
void
momentary_door::SetMovementDirection(void)
{
if (m_oldAngle == [0,-1,0]) {
m_vecMoveDir = [0,0,1];
} else if (m_oldAngle == [0,-2,0]) {
m_vecMoveDir = [0,0,-1];
} else {
makevectors(m_oldAngle);
m_vecMoveDir = v_forward;
}
}
void
momentary_door::Respawn(void)
{
SetMovetype(MOVETYPE_PUSH);
SetSolid(SOLID_BSP);
SetModel(m_oldModel);
SetOrigin(m_oldOrigin);
SetMovementDirection();
SetAngles([0,0,0]);
m_vecPos1 = m_oldOrigin;
m_vecPos2 = (m_vecPos1 + m_vecMoveDir * (fabs(m_vecMoveDir * size) - m_flDistance));
}
void
momentary_door::momentary_door(void)
{
for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
switch (argv(i)) {
case "lip":
m_flDistance = stof(argv(i+1));
break;
case "speed":
m_flSpeed = stof(argv(i+1));
break;
case "returnspeed":
m_flReturnspeed = stof(argv(i+1));
break;
default:
break;
}
}
CBaseTrigger::CBaseTrigger();
}

View file

@ -0,0 +1,142 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*QUAKED momentary_rot_button (0 .5 .8) ? MRBFL_DOORHACK MRBFL_NOTUSE x x MRBFL_AUTORETURN x MRBFL_XAXIS MRBFL_YAXIS
"targetname" Name
*/
enumflags
{
MRBFL_DOORHACK,
MRBFL_NOTUSE,
MRBFL_UNUSED4,
MRBFL_UNUSED8,
MRBFL_AUTORETURN,
MRBFL_UNUSED32,
MRBFL_XAXIS,
MRBFL_YAXIS
};
class momentary_rot_button:CBaseMomentary
{
void(void) momentary_rot_button;
virtual void(void) PlayerUse;
virtual void(void) customphysics;
virtual void(void) Respawn;
virtual void(void) SetMovementDirection;
};
void
momentary_rot_button::PlayerUse(void)
{
if (spawnflags & MRBFL_NOTUSE)
return;
m_eUser = eActivator;
}
void
momentary_rot_button::customphysics(void)
{
entity e = find(world, CBaseEntity::m_strTargetName, m_strTarget);
CBaseMomentary bl = (CBaseMomentary)e;
if (m_eUser != world) {
base_player pl = (base_player)m_eUser;
/* we need to check if the user has changed every frame. */
if (!m_eUser.button5) {
/* clear user */
m_eUser = world;
if (e) {
bl.m_eUser = world;
}
} else {
if (e) {
bl.m_eUser = m_eUser;
}
m_flProgress += frametime;
if (m_flProgress >= 1.0f)
m_flProgress = 1.0f;
}
} else {
m_flProgress = Math_Lerp(m_flProgress, 0.0f, frametime * 0.5);
}
angles[0] = Math_Lerp(m_vecPos1[0], m_vecPos2[0], m_flProgress);
angles[1] = Math_Lerp(m_vecPos1[1], m_vecPos2[1], m_flProgress);
angles[2] = Math_Lerp(m_vecPos1[2], m_vecPos2[2], m_flProgress);
/* support for think/nextthink */
if (think && nextthink > 0.0f) {
if (nextthink < time) {
nextthink = 0.0f;
think();
}
}
}
void
momentary_rot_button::SetMovementDirection(void)
{
if (spawnflags & MRBFL_XAXIS) {
m_vecMoveDir = [0,0,1];
} else if (spawnflags & MRBFL_YAXIS) {
m_vecMoveDir = [1,0,0];
} else {
m_vecMoveDir = [0,1,0];
}
}
void
momentary_rot_button::Respawn(void)
{
SetMovetype(MOVETYPE_PUSH);
SetSolid(SOLID_BSP);
SetModel(m_oldModel);
SetOrigin(m_oldOrigin);
SetMovementDirection();
SetAngles([0,0,0]);
m_vecPos1 = [0,0,0];
m_vecPos2 = m_oldAngle + m_vecMoveDir * m_flDistance;
}
void
momentary_rot_button::momentary_rot_button(void)
{
for (int i = 1; i < (tokenize(__fullspawndata) - 1); i += 2) {
switch (argv(i)) {
case "distance":
m_flDistance = stof(argv(i+1));
break;
case "speed":
m_flSpeed = stof(argv(i+1));
break;
case "returnspeed":
m_flReturnspeed = stof(argv(i+1));
break;
default:
break;
}
}
CBaseTrigger::CBaseTrigger();
}

View file

@ -0,0 +1,43 @@
/*
* Copyright (c) 2016-2020 Marco Hladik <marco@icculus.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*QUAKED func_wall (0 .5 .8) ?
"targetname" Name
Brush that lets light to pass through it.
On idTech 2 BSPs, it will change texture variants when triggered.
*/
class CBaseMomentary:CBaseTrigger
{
entity m_eUser;
float m_flProgress;
vector m_vecMoveDir;
vector m_vecPos1;
vector m_vecPos2;
/* map keys */
float m_flDistance;
float m_flProgress;
float m_flSpeed;
float m_flReturnspeed;
void(void) CBaseMomentary;
};
void CBaseMomentary::CBaseMomentary(void)
{
}