📄 ai.htm
字号:
<html><head><title>ai.qc</title></head><body bgcolor="#C0F0D0">
<base target=examine>
<pre>
<a href="qc-types.htm#void">void</a>() <a href="ai.htm#movetarget_f">movetarget_f</a>;
<a href="qc-types.htm#void">void</a>() <a href="ai.htm#t_movetarget">t_movetarget</a>;
<a href="qc-types.htm#void">void</a>() <a href="knight.htm#knight_walk1">knight_walk1</a>;
<a href="qc-types.htm#void">void</a>() <a href="knight.htm#knight_bow6">knight_bow6</a>;
<a href="qc-types.htm#void">void</a>() <a href="knight.htm#knight_bow1">knight_bow1</a>;
<a href="qc-types.htm#void">void</a>(<a href="qc-types.htm#entity">entity</a> etemp, <a href="qc-types.htm#entity">entity</a> stemp, <a href="qc-types.htm#entity">entity</a> stemp, <a href="qc-types.htm#float">float</a> dmg) <a href="combat.htm#T_Damage">T_Damage</a>;
<i>/*
.enemy
Will be world if not currently angry at anyone.
.movetarget
The next path spot to walk toward. If .enemy, ignore .movetarget.
When an enemy is killed, the monster will try to return to it's path.
.huntt_ime
Set to time + something when the player is in sight, but movement straight for
him is blocked. This causes the monster to use wall following code for
movement direction instead of sighting on the player.
.ideal_yaw
A yaw angle of the intended direction, which will be turned towards at up
to 45 deg / state. If the enemy is in view and hunt_time is not active,
this will be the exact line towards the enemy.
.pausetime
A monster will leave it's stand state and head towards it's .movetarget when
time > .pausetime.
walkmove(angle, speed) primitive is all or nothing
*/</i>
<i>//</i>
<i>// globals</i>
<i>//</i>
<a href="qc-types.htm#float">float</a> <b><a name="current_yaw">current_yaw</a></b>;
<i>//</i>
<i>// when a monster becomes angry at a player, that monster will be used</i>
<i>// as the sight target the next frame so that monsters near that one</i>
<i>// will wake up even if they wouldn't have noticed the player</i>
<i>//</i>
<a href="qc-types.htm#entity">entity</a> <b><a name="sight_entity">sight_entity</a></b>;
<a href="qc-types.htm#float">float</a> <b><a name="sight_entity_time">sight_entity_time</a></b>;
<a href="qc-types.htm#float">float</a>(<a href="qc-types.htm#float">float</a> v) <b>anglemod</b><a name="anglemod">=</a>
{
<b>while</b> (v >= 360)
v = v - 360;
<b>while</b> (v < 0)
v = v + 360;
return v;
};
<i>/*
==============================================================================
MOVETARGET CODE
The angle of the movetarget effects standing and bowing direction, but has no effect on movement, which allways heads to the next target.
targetname
must be present. The name of this movetarget.
target
the next spot to move to. If not present, stop here for good.
pausetime
The number of seconds to spend standing or bowing for path_stand or path_bow
==============================================================================
*/</i>
<a href="qc-types.htm#void">void</a>() <b>movetarget_f</b><a name="movetarget_f">=</a>
{
<b>if</b> (!<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_targetname">targetname</a>)
<a href="qc-built.htm#objerror">objerror</a> (<b>"monster_movetarget: no targetname"</b>);
<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-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_touch">touch</a> = <a href="ai.htm#t_movetarget">t_movetarget</a>;
<a href="qc-built.htm#setsize">setsize</a> (<a href="qc-glob.htm#self">self</a>, '-8 -8 -8', '8 8 8');
};
<i>/*QUAKED path_corner (0.5 0.3 0) (-8 -8 -8) (8 8 8)
Monsters will continue walking towards the next target corner.
*/</i>
<a href="qc-types.htm#void">void</a>() <b>path_corner</b><a name="path_corner">=</a>
{
<a href="ai.htm#movetarget_f">movetarget_f</a> ();
};
<i>/*
=============
t_movetarget
Something has bumped into a movetarget. If it is a monster
moving towards it, change the next destination and continue.
==============
*/</i>
<a href="qc-types.htm#void">void</a>() <b>t_movetarget</b><a name="t_movetarget">=</a>
{
<b>local</b> <a href="qc-types.htm#entity">entity</a> temp;
<b>if</b> (<a href="qc-glob.htm#other">other</a>.<a href="qc-enty.htm#dot_movetarget">movetarget</a> != <a href="qc-glob.htm#self">self</a>)
<b>return</b>;
<b>if</b> (<a href="qc-glob.htm#other">other</a>.<a href="qc-enty.htm#dot_enemy">enemy</a>)
<b>return</b>; <i>// fighting, not following a path</i>
temp = <a href="qc-glob.htm#self">self</a>;
<a href="qc-glob.htm#self">self</a> = <a href="qc-glob.htm#other">other</a>;
<a href="qc-glob.htm#other">other</a> = temp;
<b>if</b> (<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_classname">classname</a> == <b>"monster_ogre"</b>)
<a href="qc-built.htm#sound">sound</a> (<a href="qc-glob.htm#self">self</a>, <a href="qc-defs.htm#CHAN_VOICE">CHAN_VOICE</a>, <b>"ogre/ogdrag.wav"</b>, 1, <a href="qc-defs.htm#ATTN_IDLE">ATTN_IDLE</a>);<i>// play chainsaw drag sound</i>
<i>//dprint ("t_movetarget\n");</i>
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_goalentity">goalentity</a> = <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movetarget">movetarget</a> = <a href="qc-built.htm#find">find</a> (<a href="qc-glob.htm#world">world</a>, targetname, <a href="qc-glob.htm#other">other</a>.<a href="qc-enty.htm#dot_target">target</a>);
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_ideal_yaw">ideal_yaw</a> = <a href="qc-built.htm#vectoyaw">vectoyaw</a>(<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_goalentity">goalentity</a>.<a href="qc-enty.htm#dot_origin">origin</a> - <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_origin">origin</a>);
<b>if</b> (!<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_movetarget">movetarget</a>)
{
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_pausetime">pausetime</a> = <a href="qc-glob.htm#time">time</a> + 999999;
<a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_th_stand">th_stand</a> ();
<b>return</b>;
}
};
<i>//============================================================================</i>
<i>/*
=============
range
returns the range catagorization of an entity reletive to self
0 melee range, will become hostile even if back is turned
1 visibility and infront, or visibility and show hostile
2 infront and show hostile
3 only triggered by damage
=============
*/</i>
<a href="qc-types.htm#float">float</a>(<a href="qc-types.htm#entity">entity</a> targ) <b>range</b><a name="range">=</a>
{
<b>local</b> <a href="qc-types.htm#vector">vector</a> spot1, spot2;
<b>local</b> <a href="qc-types.htm#float">float</a> r;
spot1 = <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_view_ofs">view_ofs</a>;
spot2 = targ.<a href="qc-enty.htm#dot_origin">origin</a> + targ.<a href="qc-enty.htm#dot_view_ofs">view_ofs</a>;
r = <a href="qc-built.htm#vlen">vlen</a> (spot1 - spot2);
<b>if</b> (r < 120)
return RANGE_MELEE;
<b>if</b> (r < 500)
return RANGE_NEAR;
<b>if</b> (r < 1000)
return RANGE_MID;
return RANGE_FAR;
};
<i>/*
=============
visible
returns 1 if the entity is visible to self, even if not infront ()
=============
*/</i>
<a href="qc-types.htm#float">float</a> (<a href="qc-types.htm#entity">entity</a> targ) <b>visible</b><a name="visible">=</a>
{
<b>local</b> <a href="qc-types.htm#vector">vector</a> spot1, spot2;
spot1 = <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_view_ofs">view_ofs</a>;
spot2 = targ.<a href="qc-enty.htm#dot_origin">origin</a> + targ.<a href="qc-enty.htm#dot_view_ofs">view_ofs</a>;
<a href="qc-built.htm#traceline">traceline</a> (spot1, spot2, <a href="defs.htm#TRUE">TRUE</a>, <a href="qc-glob.htm#self">self</a>); <i>// see through other monsters</i>
<b>if</b> (<a href="qc-built.htm#trace_inopen">trace_inopen</a> && <a href="qc-built.htm#trace_inwater">trace_inwater</a>)
return FALSE; <i>// sight line crossed contents</i>
<b>if</b> (<a href="qc-built.htm#trace_fraction">trace_fraction</a> == 1)
return TRUE;
return FALSE;
};
<i>/*
=============
infront
returns 1 if the entity is in front (in sight) of self
=============
*/</i>
<a href="qc-types.htm#float">float</a>(<a href="qc-types.htm#entity">entity</a> targ) <b>infront</b><a name="infront">=</a>
{
<b>local</b> <a href="qc-types.htm#vector">vector</a> vec;
<b>local</b> <a href="qc-types.htm#float">float</a> dot;
<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>);
vec = <a href="qc-built.htm#normalize">normalize</a> (targ.<a href="qc-enty.htm#dot_origin">origin</a> - <a href="qc-glob.htm#self">self</a>.<a href="qc-enty.htm#dot_origin">origin</a>);
dot = vec * <a href="qc-built.htm#v_forward">v_forward</a>;
<b>if</b> ( dot > 0.3)
{
return TRUE;
}
return FALSE;
};
<i>//============================================================================</i>
<i>/*
===========
ChangeYaw
Turns towards self.ideal_yaw at self.yaw_speed
Sets the global variable current_yaw
Called every 0.1 sec by monsters
============
*/</i>
<i>/*
void() ChangeYaw =
{
local float ideal, move;
//current_yaw = self.ideal_yaw;
// mod down the current angle
current_yaw = anglemod( self.angles_y );
ideal = self.ideal_yaw;
if (current_yaw == ideal)
return;
move = ideal - current_yaw;
if (ideal > current_yaw)
{
if (move > 180)
move = move - 360;
}
else
{
if (move < -180)
move = move + 360;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -