djcev.com

//

Git Repos / fte_dogmode / qc / func / counter.qc

Last update to this file was on 2024-03-24 at 02:40.

Show counter.qc

//==============================================================================
// func_counter, func_oncount -- Hipnotic Interactive, Jim Dose'
//==============================================================================

// Counter QuickC program
// By Jim Dose' 9/13/96
// Copyright (c)1996 Hipnotic Interactive, Inc.
// All rights reserved.
// Distributed (unsupported) on 3.12.97

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

const float COUNTER_TOGGLE = 1;
const float COUNTER_LOOP = 2;
const float COUNTER_STEP = 4;
const float COUNTER_RESET = 8;
const float COUNTER_RANDOM = 16;
const float COUNTER_FINISHCOUNT = 32;
const float COUNTER_START_ON = 64;

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

// func_counter
void() func_counter_think_starton;
void() func_counter_think;
void() func_counter_use_on;
void() func_counter_use_off;
float(entity e) func_counter_getcount;
void(entity e) func_counter_init;
void() func_counter;

// func_oncount
void() func_oncount_use;
void(entity e) func_oncount_init;
void() func_oncount;

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

/*QUAKED func_counter (0 0 0.5) (0 0 0) (32 32 32) TOGGLE LOOP STEP RESET RANDOM FINISHCOUNT START_ON 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
TOGGLE causes the counter to switch between an on and off state
each time the counter is triggered.

LOOP causes the counter to repeat infinitly. The count resets to zero
after reaching the value in "count".

STEP causes the counter to only increment when triggered. Effectively,
this turns the counter into a relay with counting abilities.

RESET causes the counter to reset to 0 when restarted.

RANDOM causes the counter to generate random values in the range 1 to "count"
at the specified interval.

FINISHCOUNT causes the counter to continue counting until it reaches "count"
before shutting down even after being set to an off state.

START_ON causes the counter to be on when the level starts.

"count" specifies how many times to repeat the event. If LOOP is set,
it specifies how high to count before reseting to zero. Default is 10.

"wait" the length of time between each trigger event. Default is 1 second.

"delay" how much time to wait before firing after being switched on.
*/
//----------------------------------------------------------------------
// class func_counter: base_func
// {
//--------------------------------------------------------------
void() func_counter_think_starton =
{
activator = world;
func_counter_use_off ();
};

//--------------------------------------------------------------
void() func_counter_think =
{
// was counter_think -- CEV
self.cnt = self.cnt + 1;
if (self.spawnflags & COUNTER_RANDOM)
{
self.state = random () * self.count;
self.state = floor (self.state) + 1;
}
else
{
self.state = self.cnt;
}

// fix func_counter and func_oncount handling of activator -- iw
// activator = other;
activator = self.enemy;
sub_usetargets ();
self.nextthink = time + self.wait;

if (self.spawnflags & COUNTER_STEP)
{
func_counter_use_on ();
}

if (self.cnt >= self.count)
{
self.cnt = 0;
if ((self.aflag) || !(self.spawnflags & COUNTER_LOOP))
if (self.spawnflags & COUNTER_TOGGLE)
func_counter_use_on ();
else
remove (self);
}
};

//--------------------------------------------------------------
void() func_counter_use_on =
{
if ((self.cnt != 0) && (self.spawnflags & COUNTER_FINISHCOUNT))
{
self.aflag = TRUE;
return;
}

self.use = func_counter_use_off;
self.think = sub_null;
self.aflag = FALSE;
};

//--------------------------------------------------------------
void() func_counter_use_off =
{
self.aflag = FALSE;
// make sure to toggle -- CEV
if (self.spawnflags & COUNTER_TOGGLE)
self.use = func_counter_use_on;
else
self.use = sub_null;

if (self.spawnflags & COUNTER_RESET)
{
self.cnt = 0;
self.state = 0;
}

// fix func_counter and func_oncount handling of activator -- iw
self.enemy = activator;
self.think = func_counter_think;

// fix "delay" making func_counter not work -- iw
// if (self.delay)
if (self.pausetime)
// fix "delay" making func_counter not work -- iw
// self.nextthink = time + self.delay;
self.nextthink = time + self.pausetime;
else
func_counter_think ();
};

//--------------------------------------------------------------
float(entity e) func_counter_getcount =
{
if (e.classtype == CT_FUNC_COUNTER)
return e.state;

return 0;
};

//--------------------------------------------------------------
void(entity e) func_counter_init =
{
e.classname = "counter";
e.classtype = CT_FUNC_COUNTER;

base_func_init (e);

if (!e.wait)
e.wait = 1;

e.count = floor (e.count);
if (e.count <= 0)
e.count = 10;

// fix "delay" making func_counter not work -- iw
e.pausetime = e.delay;
e.delay = 0;
e.cnt = 0;
e.state = 0;

e.use = func_counter_use_off;

if (e.spawnflags & COUNTER_START_ON)
{
e.think = func_counter_think_starton;
e.nextthink = time + 0.1;
}
else
{
e.think = sub_null;
}
};

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

func_counter_init (self);
};
// };

/*QUAKED func_oncount (0 0 0.5) (0 0 0) (16 16 16)
Must be used as the target for func_counter. When the counter
reaches the value set by count, func_oncount triggers its targets.

"count" specifies the value to trigger on. Default is 1.

"delay" how much time to wait before firing after being triggered.
*/
//----------------------------------------------------------------------
// class func_oncount: base_func
// {
//--------------------------------------------------------------
void() func_oncount_use =
{
if (func_counter_getcount(other) == self.count)
{
// fix func_counter and func_oncount handling
// of activator -- iw
// activator = other;
sub_usetargets ();
}
};

//--------------------------------------------------------------
void(entity e) func_oncount_init =
{
e.classname = "oncount";
e.classtype = CT_FUNC_ONCOUNT;

base_func_init (e);

e.count = floor (e.count);
if (e.count <= 0)
e.count = 1;

e.think = sub_null;
e.use = func_oncount_use;
};

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

func_oncount_init (self);
};
// };

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

Log counter.qc

Date Commit Message Author + -
2024-03-24 2nd pass refactor, rework QC class structure cev +133 -141
2024-02-18 Client/player, projectiles, entrypoints refactor cev +6 -2
2024-01-31 Class based monster refactor & start projectiles cev +32 -3
2024-01-09 Continue OO / Class-based refactor cev +166 -162
2023-11-27 Code reorg, minor movement changes, misc cev +234  

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