djcev.com

//

Git Repos / fte_dogmode / qc / func / button.qc

Last update to this file was on 2024-04-12 at 18:56.

Show button.qc

//==============================================================================
// func_button -- button and multiple button
//==============================================================================

//======================================================================
// forward declarations
//======================================================================

// func_button
void() func_button_think_wait;
void() func_button_think_done;
void() func_button_think_return;
void() func_button_blocked;
void() func_button_fire;
void(vector dir) func_button_destroy;
void() func_button_use;
void() func_button_touch;
void(entity b) func_button_lock;
void(entity b, float dontresetstate) func_button_unlock;
void(entity e) func_button_init;
void() func_button;

//------------------------------------------------------------------------------

/*QUAKED func_button (0 .5 .8) ? X X X X X X X X NOT_ON_EASY NOT_ON_NORMAL NOT_ON_HARD_OR_NIGHTMARE NOT_IN_DEATHMATCH NOT_IN_COOP NOT_IN_SINGLEPLAYER X NOT_ON_HARD_ONLY NOT_ON_NIGHTMARE_ONLY
When a button is touched, it moves some distance in the direction of it's angle, triggers all of it's targets, waits some time, then returns to it's original position where it can be triggered again.

"angle" determines the opening direction
"target" all entities with a matching targetname will be used
"speed" override the default 40 speed
"wait" override the default 1 second wait (-1 = never return)
"lip" override the default 4 pixel lip remaining at end of move
"health" if set, the button must be killed instead of touched
"sounds"
0) steam metal
1) wooden clunk
2) metallic click
3) in-out
*/
//----------------------------------------------------------------------
// class func_button: base_func
// {
//--------------------------------------------------------------
void() func_button_think_wait =
{
self.state = FUNC_STATE_TOP;
self.think = func_button_think_return;
self.nextthink = self.ltime + self.wait;
activator = self.enemy;
// use alternate textures
self.frame = 1;

if (self.estate != STATE_ACTIVE)
return;

sub_usetargets ();
};

//--------------------------------------------------------------
void() func_button_think_done =
{
self.state = FUNC_STATE_BOTTOM;
};

//--------------------------------------------------------------
void() func_button_think_return =
{
if (self.estate != STATE_ACTIVE)
return;

self.state = FUNC_STATE_DOWN;
sub_calcmove (self, self.pos1, self.speed,
func_button_think_done);
// use normal textures
self.frame = 0;

if (self.health)
// can be shot again
self.takedamage = DAMAGE_YES;
};

//--------------------------------------------------------------
void() func_button_blocked =
{
// do nothing, just don't come all the way back out
};

//--------------------------------------------------------------
void() func_button_fire =
{
if (self.estate != STATE_ACTIVE)
return;

if (self.state == FUNC_STATE_UP || self.state == FUNC_STATE_TOP)
return;

sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);

self.state = FUNC_STATE_UP;
sub_calcmove (self, self.pos2, self.speed,
func_button_think_wait);
};

//--------------------------------------------------------------
void(vector dir) func_button_destroy =
{
if (self.estate != STATE_ACTIVE)
return;

self.enemy = damage_attacker;
self.health = self.max_health;
// wil be reset upon return
self.takedamage = DAMAGE_NO;

func_button_fire ();
};

//--------------------------------------------------------------
void() func_button_use =
{
self.enemy = activator;
func_button_fire ();
};

//--------------------------------------------------------------
void() func_button_touch =
{
if (self.health)
return;

if (other.classtype != CT_PLAYER)
return;

self.enemy = other;
func_button_fire ();
};

//--------------------------------------------------------------
// adapted from Copper, thanks Lunaran -- modified again by CEV
//--------------------------------------------------------------
void(entity b) func_button_lock =
{
if (b.estate == STATE_INACTIVE)
return;

if (b.state == FUNC_STATE_UP || b.state == FUNC_STATE_TOP)
b.prevstate = FUNC_STATE_TOP;
else
b.prevstate = FUNC_STATE_BOTTOM;

if (b.max_health)
b.takedamage = DAMAGE_NO;

b.state = FUNC_STATE_UP;
sub_calcmove (b, b.pos2, b.speed, func_button_think_wait);
b.estate = STATE_INACTIVE;
};

//--------------------------------------------------------------
void(entity b, float dontresetstate) func_button_unlock =
{
if (b.estate == STATE_ACTIVE)
return;

if (!dontresetstate || b.wait != -1 ||
b.prevstate == FUNC_STATE_BOTTOM)
{
if (b.max_health)
{
b.takedamage = DAMAGE_YES;
b.health = b.max_health;
}

// use normal textures
b.frame = 0;
b.state = FUNC_STATE_DOWN;
sub_calcmove (b, b.pos1, b.speed,
func_button_think_done);
}

b.estate = STATE_ACTIVE;
};

//--------------------------------------------------------------
void(entity e) func_button_init =
{
e.classname = "func_button";
e.classtype = CT_FUNC_BUTTON;
e.blocked = func_button_blocked;
e.use = func_button_use;

base_func_init (e);

if (e.sounds == 0)
{
precache_sound ("buttons/airbut1.wav");
e.noise = "buttons/airbut1.wav";
}

if (e.sounds == 1)
{
precache_sound ("buttons/switch21.wav");
e.noise = "buttons/switch21.wav";
}

if (e.sounds == 2)
{
precache_sound ("buttons/switch02.wav");
e.noise = "buttons/switch02.wav";
}

if (e.sounds == 3)
{
precache_sound ("buttons/switch04.wav");
e.noise = "buttons/switch04.wav";
}

sub_setmovedir (e);

e.movetype = MOVETYPE_PUSH;
e.solid = SOLID_BSP;
setmodel (e, e.model);

if (e.health)
{
e.max_health = e.health;
e.takedamage = DAMAGE_YES;
e.destroy = func_button_destroy;
}
else
{
e.touch = func_button_touch;
}

if (!e.speed)
e.speed = 40;
if (!e.wait)
e.wait = 1;
if (!e.lip)
e.lip = 4;

e.state = FUNC_STATE_BOTTOM;

e.pos1 = e.origin;
e.pos2 = e.pos1 + e.movedir *
(fabs(e.movedir * e.size) - e.lip);
};

//--------------------------------------------------------------
void() func_button =
{
// new spawnflags for all entities -- iw
if (SUB_Inhibit())
return;

func_button_init (self);
};
// };

Return to the top of this page or return to the overview of this repo.

Log button.qc

Date Commit Message Author + -
2024-04-12 Moveable gibs, heads, some bugfixes cev +2 -2
2024-03-24 Fix projectile and func_ blocked interaction cev +1 -1
2024-03-24 2nd pass refactor, rework QC class structure cev +120 -95
2024-02-18 Client/player, projectiles, entrypoints refactor cev +15 -15
2024-01-31 Class based monster refactor & start projectiles cev +22 -3
2024-01-09 Continue OO / Class-based refactor cev +172 -193
2023-11-27 Code reorg, minor movement changes, misc cev +235  

Return to the top of this page or return to the overview of this repo.