djcev.com

//

Git Repos / fte_dogmode / qc / func / plat.qc

Last update to this file was on 2024-03-24 at 17:34.

Show plat.qc

//==============================================================================
// func_plat -- was plats.qc
//==============================================================================

//======================================================================
// constants
//======================================================================

const float PLAT_LOW_TRIGGER = 1;

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

// temp_plat_trigger
void() temp_plat_trigger_touch;
entity(entity own) spawn_temp_plat_trigger;
void(entity e) temp_plat_trigger_init;
strip void() temp_plat_trigger;

// func_plat
void() func_plat_hit_top;
void() func_plat_hit_bottom;
void() func_plat_go_down;
void() func_plat_go_up;
void() func_plat_blocked;
void() func_plat_use;
void(entity e) func_plat_init;
void() func_plat;

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

//----------------------------------------------------------------------
// class temp_plat_trigger: base_tempentity
// {
//--------------------------------------------------------------
void() temp_plat_trigger_touch =
{
// from Copper -- dumptruck_ds
if (sub_checkvalidtouch(other) == FALSE)
return;

if (self.owner.classtype != CT_FUNC_PLAT)
return;

if (self.owner.state == FUNC_STATE_BOTTOM)
sub_runvoidas (self.owner, func_plat_go_up);
else if (self.owner.state == FUNC_STATE_TOP)
// delay going down
self.owner.nextthink = self.owner.ltime + 1;
};

//--------------------------------------------------------------
entity(entity own) spawn_temp_plat_trigger =
{
local entity e = spawn ();
e.owner = own;
temp_plat_trigger_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) temp_plat_trigger_init =
{
e.classname = "temp_plat_trigger";
e.classtype = CT_TEMP_PLAT_TRIGGER;
base_tempentity_init (e);

e.movetype = MOVETYPE_NONE;
e.solid = SOLID_TRIGGER;
e.touch = temp_plat_trigger_touch;

if (!e.owner)
objerror ("temp_plat_trigger_init: no linked plat!\n");

if (e.owner.classtype != CT_FUNC_PLAT)
return;

local vector tmin = e.owner.mins + '25 25 0';
local vector tmax = e.owner.maxs - '25 25 -8';
tmin_z = tmax_z - (e.owner.pos1_z - e.owner.pos2_z + 8);
if (e.owner.spawnflags & PLAT_LOW_TRIGGER)
tmax_z = tmin_z + 8;

if (e.owner.size_x <= 50)
{
tmin_x = (e.owner.mins_x + e.owner.maxs_x) / 2;
tmax_x = tmin_x + 1;
}

if (e.owner.size_y <= 50)
{
tmin_y = (e.owner.mins_y + e.owner.maxs_y) / 2;
tmax_y = tmin_y + 1;
}

setsize (e, tmin, tmax);
};

//--------------------------------------------------------------
strip void() temp_plat_trigger =
{
temp_plat_trigger_init (self);
};
// };

/*QUAKED func_plat (0 .5 .8) ? PLAT_LOW_TRIGGER 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

speed default 150

Plats are always drawn in the extended position, so they will light correctly.

If the plat is the target of another trigger or button, it will start out disabled in the extended position until it is trigger, when it will lower and become a normal plat.

If the "height" key is set, that will determine the amount the plat moves, instead of being implicitly determined by the model's height.
Set "sounds" to one of the following:
1) base fast
2) chain slow
*/
//----------------------------------------------------------------------
// class func_plat: base_func
// {
//--------------------------------------------------------------
void() func_plat_hit_top =
{
sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
self.state = FUNC_STATE_TOP;
self.think = func_plat_go_down;
self.nextthink = self.ltime + 3;
};

//--------------------------------------------------------------
void() func_plat_hit_bottom =
{
sound (self, CHAN_VOICE, self.noise1, 1, ATTN_NORM);
self.state = FUNC_STATE_BOTTOM;
};

