192 lines
3.8 KiB
C++
192 lines
3.8 KiB
C++
/* counter quickc program
|
|
by jim dose' 9/13/96
|
|
copyright (c)1996 hipnotic interactive, inc.
|
|
all rights reserved.
|
|
do not distribute.
|
|
*/
|
|
|
|
float counter_toggle = 1;
|
|
float counter_loop = 2;
|
|
float counter_step = 4;
|
|
float counter_reset = 8;
|
|
float counter_random = 16;
|
|
float counter_finishcount = 32;
|
|
float counter_start_on = 64;
|
|
|
|
void() counter_on_use;
|
|
void() counter_off_use;
|
|
|
|
void() counter_think =
|
|
{
|
|
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;
|
|
}
|
|
|
|
activator = other;
|
|
sub_usetargets();
|
|
self.nextthink = time + self.wait;
|
|
|
|
if ( self.spawnflags & counter_step )
|
|
{
|
|
counter_on_use();
|
|
}
|
|
|
|
if ( self.cnt >= self.count )
|
|
{
|
|
self.cnt = 0;
|
|
if ( ( self.aflag ) || !( self.spawnflags & counter_loop ) )
|
|
{
|
|
if (self.spawnflags & counter_toggle)
|
|
{
|
|
counter_on_use();
|
|
}
|
|
else
|
|
{
|
|
remove (self);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
void() counter_on_use =
|
|
{
|
|
if ( ( self.cnt != 0 ) && ( self.spawnflags & counter_finishcount ) )
|
|
{
|
|
self.aflag = true;
|
|
return;
|
|
}
|
|
|
|
self.use = counter_off_use;
|
|
self.think = sub_null;
|
|
self.aflag = false;
|
|
};
|
|
|
|
void() counter_off_use =
|
|
{
|
|
self.aflag = false;
|
|
if (self.spawnflags & counter_toggle)
|
|
{
|
|
self.use = counter_on_use;
|
|
}
|
|
else
|
|
{
|
|
self.use = sub_null;
|
|
}
|
|
|
|
if ( self.spawnflags & counter_reset )
|
|
{
|
|
self.cnt = 0;
|
|
self.state = 0;
|
|
}
|
|
self.think = counter_think;
|
|
if (self.delay)
|
|
{
|
|
self.nextthink = time + self.delay;
|
|
}
|
|
else
|
|
{
|
|
counter_think();
|
|
}
|
|
};
|
|
|
|
float( entity counter ) counter_getcount =
|
|
{
|
|
local float value;
|
|
|
|
if ( counter.classname == "counter" )
|
|
{
|
|
return counter.state;
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
/*quaked func_counter (0 0 0.5) (0 0 0) (32 32 32) toggle loop step reset random finishcount start_on
|
|
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.
|
|
*/
|
|
|
|
void() func_counter =
|
|
{
|
|
if ( !self.wait )
|
|
{
|
|
self.wait = 1;
|
|
}
|
|
|
|
self.count = floor( self.count );
|
|
if ( self.count <= 0 )
|
|
{
|
|
self.count = 10;
|
|
}
|
|
self.cnt = 0;
|
|
self.state = 0;
|
|
|
|
self.classname = "counter";
|
|
self.use = counter_off_use;
|
|
self.think = sub_null;
|
|
if ( self.spawnflags & counter_start_on )
|
|
{
|
|
self.think = counter_off_use;
|
|
self.nextthink = time + 0.1;
|
|
}
|
|
};
|
|
|
|
void() oncount_use =
|
|
{
|
|
if ( counter_getcount( other ) == self.count )
|
|
{
|
|
activator = other;
|
|
sub_usetargets();
|
|
}
|
|
};
|
|
|
|
/*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.
|
|
*/
|
|
|
|
void() func_oncount =
|
|
{
|
|
self.count = floor( self.count );
|
|
if ( self.count <= 0 )
|
|
{
|
|
self.count = 1;
|
|
}
|
|
|
|
self.classname = "oncount";
|
|
self.use = oncount_use;
|
|
self.think = sub_null;
|
|
};
|