⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subs.htm

📁 Quake 的 各 种 文 档 格 式 说 明
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html><head><title>subs.qc</title></head><body bgcolor="#C0F0D0">
<base target=examine>
<pre>


<a href="qc-types.htm#void">void</a>() <b>SUB_Null</b><a name="SUB_Null">=</a> {};

<a href="qc-types.htm#void">void</a>() <b>SUB_Remove</b><a name="SUB_Remove">=</a> {<a href="qc-built.htm#remove">remove</a>(<a href="qc-glob.htm#self">self</a>);};


<i>/*
QuakeEd only writes a single float for angles (bad idea), so up and down are
just constant angles.
*/</i>

<a href="qc-types.htm#vector">vector</a>() <b>SetMovedir</b><a name="SetMovedir">=</a>
{
	<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_angles">angles</a> == '0 -1 0')
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movedir">movedir</a> = '0 0 1';
	<b>else</b> <b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_angles">angles</a> == '0 -2 0')
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movedir">movedir</a> = '0 0 -1';
	<b>else</b>
	{
		<a href="qc-built.htm#makevectors">makevectors</a> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_angles">angles</a>);
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movedir">movedir</a> = <a href="qc-built.htm#v_forward">v_forward</a>;
	}
	
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_angles">angles</a> = '0 0 0';
};

<i>/*
================
InitTrigger
================
*/</i>

