GS-Entbase: Add Input/Output methods for func_conveyor, func_guntarget,

func_wall_toggle
This commit is contained in:
Marco Cawthorne 2020-10-31 14:32:23 +01:00
parent 69fa528822
commit 422741a295
7 changed files with 120 additions and 35 deletions

View File

@ -39,6 +39,7 @@ class func_conveyor:CBaseTrigger
virtual void(entity, int) Trigger;
virtual void(void) touch;
virtual void(void) SetMovementDirection;
virtual void(entity, string, string) Input;
};
void
@ -92,6 +93,21 @@ func_conveyor::Respawn(void)
SetAngles([0,0,0]);
}
void
func_conveyor::Input(entity eAct, string strInput, string strData)
{
switch (strInput) {
case "ToggleDirection":
Trigger(eAct, TRIG_TOGGLE);
break;
case "SetSpeed":
m_flSpeed = stof(strData);
break;
default:
CBaseTrigger::Input(eAct, strInput, strData);
}
}
void
func_conveyor::func_conveyor(void)
{

View File

@ -32,17 +32,20 @@ This entity was introduced in Half-Life (1998).
class func_guntarget:CBaseTrigger
{
float m_flSpeed;
string m_strFire;
string m_strOnDeath;
string m_strOnDeathLegacy;
void(void) func_guntarget;
virtual void(void) Respawn;
virtual void(void) NextPath;
virtual void(void) Move;
virtual void(void) Start;
virtual void(void) Stop;
virtual void(entity act, int) Trigger;
virtual void(void) Death;
virtual void(string, string) SpawnKey;
virtual void(entity, string, string) Input;
};
void
@ -102,19 +105,31 @@ func_guntarget::NextPath(void)
void
func_guntarget::Death(void)
{
entity a;
Stop();
if (!m_strFire) {
if (!m_strOnDeath && !m_strOnDeathLegacy) {
return;
}
for (a = world; (a = find(a, ::targetname, m_strFire));) {
CBaseTrigger trigger = (CBaseTrigger)a;
trigger.Trigger(g_dmg_eAttacker, TRIG_TOGGLE);
if (!m_strOnDeathLegacy) {
UseOutput(g_dmg_eAttacker, m_strOnDeath);
} else {
entity a;
for (a = world; (a = find(a, ::targetname, m_strOnDeathLegacy));) {
CBaseTrigger trigger = (CBaseTrigger)a;
trigger.Trigger(g_dmg_eAttacker, TRIG_TOGGLE);
}
}
}
void
func_guntarget::Start(void)
{
takedamage = DAMAGE_YES;
NextPath();
m_iValue = 0;
}
void
func_guntarget::Stop(void)
{
@ -122,22 +137,27 @@ func_guntarget::Stop(void)
velocity = [0,0,0];
nextthink = 0;
think = __NULL__;
m_iValue = 1;
}
/* TODO: Handle state? */
void
func_guntarget::Trigger(entity act, int state)
{
flags = (1 << FL_FROZEN) | flags;
if (flags & FL_FROZEN) {
takedamage = DAMAGE_NO;
Stop();
m_iValue = 1;
} else {
takedamage = DAMAGE_YES;
NextPath();
switch (state) {
case TRIG_OFF:
m_iValue = 0;
break;
case TRIG_ON:
m_iValue = 1;
break;
default:
m_iValue = 1 - m_iValue;
}
if (m_iValue) {
Start();
} else {
Stop();
}
}
@ -159,6 +179,24 @@ func_guntarget::Respawn(void)
}
}
void
func_guntarget::Input(entity eAct, string strInput, string strData)
{
switch (strInput) {
case "Start":
Trigger(eAct, TRIG_ON);
break;
case "Stop":
Trigger(eAct, TRIG_OFF);
break;
case "Toggle":
Trigger(eAct, TRIG_TOGGLE);
break;
default:
CBaseTrigger::Input(eAct, strInput, strData);
}
}
void
func_guntarget::SpawnKey(string strKey, string strValue)
{
@ -170,7 +208,11 @@ func_guntarget::SpawnKey(string strKey, string strValue)
m_flSpeed = stof(strValue);
break;
case "message":
m_strFire = strValue;
m_strOnDeathLegacy = strValue;
break;
case "OnDeath":
strValue = strreplace(",", ",_", strValue);
m_strOnDeath = strcat(m_strOnDeath, ",_", strValue);
break;
default:
CBaseTrigger::SpawnKey(strKey, strValue);

View File

@ -38,6 +38,7 @@ class func_wall_toggle:CBaseTrigger
void(void) func_wall_toggle;
virtual void(void) Respawn;
virtual void(entity, int) Trigger;
virtual void(entity, string, string) Input;
};
void
@ -78,6 +79,18 @@ func_wall_toggle::Respawn(void)
}
}
void
func_wall_toggle::Input(entity eAct, string strInput, string strData)
{
switch (strInput) {
case "Toggle":
Trigger(eAct, TRIG_TOGGLE);
break;
default:
CBaseTrigger::Input(eAct, strInput, strData);
}
}
void
func_wall_toggle::func_wall_toggle(void)
{

View File

@ -40,7 +40,7 @@ item_longjump::touch(void)
if (other.classname != "player") {
return;
}
player pl = (player)other;
if (pl.g_items & ITEM_LONGJUMP) {
return;

View File

@ -26,6 +26,7 @@
#include "math.h"
#include "sound.h"
#include "pmove.h"
#include "memory.h"
/* Those are constant for HL BSP and CANNOT be changed.
* Blame Valve for purchasing a Quake II license but not
@ -64,21 +65,6 @@ const vector VEC_PLAYER_CVIEWPOS = [0,0,12];
.vector basevelocity;
.float gflags;
void*
memrealloc(__variant *oldptr, int elementsize, int oldelements, int newelements)
{
void *n = memalloc(elementsize * newelements);
memcpy(n, oldptr, elementsize * min(oldelements, newelements));
memfree(oldptr);
return n;
}
__wrap __variant*
memalloc(int size)
{
return prior(size);
}
void
Empty(void)
{

View File

@ -14,8 +14,6 @@
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#define MATH_PI 3.1415926
float
Math_LerpAngle(float fStart, float fEnd, float fAmount)
{

30
src/shared/memory.h Normal file
View File

@ -0,0 +1,30 @@
/*
* 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.
*/
void*
memrealloc(__variant *oldptr, int elementsize, int oldelements, int newelements)
{
void *n = memalloc(elementsize * newelements);
memcpy(n, oldptr, elementsize * min(oldelements, newelements));
memfree(oldptr);
return n;
}
__wrap __variant*
memalloc(int size)
{
return prior(size);
}