//--------------------------------------------------------------
void() func_plat_go_down =
{
sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
self.state = FUNC_STATE_DOWN;
sub_calcmove (self, self.pos2, self.speed,
func_plat_hit_bottom);
};

//--------------------------------------------------------------
void() func_plat_go_up =
{
sound (self, CHAN_VOICE, self.noise, 1, ATTN_NORM);
self.state = FUNC_STATE_UP;
sub_calcmove (self, self.pos1, self.speed, func_plat_hit_top);
};

//--------------------------------------------------------------
void() func_plat_blocked =
{
// handle projectiles -- CEV
if (other.classgroup & CG_PROJECTILE)
{
if (other.mins != '0 0 0' || other.maxs != '0 0 0')
setsize (other, '0 0 0', '0 0 0');

// continue on the same path
if (self.state == FUNC_STATE_UP)
func_plat_go_up ();
else if (self.state == FUNC_STATE_DOWN)
func_plat_go_down ();
return;
}

t_damage2 (other, self, self, 1);

// reverse direction
if (self.state == FUNC_STATE_UP)
func_plat_go_down ();
else if (self.state == FUNC_STATE_DOWN)
func_plat_go_up ();
else
objerror ("func_plat_blocked: bad self.state\n");
};

//--------------------------------------------------------------
void() func_plat_use =
{
self.use = sub_null;

if (self.targetname != "")
{
if (self.state != FUNC_STATE_UP)
objerror ("func_plat_use: not in up state\n");
func_plat_go_down ();
}
else
{
if (self.think)
// already activated
return;

func_plat_go_down ();
}
};

//--------------------------------------------------------------
void(entity e) func_plat_init =
{
e.classname = "plat";
e.classtype = CT_FUNC_PLAT;
base_func_init (e);

if (!e.t_length)
e.t_length = 80;
if (!e.t_width)
e.t_width = 10;

if (e.sounds == 0)
e.sounds = 2;

// FIX THIS TO LOAD A GENERIC PLAT SOUND
if (e.sounds == 1)
{
precache_sound ("plats/plat1.wav");
precache_sound ("plats/plat2.wav");
e.noise = "plats/plat1.wav";
e.noise1 = "plats/plat2.wav";
}

if (e.sounds == 2)
{
precache_sound ("plats/medplat1.wav");
precache_sound ("plats/medplat2.wav");
e.noise = "plats/medplat1.wav";
e.noise1 = "plats/medplat2.wav";
}

e.mangle = e.angles;
e.angles = '0 0 0';

e.solid = SOLID_BSP;
e.movetype = MOVETYPE_PUSH;
setorigin (e, e.origin);
setmodel (e, e.model);
setsize (e, e.mins , e.maxs);

e.blocked = func_plat_blocked;
e.use = func_plat_use;

if (!e.speed)
e.speed = 150;

// pos1 is the top position, pos2 is the bottom
e.pos1 = e.origin;
e.pos2 = e.origin;
if (e.height)
e.pos2_z = e.origin_z - e.height;
else
e.pos2_z = e.origin_z - e.size_z + 8;

dprint (sprintf("func_plat_init: pos1 %v, pos2 %v, "
"origin %v\n", e.pos1, e.pos2, e.origin));

// the "start moving" trigger
spawn_temp_plat_trigger (e);

if (e.targetname != "")
{
e.state = FUNC_STATE_UP;
}
else
{
setorigin (e, e.pos2);
e.state = FUNC_STATE_BOTTOM;
}
};

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

func_plat_init (self);
};
// };

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

Log plat.qc

Date Commit Message Author + -
2024-03-24 Fix projectile and func_ blocked interaction cev +15  
2024-03-24 2nd pass refactor, rework QC class structure cev +148 -193
2024-02-18 Client/player, projectiles, entrypoints refactor cev +3 -3
2024-01-31 Class based monster refactor & start projectiles cev +77 -13
2024-01-09 Continue OO / Class-based refactor cev +212 -186
2023-11-27 Code reorg, minor movement changes, misc cev +226  

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