<a href="qc-types.htm#void">void</a>() <b>InitTrigger</b><a name="InitTrigger">=</a>
{
<i>// trigger angles are used for one-way touches.  An angle of 0 is assumed</i>
<i>// to mean no restrictions, so use a yaw of 360 instead.</i>
	<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_angles">angles</a> != '0 0 0')
		<a href="subs.htm#SetMovedir">SetMovedir</a> ();
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_solid">solid</a> = <a href="qc-defs.htm#SOLID_TRIGGER">SOLID_TRIGGER</a>;
	<a href="qc-built.htm#setmodel">setmodel</a> (<a href="qc-glob.htm#self">self</a>, <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_model">model</a>);	<i>// set size and link into world</i>
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movetype">movetype</a> = <a href="qc-defs.htm#MOVETYPE_NONE">MOVETYPE_NONE</a>;
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_modelindex">modelindex</a> = 0;
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_model">model</a> = <b>""</b>;
};

<i>/*
=============
SUB_CalcMove

calculate self.velocity and self.nextthink to reach dest from
self.origin traveling at speed
===============
*/</i>

<a href="qc-types.htm#void">void</a>(<a href="qc-types.htm#entity">entity</a> ent, <a href="qc-types.htm#vector">vector</a> tdest, <a href="qc-types.htm#float">float</a> tspeed, <a href="qc-types.htm#void">void</a>() func) <b>SUB_CalcMoveEnt</b><a name="SUB_CalcMoveEnt">=</a>
{
<b>local</b> <a href="qc-types.htm#entity">entity</a>	stemp;
	stemp = <a href="qc-glob.htm#self">self</a>;
	<a href="qc-glob.htm#self">self</a> = ent;

	<a href="subs.htm#SUB_CalcMove">SUB_CalcMove</a> (tdest, tspeed, func);
	<a href="qc-glob.htm#self">self</a> = stemp;
};

<a href="qc-types.htm#void">void</a>(<a href="qc-types.htm#vector">vector</a> tdest, <a href="qc-types.htm#float">float</a> tspeed, <a href="qc-types.htm#void">void</a>() func) <b>SUB_CalcMove</b><a name="SUB_CalcMove">=</a>
{
<b>local</b> <a href="qc-types.htm#vector">vector</a>	vdestdelta;
<b>local</b> <a href="qc-types.htm#float">float</a>		len, traveltime;

	<b>if</b> (!tspeed)
		<a href="qc-built.htm#objerror">objerror</a>(<b>"No speed is defined!"</b>);

	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_think1">think1</a> = func;
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_finaldest">finaldest</a> = tdest;
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_think">think</a> = <a href="subs.htm#SUB_CalcMoveDone">SUB_CalcMoveDone</a>;

	<b>if</b> (tdest == <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_origin">origin</a>)
	{
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_velocity">velocity</a> = '0 0 0';
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_ltime">ltime</a> + 0.1;
		<b>return</b>;
	}
		
<i>// set destdelta to the vector needed to move</i>
	vdestdelta = tdest - <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_origin">origin</a>;
	
<i>// calculate length of vector</i>
	len = <a href="qc-built.htm#vlen">vlen</a> (vdestdelta);
	
<i>// divide by speed to get time to reach dest</i>
	traveltime = len / tspeed;

	<b>if</b> (traveltime &lt; 0.1)
	{
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_velocity">velocity</a> = '0 0 0';
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_ltime">ltime</a> + 0.1;
		<b>return</b>;
	}
	
<i>// set nextthink to trigger a think when dest is reached</i>
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_ltime">ltime</a> + traveltime;

<i>// scale the destdelta vector by the time spent traveling to get velocity</i>
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_velocity">velocity</a> = vdestdelta * (1/traveltime);	<i>// qcc won't take vec/float	</i>
};

<i>/*
============
After moving, set origin to exact final destination
============
*/</i>

<a href="qc-types.htm#void">void</a>() <b>SUB_CalcMoveDone</b><a name="SUB_CalcMoveDone">=</a>
{
	<a href="qc-built.htm#setorigin">setorigin</a>(<a href="qc-glob.htm#self">self</a>, <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_finaldest">finaldest</a>);
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_velocity">velocity</a> = '0 0 0';
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> = -1;
	<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_think1">think1</a>)
		<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_think1">think1</a>();
};


<i>/*
=============
SUB_CalcAngleMove

calculate self.avelocity and self.nextthink to reach destangle from
self.angles rotating 

The calling function should make sure self.think is valid
===============
*/</i>

<a href="qc-types.htm#void">void</a>(<a href="qc-types.htm#entity">entity</a> ent, <a href="qc-types.htm#vector">vector</a> destangle, <a href="qc-types.htm#float">float</a> tspeed, <a href="qc-types.htm#void">void</a>() func) <b>SUB_CalcAngleMoveEnt</b><a name="SUB_CalcAngleMoveEnt">=</a>
{
<b>local</b> <a href="qc-types.htm#entity">entity</a>		stemp;
	stemp = <a href="qc-glob.htm#self">self</a>;
	<a href="qc-glob.htm#self">self</a> = ent;
	<a href="subs.htm#SUB_CalcAngleMove">SUB_CalcAngleMove</a> (destangle, tspeed, func);
	<a href="qc-glob.htm#self">self</a> = stemp;
};

<a href="qc-types.htm#void">void</a>(<a href="qc-types.htm#vector">vector</a> destangle, <a href="qc-types.htm#float">float</a> tspeed, <a href="qc-types.htm#void">void</a>() func) <b>SUB_CalcAngleMove</b><a name="SUB_CalcAngleMove">=</a>
{
<b>local</b> <a href="qc-types.htm#vector">vector</a>	destdelta;
<b>local</b> <a href="qc-types.htm#float">float</a>		len, traveltime;

	<b>if</b> (!tspeed)
		<a href="qc-built.htm#objerror">objerror</a>(<b>"No speed is defined!"</b>);
		
<i>// set destdelta to the vector needed to move</i>
	destdelta = destangle - <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_angles">angles</a>;
	
<i>// calculate length of vector</i>
	len = <a href="qc-built.htm#vlen">vlen</a> (destdelta);
	
<i>// divide by speed to get time to reach dest</i>
	traveltime = len / tspeed;

<i>// set nextthink to trigger a think when dest is reached</i>
	<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_nextthink">nextthink</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_ltime">ltime</a> + traveltime;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -