home *** CD-ROM | disk | FTP | other *** search
/ Quake 'em / QUAKEEM.BIN / quake / docs / qcman10 / qcman10.txt
Encoding:
Text File  |  1996-08-14  |  79.3 KB  |  2,191 lines

  1. QuakeC Manual 1.0
  2. Copyright(C) 1996 by Ferrara Francesco (frank@aerre.it)
  3. ________________________________________________________________________________
  4.               
  5.         Table of contents
  6.         
  7. 1.      Introduction
  8.         1.1     What is QuakeC
  9.         1.2     Contributions
  10. 2.      QuakeC Language   
  11.         2.1     Comments
  12.         2.2     Names
  13.         2.3     New types
  14.         2.4     Definition of variables
  15.         2.5     Definitions of constants
  16.         2.6     Definitions of functions
  17.         2.7     Function declaration
  18.         2.8     Definition of a frame function
  19.         2.9     Conditional construct
  20.         2.10    Loop construct
  21.         2.11    Function calls
  22.         2.12    Logical operations
  23.         2.13    Comparisons
  24.         2.14    Operations on floats or integer
  25.         2.15    Bitwise operations
  26. 3.      Builtin functions
  27.         3.1     Basic math functions
  28.         3.2     Basic vector maths
  29.         3.3     Sound emission
  30.         3.4     Entity management
  31.         3.5     Move Entities
  32.         3.6     Fights and Shots
  33.         3.7     Collision checking
  34.         3.8     Server related functions
  35.         3.9     Print messages
  36.         3.10    Console 
  37.         3.11    Debugging
  38.         3.12    Precaching files
  39. 4.      Defines
  40.         4.1     Values: temporary entities
  41.         4.2     Values: Sound Channel of entities
  42.         4.3     Values: Sound Attenuation
  43.         4.4     Values: Contents of level areas
  44.         4.5     Values: Entity light effects
  45.         4.6     Values: Existing Items
  46.         4.7     Values: Behavior of solid objects
  47.         4.8     Values: Type of movements
  48.         4.9     Values: Entity can solid take damage
  49.         4.10    Values: Entity dead flag
  50.         4.11    Values: Spawnflags
  51. 5.      Entities
  52. 6.      Model pragma
  53. 7.      Network protocol
  54. 8.      Network Builtin functions
  55. 9.      Tips & tricks
  56. 10.     Basic Types
  57. 11.     Compilation of QuakeC
  58. 12.     Execution of QuakeC
  59. 13.     Examples
  60.         13.1    Looping between all monster
  61.         13.2    Creating a new entities
  62.         13.3    Setting point of view
  63.         13.4    Teleporting
  64.         13.5    Throwing your Eyes
  65.         13.6    Radar
  66.  
  67.  
  68.  
  69. 1. Introduction
  70. ________________________________________________________________________________
  71.  
  72. 1.1 What is QuakeC?
  73.  
  74.         QuakeC is a language similar to C. 
  75.         QuakeC can be compiled with qcc (Quake C compiler) to produce progs.dat a file that quake can load at startup. In that file Quake search the engines for various things in the Quake World.
  76.         Monsters, player, buttons, weapons are the target of QuakeC, you cannot modify levels or graphics that you can modify with a external editor.
  77.         Major part of this document are copyright by Olivier Montanuy . All the informations contained in this document are related to Quake-C, a language developed by and for idsoftware, so all those informations are copyright (c) 1996, id software. 
  78.         To compile and use all this info you must have qcc.tar.gz take it from idsoftware. You can edit and than compile with qccdos (the compiler) all of the qc files. You can rewrote all AI of the monster or create new entities.
  79.         I have only converted, corrected and added some stuff.
  80.  
  81. 1.2 Contributions
  82.  
  83.         Olivier Montanuy he is the real compiler of this document, I have rearranged it to a TXT version. Thanks Olivier.
  84.         
  85.         
  86. 2. QuakeC Language
  87. ________________________________________________________________________________
  88.  
  89.         Basic constructs of Quake-C
  90.  
  91. 2.1 Comments
  92.  
  93.  
  94.     // followed by comments, until the next line. 
  95.     /* enclose a block comments */ 
  96.  
  97. Those comments are the same as in C++ (and many C languages). 
  98.  
  99. 2.2 Names
  100.  
  101. Names of variable, fields, or functions have a maximum of 64 characters, must begin with A-Z,a-z, or _, and can continue with those characters or 0-9.
  102.  
  103. 2.3 New types
  104.  
  105. You cannot define new types from the existing ones. In particular, you cannot define new structure, new objects, and you cannot affect a new name to a type (as does typedef in C).
  106.  
  107. These restrictions make Quake-C compare unfavourably even to Basic, and sure it's about time the id software guys hired someone that already wrote a compiler.
  108.  
  109. You can add only fields to the most important type in QuakeC entity.
  110.  
  111. 2.4 Definition of variables
  112.  
  113.     type variable1, variable2;
  114.     eg: 
  115.     float   a,b;
  116.  
  117. where type is one of the pre-defined simple types.
  118. You can also affect default values to variables, for instance: 
  119.  
  120.     type variable1 = value;
  121.     eg:
  122.     float a = 2;
  123.  
  124. Scoping of variables: There are two levels of scoping. By default all variables are global: they can be accessed by any functions, and they are shared by all the functions (and all the clients of a given network server, of course). 
  125.  
  126. But inside the functions, using the keyword local just before the declaration of a variable, you can make this variable visible only the function itself (i.e. it will be allocated on the stack). 
  127.  
  128. Note that parameters of a functions are treated like local variables, they are only visible to the function, but they can be modified. 
  129.  
  130. 2.5 Definitions of constants
  131.  
  132. Any global variable that is initialized by setting a value to it is actually assumed to be a constant.
  133.  
  134. Since a constant is in fact represented by immediate values, you should NEVER attempt to modify a constant by giving it another value. Otherwise the program might not function correctly. 
  135.  
  136. The constants are not saved to game files. Only regular variables are. 
  137.  
  138. 2.6 Definitions of functions
  139.  
  140. The general structure of a function definition is: 
  141.  
  142.     type (type param1, typeparam2, ... ) function =
  143.     {
  144.        ... code ...
  145.     };
  146.  
  147. Don't forget the ; after the brackets. 
  148.  
  149. Here are some examples: 
  150.  
  151.     void()      think = {...};
  152.     entity()    FindTarget = {...};
  153.     void(vector destination, float speed, void() callback)      SUB_CalcMove = {...};
  154.  
  155. 2.7 Function declaration
  156.  
  157. If you want to use a function before defining it, you must declare it, otherwise the Quake-C compiler will not be able to use it.
  158.  
  159. The general structure of a function declaration is: 
  160.  
  161.     type (type param1, typeparam2, ... ) function;
  162.  
  163. 2.8 Definition of a frame function
  164.  
  165. Frame functions (also called States) are special functions made for convenience. They are meant to facilitate the definition of animation frames, by making them more readable.
  166.  
  167. Here is an example: 
  168.  
  169.     void() framename = [$framenum, nextthink] { ...code...};
  170.  
  171. It is strictly equivalent to: 
  172.  
  173.     void() framename =
  174.     {
  175.        self.frame= $framenum;  // the model frame to displayed
  176.        self.nextthink = time + 0.1;   // next frame happens in 1/10 of second
  177.        self.think = nextthink; // the function to call at the next frame
  178.        ...code...
  179.     };
  180.  
  181.  
  182.  
  183. Controlling the flow of execution in Quake-C
  184.  
  185. 2.9 Conditional construct
  186.  
  187.     if( expression )
  188.     {
  189.       statements
  190.     }
  191.     else
  192.     {
  193.       statements
  194.     }
  195.  
  196. 2.10 Loop construct
  197.  
  198.     while( expression )
  199.     {
  200.       statements
  201.     }
  202.  
  203. or 
  204.  
  205.     do
  206.     { 
  207.       statements
  208.     }while( expression )
  209.  
  210. 2.11 Function calls
  211.  
  212. Call a function: 
  213.  
  214.     function_name ( parameter1, parameter2,... )
  215.  
  216. The cannot be more than 8 parameters. 
  217.  
  218. Return a value: 
  219.  
  220.     return( expression )
  221.  
  222. 2.12 Logical operations
  223.  
  224.      !   // logical not
  225.      &&  // logical and
  226.      ||  // logical or
  227.  
  228. Take care that in if() conditional expressions containing two or more logical clauses, all the clauses will be evaluated before the condition test (like in Basic, and unlike C). 
  229.  
  230. That means that if one part of your condition is not always valid or defined, you had better decompose your if() into two successive if(). It should also make it faster. 
  231.  
  232. 2.13 Comparisons
  233.  
  234.      <=    <      >=     >  
  235.      ==  // equal, beware at the double = like in C.
  236.      !=  // not equal, like in C.
  237.  
  238. 2.14 Operations on floats or integer
  239.  
  240.      *  /  -  +
  241.  
  242. Use parenthesis to remove ambiguities.
  243.  
  244. 2.15 Bitwise operations 
  245.  
  246.     &   // bitwise and
  247.     |   // bitwise or
  248.  
  249. These operators treat floats like integers, so they are usually meant to be used with values made of bit masks.
  250.  
  251.  
  252.  
  253. 3. Builtin functions
  254. ________________________________________________________________________________
  255.  
  256.  
  257.         These are the built-in functions of Quake C. Since they are hard-coded in C, they cannot be redefined, but they are very fast. 
  258.  
  259. 3.1 Basic math functions
  260.  
  261. Function: anglemod
  262.  
  263.         float anglemod (float angle)
  264.         returns angle in degree, module 360. 
  265.  
  266. Function: rint
  267.  
  268.         float rint(float val)
  269.         Returns val, rounded up to the closest integer value. 
  270.  
  271. Function: floor
  272.  
  273.         float floor(float val)
  274.         Returns val, rounded up to the integer below (like the equivalent function in C). 
  275.  
  276. Function: ceil
  277.  
  278.         float ceil(float val)
  279.         Returns val, rounded up to the integer above (like the equivalent function in C). 
  280.  
  281. Function: fabs
  282.  
  283.         float fabs(float val)
  284.         Returns absolute value of val (like the equivalent function in C). 
  285.  
  286. Function: random
  287.         
  288.         float random()
  289.         Returns a random floating point number between 0.0 and 1.0.
  290.  
  291. Function: ftos
  292.  
  293.         string ftos(float value)
  294.         Float to string: converts value to string. 
  295.  
  296. 3.2 Basic vector maths
  297.  
  298. Function: normalize
  299.  
  300.         vector normalize(vector v)
  301.         returns a vector of length 1
  302.         Gives the vector colinear to v, but of length 1. This can be useful for calculation of distance along an axis. 
  303.  
  304. Function: vlen
  305.  
  306.         float vlen(vector v)
  307.         Returns the length of vector v (never < 0). 
  308.  
  309. Function: vectoyaw
  310.  
  311.         float vectoyaw(vector v)
  312.         returns and angle in degree
  313.         Vector to yaw: calculates the yaw angle (bearing) corresponding to a given 3D direction v. 
  314.  
  315. Function: vectoangles
  316.  
  317.         vector vectoangles(vector v)
  318.         returns vector 'pitch  yaw  0 '
  319.         Vector to angles: calculates the pitch angle (aiming) and yaw angle (bearing) corresponding to a given 3D direction v. 
  320.  
  321. Function: vtos
  322.  
  323.         string vtos(vector v)
  324.         Vector to String: print a vector, as a string. 
  325.  
  326. Function: makevectors
  327.  
  328.         void makevectors(vector angles)
  329.         angle = 'pitch yaw 0' 
  330.         Calculate the vectors pointing forward, right and up, according to the provided angles.
  331.         Returns result in the global variables: 
  332.         vector  v_forward;  // points forward
  333.         vector  v_up;       // points up
  334.         vector  v_right;    // points toward the right
  335.  
  336. 3.3 Sound emission
  337.  
  338. Function: sound
  339.  
  340.         void sound (entity source, float channel, string sample, float volume, float attenuation)
  341.           source = entity emiting the sound (ex: self)
  342.           channel = channel to use for sound 
  343.           sample = name of the sample WAV file (ex: "ogre/ogdrag.wav")
  344.           volume = 0.0 for low volume, 1.0 for maximum volume
  345.           attenuation= attenuation of sound 
  346.         The entity emits a sound, on one of it's 8 channels. 
  347.  
  348. Function: ambientsound
  349.  
  350.         void ambientsound(vector position, string sample, float volume, float attenuation)
  351.           position = position, in 3D space, inside the level
  352.           sample = name of the sample WAV file (ex: "ogre/ogdrag.wav")
  353.           volume = 0.0 for low volume, 1.0 for maximum volume
  354.           attenuation= attenuation of sound 
  355.         An ambient sound is emited, from the given position. 
  356.  
  357.  
  358. 3.4 Entity management
  359.  
  360. Function: spawn
  361.  
  362.         entity spawn ()
  363.         returns an empty entity.
  364.         Create a new entity, totally empty. You can manually set every field, or just set the origin and call one of the existing entity setup functions. 
  365.  
  366. Function: remove
  367.  
  368.         void remove (entity e)
  369.         Removes entity e from the world (R.I.P.). 
  370.  
  371. Function: makestatic
  372.  
  373.         void makestatic (entity e)
  374.         Make an entity static to the world, by sending a broadcast message to the network. The entity is then removed from the list of dynamic entities in the world, and it cannot be deleted (until the level ends). 
  375.  
  376. Function: nextent
  377.  
  378.         entity nextent(entity e)
  379.         Returns entity that is just after e in the entity list. 
  380. Useful to browse the list of entities, because it skips the undefined ones. 
  381.  
  382. Function: find
  383.  
  384.         entity find (entity start, .string field, string match)
  385.           start = begining of list to search (world, for the begining of list)
  386.           field = entity field that must be examined (ex: targetname)
  387.           match = value that must be matched (ex: other.target)
  388.         returns the entity found, or world if no entity was found.
  389.         Searches the server entity list beginning at start, looking for an entity that has entity.field = match.
  390.  
  391.         Example: find the first player entity 
  392.  
  393.          e = find( world, classname, "player");
  394.  
  395.         Take care that field is a name of an entity field, without dot, and without quotes. 
  396.  
  397. Function: findradius
  398.  
  399.         entity findradius (vector origin, float radius)
  400.           origin = origin of sphere
  401.           radius = radius of sphere
  402.         Returns a chain of entities that have their origins within a spherical area. The entity returned is e, and the next in the chain is e.chain, until e==FALSE. Typical usage: find and harm the victims of an explosion. 
  403.  
  404.           e = findradius( origin, radius)
  405.           while(e)
  406.           {
  407.             T_Damage(e, ... ) // Let God sort his ones!
  408.             e = e.chain
  409.           }
  410.  
  411. Function: setmodel
  412.  
  413.         void setmodel (entity e, string model)
  414.           e = entity whose model is to be set
  415.           model = name of the model (ex: "progs/soldier.mdl")
  416.  
  417.         Changes the model associated to an entity. This model should also be declared by precache_model. Please set e.movetype and e.solid first. 
  418.  
  419. Function: lightstyle
  420.  
  421.         void lightstyle(float style, string value)
  422.           style = index of the light style, from 0 to 63.
  423.           value = (ex: "abcdefghijklmlkjihgfedcb")
  424.  
  425.         Modifies a given light style. The light style is used to create cyclic lighting effects, like torches or teleporter lighting. There are 64 light tyles, from 0 to 63. If style is not strictly comprised in these values, the game may crash. Styles 32-62 are assigned by the light program for switchable lights. Value is a set of characters, whose ascii value indicates a light level, from "a" (0) to "z" (30). 
  426.  
  427.  
  428. 3.5 Move Entities
  429.  
  430. Function: ChangeYaw
  431.  
  432.         void ChangeYaw()
  433.         Change the horizontal orientation of self. Turns towards self.ideal_yaw at self.yaw_speed, and sets the global variable current_yaw. 
  434. Called every 0.1 sec by monsters 
  435.  
  436. Function: walkmove
  437.  
  438.         float walkmove(float yaw, float dist)
  439.         returns TRUE or FALSE 
  440.         Moves self in the given direction. 
  441. Returns FALSE if could not move (used to detect blocked monsters). 
  442.  
  443. Function: droptofloor
  444.  
  445.         float droptofloor()
  446.         returns TRUE or FALSE 
  447.         Drops self to the floor, if the floor is less than -256 coordinates below. Returns TRUE if landed on floor. Mainly used to spawn items or walking monsters on the floor. 
  448.  
  449. Function: setorigin
  450.  
  451.         void setorigin (entity e, vector position)
  452.           e = entity to be moved
  453.           position = new position for the entity
  454.         Move an entity to a given location. That function is to be used when spawning an entity or when teleporting it. This is the only valid way to move an object without using the physics of the world (setting velocity and waiting). DO NOT change directly e.origin, otherwise internal links would be screwed, and entity clipping would be messed up. 
  455.  
  456. Function: setsize
  457.  
  458.         void setsize (entity e, vector min, vector max)
  459.           e = entity whose bounding box is to be set  
  460.           min = minimum, for bounding box (ex: VEC_HULL2_MIN)
  461.           max = maximum, for bounding box (ex: VEC_HULL2_MAX)
  462.         Set the size of the entity bounding box, relative to the entity origin. The size box is rotated by the current angle. 
  463.  
  464. Function: movetogoal
  465.  
  466.         void movetogoal (float step)
  467.  
  468.         Move self toward it's goal. 
  469.         Used for monsters. 
  470.  
  471. 3.6 Fights and Shots
  472.  
  473. Function: aim
  474.  
  475.         vector aim(entity e, float missilespeed)
  476.         Returns a vector along which the entity e can shoot. 
  477. Usually, e is a player, and the vector returned is calculated by auto-aiming to the closest enemy entity. 
  478.  
  479. Function: particle
  480.  
  481.         void particle(vector origin, vector dir, float color, float count)
  482.             origin = initial position
  483.             dir = initial direction
  484.             color = color index (73,75, 
  485.             count = time to live, in seconds
  486.         Create a particle effect (small dot that flies away). 
  487.         color = 0   for chunk
  488.         color = 75  for yellow
  489.         color = 73  for blood red
  490.         color = 225 for entity damage
  491.  
  492. Function: checkclient
  493.  
  494.         entity checkclient()
  495.         Returns client (or object that has a client enemy) that would be a valid target. If there are more than one valid options, they are cycled each frame. 
  496. If (self.origin + self.viewofs) is not in the PVS of the target, 0 (false) is returned. 
  497.  
  498.  
  499. 3.7 Collision checking
  500.  
  501. Function: traceline
  502.  
  503.         traceline (vector v1, vector v2, float nomonsters, entity forent)
  504.           v1= start of line
  505.           v2= end of line
  506.           nomonster= if TRUE, then see through other monsters, else FALSE.
  507.           forent= ignore this entity, it's owner, and it's owned entities.
  508.             if forent = world, then ignore no entity.
  509.         Trace a line of sight, possibly ignoring monsters, and possibly ignoring the entity forent (usually, forent = self). This function is used very often, tracing and shot targeting. Traces are blocked by bounding boxes and exact bsp entities. Returns the results in the global variables: 
  510.         float trace_allsolid;
  511.           // never used
  512.         float trace_startsolid;
  513.           // never used
  514.         float trace_fraction;
  515.           // fraction (percent) of the line that was traced, before
  516.           // an obstacle was hit. Equal to 1 if no obstacle were found.
  517.         vector trace_endpos; 
  518.           // point where line ended or met an obstacle.
  519.         vector trace_plane_normal;
  520.           // direction vector of trace (?)
  521.         float  trace_plane_dist;  
  522.           // distance to impact along direction vector (?)
  523.         entity trace_ent;      
  524.           // entity hit by the line
  525.         float  trace_inopen;
  526.           // boolean, true if line went through non-water area.
  527.         float  trace_inwater;
  528.           // boolean, true if line went through water area.
  529.  
  530. Function: checkpos
  531.  
  532.         CURRENTLY DISABLED. DO NOT USE. 
  533.         scalar checkpos (entity e, vector position)
  534.         Returns true if the given entity can move to the given position from it's current position by walking or rolling. 
  535.  
  536. Function: checkbottom
  537.  
  538.         float checkbottom(entity e)
  539.           e = entity that is to be checked
  540.         return TRUE or FALSE
  541.         Returns TRUE if on the ground. Used only for jumping monster, that need to jump randomly not to get hung up (or whatever it actually means). 
  542.  
  543. Function: pointcontents
  544.  
  545.         float pointcontents(vector pos) 
  546.  
  547.         Returns the contents of the area situated at position pos. 
  548.         Used to know if an area is in water, in slime or in lava. 
  549.         Makes use of the BSP tree, and is supposed to be very fast. 
  550.  
  551.  
  552. 3.8 Server related functions
  553.  
  554. Function: changelevel
  555.  
  556.         void changelevel (string mapname)
  557.         Warp to the game map named mapname. Actually executes the console command "changelevel" + mapname, so if you want to alias it... 
  558.  
  559. Function: setspawnparms
  560.  
  561.         void setspawnparms (entity client)
  562.         Restore the original spawn parameters of a client entity. 
  563. Doesn't work if client is not a player. 
  564.  
  565. Function: stuffcmd
  566.  
  567.         stuffcmd (entity client, string text)
  568.           client = player that is to receive the command
  569.           text = text of the command, ended by \n (newline).
  570.         Send a command to a given player, as if it had been typed on the player's console. Don't forget the \n (newline) at the end, otherwise your command will not be executed, and will stand still on the console window.
  571.  
  572.         Examples: 
  573.         
  574.            stuffcmd(self, "bf\n"); // create a flash of light on the         screen
  575.            stuffcmd(self, "name Buddy\n"); // name the player Buddy
  576.         Mostly used to send the command bf, that creates a flash of light on the client's screen.
  577.  
  578. 3.9 Print messages
  579.  
  580. Function: bprint
  581.  
  582.         void bprint (string text)
  583.           text = text of the message
  584.         Broadcast a message to all players on the current server. 
  585.  
  586. Function: centerprint
  587.  
  588.         void centerprint( entity client, string text)
  589.           client = player that is to receive the message
  590.           text = text of the message
  591.         Sends a message to a specific player, and print it centered. 
  592.  
  593. Function: sprint
  594.  
  595.         void sprint (entity client, string text)
  596.           client = player that is to receive the message
  597.           text = text of the message
  598.         Sends a message to a player. 
  599.  
  600.  
  601. 3.10 Console 
  602.  
  603. Function: localcmd
  604.  
  605.         void localcmd (string text)
  606.           text = text of the command, ended by \n (newline).
  607.         Execute a command on the server, as if it had been typed on the server's console. 
  608.  
  609.         Examples: 
  610.  
  611.            localcmd("restart\n");      // restart the level
  612.            localcmd("teamplay 1\n");   // set deathmatch mode to teamplay
  613.            localcmd("killserver\n");   // poor server...
  614.  
  615. Function: dprint
  616.  
  617.         void dprint (string text)
  618.           text = text of the message
  619.         Prints a message to the server console. 
  620.  
  621. Function: cvar
  622.  
  623.         float cvar (string variable)
  624.           variable = see console variables
  625.         returns the value of a console variable. 
  626.  
  627. Function: cvar_set
  628.  
  629.         float cvar_set (string variable, string value)
  630.           variable = see console variables
  631.         sets the value of a console variable. 
  632.  
  633.  
  634. 3.11 Debugging
  635.  
  636. Function: eprint
  637.  
  638.         void eprint (entity e)
  639.           e = entity to print
  640.         Print details about a given entity (for debug purposes). 
  641.  
  642. Function: coredump
  643.  
  644.         void coredump()
  645.         Print all entities 
  646.  
  647. Function: traceon
  648.  
  649.         void traceon()
  650.         Start tracing functions, end them with traceoff() 
  651.  
  652. Function: traceoff
  653.  
  654.         void traceoff()
  655.         End traces started by traceon() 
  656.  
  657. Function: break
  658.  
  659.         void break()
  660.         Exit the programs. Never used? 
  661.  
  662. Function: error
  663.  
  664.         void error (string text)
  665.         Print an error message. 
  666.  
  667. Function: objerror
  668.  
  669.         void objerror (string text)
  670.         Print an error message related to object self. 
  671.  
  672. 3.12 Precaching files
  673.  
  674.         Those functions are used to declare models, sounds and stuff, before the PAK file is built. Just follow this rule: whenever one of your functions makes use of a file that's not defined in Quake, precache this file in a function that will be called by worldspawn(). Then, the QCC compiler can automatically include in the PAK file all the files that you really need to run your programs.
  675.         And when the level starts running, those precache orders will be executed, so as to attribute a fixed table index to all those files. DO NOT USE those functions in code that will be called after worldspawn() was called. As
  676. a matter of fact, that could bomb Quake (restarting the level, without crashing the game). 
  677.         Files can only be precached in spawn functions.
  678.  
  679. Function: precache_file
  680.  
  681.         void precache_file(string file)
  682.           file = name of the file to include in PAK file.
  683.         Does nothing during game play. 
  684.         Use precache_file2 for registered Quake. 
  685.  
  686. Function: precache_model
  687.  
  688.         void precache_model(string file)
  689.           file = name of the MDL or BSP file to include in PAK file.
  690.         Does nothing during game play. Must be used in a model's spawn function, to declare the model file. Use precache_model2 for registered Quake. 
  691.  
  692. Function: precache_sound
  693.  
  694.         void precache_sound(string file)
  695.           file = name of the WAV file to include in PAK file.
  696.         Does nothing during game play. Must be used in a model's spawn function, to declare the sound files. Use precache_sound2 for registered Quake. 
  697.  
  698.  
  699.  
  700. 4. Defines
  701. ________________________________________________________________________________
  702.  
  703. 4.1 Values: temporary entities
  704.  
  705. Information copied from the DEM specifications
  706.  
  707. // point entity is a small point like entity.
  708.  0    TE_SPIKE           unknown
  709.  1    TE_SUPERSPIKE      superspike hits (spike traps)
  710.  2    TE_GUNSHOT         hit on the wall (Axe, Shotgun)
  711.  3    TE_EXPLOSION       grenade/missile explosion
  712.  4    TE_TAREXPLOSION    explosion of a tarbaby
  713.  7    TE_WIZSPIKE        wizard's hit
  714.  8    TE_KNIGHTSPIKE     hell knight's shot hit
  715. 10    TE_LAVASPLASH      Chthon awakes and falls dead
  716. 11    TE_TELEPORT        teleport end
  717. // large entity is a 2 dimensional entity.
  718.  5    TE_LIGHTNING1      flash of the Shambler
  719.  6    TE_LIGHTNING2      flash of the Thunderbolt
  720.  9    TE_LIGHTNING3      flash in e1m7 to kill Chthon
  721.  
  722. 4.2 Values: Sound Channel of entities
  723.  
  724. CHAN_AUTO = 0;   // Create a new sound
  725. CHAN_WEAPON = 1; // Replace entitie's weapon noise
  726. CHAN_VOICE = 2;  // Replace entitie's voice
  727. CHAN_ITEM = 3;   // Replace entitie's item noise
  728. CHAN_BODY = 4;   // Replace entitie's body noise 
  729.  
  730. Those values are meant to be used with the function sound. 
  731.  
  732. 4.3 Values: Sound Attenuation
  733.  
  734. ATTN_NONE = 0;    // full volume everywhere in the leve
  735. ATTN_NORM = 1;    // normal
  736. ATTN_IDLE = 2;    // [FIXME]
  737. ATTN_STATIC = 3;  // [FIXME]
  738.  
  739. Those values are meant to be used with the functions sound and ambientsound. 
  740.  
  741. 4.4 Values: Contents of level areas
  742.  
  743. CONTENT_EMPTY = -1;   // Empty area
  744. CONTENT_SOLID = -2;   // Totally solid area (rock)   
  745. CONTENT_WATER = -3;   // Pool of water
  746. CONTENT_SLIME = -4;   // Pool of slime
  747. CONTENT_LAVA = -5;    // Lava
  748. CONTENT_SKY = -6;     // Sky
  749.  
  750. 4.5 Values: Entity light effects
  751.  
  752. EF_BRIGHTFIELD = 1;  // Glowing field of dots
  753. EF_MUZZLEFLASH = 2;
  754. EF_BRIGHTLIGHT = 4;
  755. EF_DIMLIGHT = 8;
  756.  
  757. 4.6 Values: Existing Items
  758.  
  759. IT_AXE = 4096;
  760. IT_SHOTGUN = 1;
  761. IT_SUPER_SHOTGUN = 2;
  762. IT_NAILGUN = 4;
  763. IT_SUPER_NAILGUN = 8;
  764. IT_GRENADE_LAUNCHER = 16;
  765. IT_ROCKET_LAUNCHER = 32;
  766. IT_LIGHTNING = 64;
  767. IT_EXTRA_WEAPON = 128;
  768. IT_SHELLS = 256;
  769. IT_NAILS = 512;
  770. IT_ROCKETS = 1024;
  771. IT_CELLS = 2048;
  772. IT_ARMOR1 = 8192;
  773. IT_ARMOR2 = 16384;
  774. IT_ARMOR3 = 32768;
  775. IT_SUPERHEALTH = 65536;
  776. IT_KEY1 = 131072;
  777. IT_KEY2 = 262144;
  778. IT_INVISIBILITY = 524288;
  779. IT_INVULNERABILITY = 1048576;
  780. IT_SUIT = 2097152;
  781. IT_QUAD = 4194304;
  782.  
  783. 4.7 Values: Behavior of solid objects
  784.  
  785. SOLID_NOT = 0;                 // no interaction with other objects
  786.                                // inactive triggers
  787. SOLID_TRIGGER = 1;             // touch on edge, but not blocking
  788.                                // active triggers, pickable items 
  789.                                // (.MDL models, like armors)
  790. SOLID_BBOX = 2;                // touch on edge, block
  791.                                // pickable items (.BSP models, like ammo box)
  792.                                // grenade, missiles
  793. SOLID_SLIDEBOX = 3;            // touch on edge, but not an onground
  794.                                // most monsters
  795. SOLID_BSP = 4;                 // bsp clip, touch on edge, block
  796.                                // buttons, platforms, doors, missiles
  797.  
  798. 4.8 Values: Type of movements
  799.  
  800.            
  801. MOVETYPE_NONE = 0;             // never moves
  802. //float MOVETYPE_ANGLENOCLIP = 1;
  803. //float MOVETYPE_ANGLECLIP = 2;
  804. MOVETYPE_WALK = 3;             // Walking players only
  805. MOVETYPE_STEP = 4;             // Walking monster
  806. MOVETYPE_FLY = 5;              // Hovering Flight 
  807.                                // meant for flying monsters (and players)
  808. MOVETYPE_TOSS = 6;             // Balistic flight 
  809.                                // meant for gibs and the like
  810. MOVETYPE_PUSH = 7;             // Not blocked by the world, push and crush 
  811.                                // meant for doors, spikes and crusing platforms
  812. MOVETYPE_NOCLIP = 8;           // Not blocked by the world
  813. MOVETYPE_FLYMISSILE = 9;       // like fly, but size enlarged against monsters
  814.                                // meant for rockets
  815. MOVETYPE_BOUNCE = 10;          // bounce off walls
  816. MOVETYPE_BOUNCEMISSILE = 11    // bounce off walls, but size enlarged against monsters
  817.                                // meant for grenades
  818.  
  819. 4.9 Values: Entity can solid take damage
  820.  
  821. DAMAGE_NO = 0;                 // Can't be damaged
  822. DAMAGE_YES = 1;                // Grenades don't explode when touching entity
  823. DAMAGE_AIM = 2;                // Grenades explode when touching entity
  824.  
  825. Most damageable entities have DAMAGE_AIM, so that when they chew on a grenade, it explodes. If you make an entity DAMAGE_YES, the grenades will bounce off it. 
  826.  
  827. 4.10 Values: Entity dead flag
  828.  
  829. DEAD_NO = 0;                   // still living
  830. DEAD_DYING = 1;                // dying (helpless)
  831. DEAD_DEAD = 2;                 // really dead
  832. DEAD_RESPAWNABLE = 3;          // dead, but can respawn
  833.  
  834. 4.11 Values: Spawnflags
  835.  
  836. The spawn flags are bit fields, whose interpretation depend on the concerned entity. There is quite a bit of a hack, that could cause unexpected bugs in the Quake C code. 
  837.  
  838.   DOOR_START_OPEN = 1;         // allow entity to be lighted in closed position
  839.   SPAWN_CRUCIFIED= 1;          // for zombie
  840.   PLAT_LOW_TRIGGER = 1;        // for func_plat
  841.   SPAWNFLAG_NOTOUCH= 1;
  842.   SPAWNFLAG_NOMESSAGE= 1;
  843.   PLAYER_ONLY = 1;
  844.   SPAWNFLAG_SUPERSPIKE = 1;    // for spike shooter
  845.   SECRET_OPEN_ONCE = 1;        // secret door, stays open
  846.   PUSH_ONCE = 1;
  847.   WEAPON_SHOTGUN = 1;          // weapon, shotgun
  848.   H_ROTTEN = 1;                // health, rotten (5-10 points)
  849.   WEAPON_BIG2 = 1;             // items 
  850.   START_OFF = 1;               // light, is off at start.
  851.   SILENT = 2;
  852.   SPAWNFLAG_LASER = 2;         // for spike shooter
  853.   SECRET_1ST_LEFT = 2;         // secret door, 1st move is left of arrow
  854.   WEAPON_ROCKET = 2;           // weapon, rocket
  855.   H_MEGA = 2;                  // health, mega (100 points)
  856.   DOOR_DONT_LINK = 4;
  857.   SECRET_1ST_DOWN = 4;         // secret door, 1st move is down from arrow
  858.   WEAPON_SPIKES = 4;           // weapon, nailgun
  859.   DOOR_GOLD_KEY = 8;
  860.   SECRET_NO_SHOOT = 8;         // secret door, only opened by trigger
  861.   WEAPON_BIG = 8;              // weapon, super model
  862.   DOOR_SILVER_KEY = 16;
  863.   SECRET_YES_SHOOT = 16;       // secret door, shootable even if targeted
  864.   DOOR_TOGGLE = 32;
  865.  
  866.  
  867.  
  868. 5. Entities
  869. ________________________________________________________________________________
  870.  
  871. Part of this information is derived from the DEM file specs 1.0.2 by Uwe Girlich. 
  872.  
  873. In Quake, monsters, players, items, and the level itself are all entities. There are three kind of entities, and you will all encounter them in Quake-C code. 
  874.  
  875. Types of entities
  876.  
  877. Static entities
  878.  
  879. A static entity doesn't interact with the rest of the game. These are flames (progs/flame.mdl), lights, illusionary objects, and
  880. the like. It is never be necessary to reference such an entity, so they don't get an entity reference number. 
  881.  
  882. A static entity will be created by the function: 
  883.  
  884. makestatic()
  885.  
  886. (it causes a spawnstatic message to be sent to every client).
  887. A static entity cannot be removed, once created. 
  888.  
  889. The maximum number of static entities is 127. 
  890.  
  891. Temporary entities
  892.  
  893. A temporary entity is a short life time entity. For instance, Quake uses these entities for hits on the wall (point-like entities)
  894. or for the Thunderbolt flash (line-like entities), gun shots, and anything that is not supposed to last more than one frame. 
  895.  
  896. A temporary entity will be created by sending a valid temporary entity message.
  897. A temporary entity need not be removed, it disapears by itself. 
  898.  
  899. Dynamic entities
  900.  
  901. A dynamic entity is anything which changes its behaviour or its appearance. These are ammunition boxes, spinning
  902. armors, player models and the like. 
  903.  
  904. A dynamic entity will be created by the sequence: 
  905.  
  906. entity = spawn();
  907. setmodel( entity, "progs/entity.mdl" );
  908. setsize( entity, vector_min, vector_max);      
  909. setorigin( entity, position );      
  910.  
  911. It will have to be removed by the function: 
  912.  
  913. remove( entity );
  914.  
  915. The maximum number of dynamic entities is 449. 
  916.  
  917.  
  918.  
  919. Definition of entity fields
  920.  
  921. These are the fields that are available in the entity objects (like self, other). Beware that this is not true object oriented
  922. programming: there is no protection when accessing those fields, and no guaranty on the validity of values. So if you put
  923. garbage there you will probably crash the game. 
  924.  
  925. You can add custom fields (for instance, to store the ammo count of a new weapon you created) but those fields must not
  926. be situated among thoses that are common between Quake-C and Quake.exe. Otherwise, Quake.exe would have to be
  927. re-compiled. So those fields must be situated after the fake variable called end_sys_fields, in the field definitions. 
  928.  
  929. Fields shared between Quake.exe and Quake-C
  930.  
  931. These fields describe the most common entity fields. They are shared between the C code of Quake.exe, and the
  932. Quake-C code of PROGS.DAT. 
  933.  
  934. Some of the fields are managed by the C code: you can read their value, but YOU SHOULD NEVER MODIFY THEIR
  935. VALUE DIRECTLY (there are special built-in functions for that). 
  936.  
  937. Technical data
  938.  
  939. entity  chain;                 // next entity, in a chain list of entities
  940. float   ltime;                 // local time for entity
  941. float   teleport_time;         // to avoid backing up
  942. float   spawnflags;            // see possible values. 
  943.  
  944. Appearance of entity
  945.  
  946. float   modelindex;            // index of model, in the precached list
  947. string  classname;             // spawn function
  948.  
  949. string  model;
  950.  
  951. The name of the file that contains the entity model. 
  952.  
  953. float   frame; 
  954.  
  955. This is the index of the currently displayed model frame. Frames must be defined by a $frame construct in the model file, and manipulated in the code as $xxx (where xxx is the name of the frame). 
  956.  
  957. float   skin;
  958.  
  959. This is the index of the model skin currently displayed. If your model has more than one skin defined, then this value indicates the skin in use. You can change it freely, as long as it remains in a valid range. For instance, it's used by the armor model to show the yellow, red or green skin. 
  960.  
  961. float   effects;
  962.  
  963. This is a flag that defines the special light effects that the entity is subject to. This can supposedly be used to make an entity glow, or to create a glowing field of dots around it.
  964.  
  965. Position in 3D
  966.  
  967.  
  968. vector  origin;                 // position of model
  969.     //  origin_x, origin_y, origin_z
  970. vector  mins;                   // bounding box extents reletive to origin
  971.     //  mins_x, mins_y, mins_z
  972. vector  maxs;                   // bounding box extents reletive to origin
  973.     //  maxs_x, maxs_y, maxs_z
  974. vector  size;                   // maxs - mins
  975.     //  size_x,size_y,size_z
  976. vector  absmin;                 // origin + mins and maxs
  977.     //  absmin_x absmin_y absmin_z
  978. vector  absmax;                 // origin + mins and maxs
  979.     //  absmax_x absmax_y absmax_z
  980. vector  oldorigin;              // old position
  981. vector  angles;                 // = 'pitch_angle yaw_angle flip_angle'
  982.  
  983. Quirks: setting the angles on a player entity doesn't work.
  984.  
  985. Situation of the entity
  986.  
  987. float   waterlevel;             // 0 = not in water, 1 = feet, 2 = waist, 3 = eyes
  988. float   watertype;              // a content value
  989. entity  groundentity;           // indicates that the entity moves on the ground
  990.  
  991. Since groundentity is used nowhere in progs, it's meaning is just a wild guess from a similar field in messages.
  992.  
  993. Movement in 3D
  994.  
  995. vector  velocity;               // = 'speed_x      speed_y    speed_z'
  996. vector  avelocity;              // = 'pitch_speed yaw_speed 0', angle velocity
  997. vector  punchangle;             // temp angle adjust from damage or recoil
  998. float   movetype;               // type of movement
  999. float   yaw_speed;              // rotation speed
  1000. float   solid;                  // tell if entity can block the movements.
  1001.  
  1002. Monster's Behavior
  1003.  
  1004. entity  goalentity;             // Monster's movetarget or enemy
  1005. float   ideal_yaw;              // Monster's ideal direction, on paths
  1006. float   yaw_speed;              // Monster's yaw speed.
  1007. string  target;                 // Target of a monster 
  1008. string  targetname;             // name of the target
  1009.  
  1010. Automatic Behavior
  1011.  
  1012. float   nextthink;              // next time when entity must act
  1013. void()  think;                  // function invoked when entity must act
  1014. void()  touch;                  // function invoked if entity is touched
  1015. void()  use;                    // function invoked if entity is used
  1016. void()  blocked;                // function for doors or plats, called when can't push other
  1017. vector  movedir;                // mostly for doors, but also used for waterjump
  1018. string  message;                // trigger messages
  1019. float   sounds;                 // either a cd track number or sound number
  1020. string  noise;                  // soudn played on entity noise channel 1
  1021. string  noise1;
  1022. string  noise2;
  1023. string  noise3;                 
  1024.  
  1025. Information by Abducted:
  1026. When you want an entity to do something specific, after a certain delay (exploding, disapearing, or the like...), you set nextthink to that delay (in seconds), and set think to the function to execute. 
  1027.  
  1028. Information by Greg Lewis:
  1029. It seems that the touch function is called before the field is checked, so you can set this type in the touch function, and it will immediatly be taken into account. 
  1030.  
  1031. Player/Monster stats and damage status
  1032.  
  1033. float   deadflag;               // tells if an entity is dead.
  1034. float   health;                 // health level
  1035. float   max_health;             // players maximum health is stored here
  1036. float   takedamage;             // indicates if entity can be damaged
  1037. float   dmg_take;               // damage is accumulated through a frame. and sent as one single
  1038. float   dmg_save;               // message, so the super shotgun doesn't generate huge messages
  1039. entity  dmg_inflictor;          // entity that inflicted the damage (player, monster, missile, door)
  1040.  
  1041. Player inventory
  1042.  
  1043. float   items;                  // bit flags
  1044. float   armortype;              // fraction of damage absorbed by armor
  1045. float   armorvalue;             // armor level
  1046. float   weapon;                 // one of the IT_SHOTGUN, etc flags
  1047. string  weaponmodel;            // entity model for weapon
  1048. float   weaponframe;            // frame for weapon model
  1049. float   currentammo;            // ammo for current weapon
  1050. float   ammo_shells;            // remaining shells
  1051. float   ammo_nails;             // remaining nails
  1052. float   ammo_rockets;           // remaining rockets and grenades
  1053. float   ammo_cells;             // remaining lightning bolts
  1054.  
  1055. float   impulse;                // weapon changes
  1056.  
  1057. When set to 0, the player's weapon doesn't change. When different from zero, this field is interpreted by the Quake-C
  1058. impulse command as a request to change weapon (see ImpulseCommand). 
  1059.  
  1060. Player Fight
  1061.  
  1062. entity  owner;                  // Entity that owns this one (missiles, bubbles are owned by the player)
  1063. entity  enemy;                  // personal enemy (only for monster entities)
  1064. float   button0;                // fire
  1065. float   button1;                // use
  1066. float   button2;                // jump
  1067. vector  view_ofs;               // position of player eye, relative to origin
  1068. float   fixangle;               // set to 1 if you want angles to change now
  1069. vector  v_angle;                // view or targeting angle for players
  1070. float   idealpitch;             // calculated pitch angle for lookup up slopes
  1071. entity  aiment;                 // aimed antity?
  1072.  
  1073. Deathmatch
  1074.  
  1075. float   frags;                  // number of frags
  1076. string  netname;                // name, in network play
  1077. float   colormap;               // colors of shirt and pants
  1078. float   team;                   // team number
  1079. float   flags;                  // ?
  1080.  
  1081. Fields used only by Quake-C (User defined)
  1082.  
  1083. These entity fields are used only by Quake-C programs, and are never referenced by the C code of Quake.exe. So you
  1084. can do whatever you want with the values, so long as it's compatible with what other Quake-C modules do.
  1085.  
  1086. If the fields defined here are not suitable for you, you can define new fields, by adding them at the end of the defintion of
  1087. fields. As a matter of fact, the number of fields in an entity (hence the size of all the instances of entity objects) is
  1088. determined by Quake-C: in the PROGS.DAT header, a value named entityfields indicates to Quake.exe the size of the
  1089. entity object. 
  1090.  
  1091. Beware however that the more field you add, the more each entity will suck memory. Add just one float (4 bytes) and it
  1092. will take, in memory, 4 bytes time the number of entity. 
  1093.  
  1094. The best is to share fields between distinct classes of entities, by reusing the same position for another kind of field. If the
  1095. Quake C Compiler was a real object-oriented compiler, that would be done very safely by single-inheritance
  1096. (multiple-inheritance would be a deadly mistake). You will also notice that id software has made quite a lousy usage of
  1097. most of the fields, defining much more than were actually needed, since they are only used by a few entities.
  1098.  
  1099. World fields
  1100.  
  1101. string wad;                      // name of WAD file with misc graphics  
  1102. string map;                      // name of the map being played
  1103. float  worldtype;                // see below
  1104.  
  1105. worldtype is 0 for a medieval setting, 1 for metal, and 2 for a base setting.
  1106. These fields might soon become global variables, so don't rely too much on them. 
  1107.  
  1108. Quake Ed fields
  1109.  
  1110. string killtarget;
  1111. float light_lev;                 // not used by game, but parsed by light util
  1112. float style;
  1113.  
  1114. Monster Behaviour
  1115.  
  1116. Those functions are called when these specific events happen: 
  1117.  
  1118. void() th_stand;            // when stands iddle
  1119. void() th_walk;             // when is walking
  1120. void() th_run;              // when is running
  1121. void() th_missile;          // when a missile comes
  1122. void() th_melee;            // when fighting in melee
  1123. void() th_die;              // when dies
  1124.  
  1125. void(entity attacker, float damage) th_pain;
  1126.  
  1127. That function is executed when the monster takes a certain amount of damage from an attacker (a player, or another
  1128. monster). Will usually cause the monster to turn against the attacker. 
  1129.  
  1130. Monster state variables
  1131.  
  1132. entity oldenemy;            // mad at this player before taking damage
  1133. float  speed;               //
  1134. float  lefty;               //
  1135. float  search_time;         //
  1136. float  attack_state;        //
  1137.  
  1138. float   pausetime;
  1139. entity  movetarget;
  1140.  
  1141. Player Only
  1142.  
  1143. float   walkframe;
  1144. float   attack_finished;
  1145. float   pain_finished;         // time when pain sound is finished
  1146. float   invincible_finished;
  1147. float   invisible_finished;
  1148. float   super_damage_finished;
  1149. float   radsuit_finished;
  1150. float   invincible_time;       // time when player cease to be invincible
  1151. float   invincible_sound;
  1152. float   invisible_time;        // time when player cease to be invisible
  1153. float   invisible_sound;
  1154. float   super_time;            // time when quad shot expires?
  1155. float   super_sound;
  1156. float   rad_time;
  1157. float   fly_sound;
  1158. float   axhitme;               // TRUE if hit by axe
  1159. float   show_hostile;          // set to time+0.2 whenever a client fires a
  1160.                                // weapon or takes damage.  Used to alert
  1161.                                // monsters that otherwise would let the player go
  1162. float   jump_flag;             // player jump flag
  1163. float   swim_flag;             // player swimming sound flag
  1164. float   air_finished;          // when time > air_finished, start drowning
  1165. float   bubble_count;          // keeps track of the number of bubbles
  1166. string  deathtype;             // keeps track of how the player died
  1167.  
  1168. Object stuff
  1169.  
  1170. string  mdl;                    // model name?
  1171. vector  mangle;                 // angle at start. 'pitch roll yaw'
  1172. vector  oldorigin;              // only used by secret door
  1173. float   t_length;
  1174. float   t_width;
  1175.  
  1176. Doors
  1177.  
  1178. vector  dest;
  1179. vector  dest1;
  1180. vector  dest2;
  1181. float   wait;                   // time from firing to restarting
  1182. float   delay;                  // time from activation to firing
  1183. entity  trigger_field;          // door's trigger entity
  1184. string  noise4;
  1185. float   aflag;
  1186. float   dmg;                    // damage done by door when hit
  1187.  
  1188. Miscellaneous
  1189.  
  1190. float   cnt;                    // counter
  1191. void()  think1;
  1192. vector  finaldest;
  1193. vector  finalangle;
  1194. //
  1195. // triggers
  1196. //
  1197. float   count;                  // for counting triggers
  1198. //
  1199. // plats / doors / buttons
  1200. //
  1201. float   lip;
  1202. float   state;
  1203. vector  pos1;
  1204. vector  pos2;                   // top and bottom positions
  1205. float   height;
  1206. //
  1207. // sounds 
  1208. //
  1209. float   waitmin;
  1210. float   waitmax;
  1211. float   distance;
  1212. float   volume;
  1213.  
  1214.  
  1215. 5.      Global Variables
  1216. ________________________________________________________________________________
  1217.  
  1218. These variables are accessible in every functions.
  1219. Quake C function are not supposed to modify them directly.
  1220.  
  1221. Variable: world
  1222.  
  1223. the server's world object, which holds all global state for the server, like the deathmatch flags and the body ques. 
  1224.  
  1225. Variable: time
  1226.  
  1227.   float time;               // in seconds
  1228.  
  1229. The current game time, a floating point value in seconds. Note that because the entities in the world are simulated
  1230. sequentially, time is NOT strictly increasing. An impact late in one entity's time slice may set time higher than the think
  1231. function of the next entity. The difference is limited to 0.1 seconds. 
  1232.  
  1233. Variable: frametime
  1234.  
  1235.   float frametime;           // in seconds
  1236.  
  1237. No idea what this can be. Used only when jumping in water. 
  1238.  
  1239. Variable: self
  1240.  
  1241.  entity self;
  1242.  
  1243. The entity that is subject to the current function. 
  1244.  
  1245. Variable: other
  1246.  
  1247.  entity other;
  1248.  
  1249. The object concerned by an impact, not used for thinks. 
  1250.  
  1251. Variable: force_retouch
  1252.  
  1253.   float force_retouch;  // counter
  1254.  
  1255. Force all entities to touch triggers next frame. this is needed because non-moving things don't normally scan for triggers,
  1256. and when a trigger is created (like a teleport trigger), it needs to catch everything.
  1257. It is decremented each frame, so it is usually set to 2 to guarantee everything is touched. 
  1258.  
  1259. Variable: mapname
  1260.  
  1261.   string mapname;
  1262.  
  1263. Name of the level map currently being played, like "start". 
  1264.  
  1265. Variable: deathmatch
  1266.  
  1267.   float deathmatch;  // a boolean value, 0 or 1
  1268.  
  1269. True if playing deathmatch. 
  1270.  
  1271. Variable: coop
  1272.  
  1273.   float coop;  // a boolean value, 0 or 1
  1274.  
  1275. True if playing cooperative. 
  1276.  
  1277. Variable: teamplay
  1278.  
  1279.   float teamplay;  // a boolean value, 0 or 1
  1280.  
  1281. True if playing by teams. 
  1282.  
  1283. Variable: serverflags
  1284.  
  1285.   float serverflags;  // bit fields
  1286.  
  1287. Propagated from level to level, and used to keep track of the completed episodes.
  1288. If serverflag & ( 1 << e)) is true, then episode e was already completed.
  1289. Generally equal to player.spawnflags & 15. 
  1290.  
  1291. Variable: total_secrets
  1292.  
  1293.   float total_secrets;  // counter
  1294.  
  1295. Number of secrets found by the players. Affected only by trigger_secret. 
  1296.  
  1297. Variable: found_secrets
  1298.  
  1299.   float found_secrets;  // counter
  1300.  
  1301. Number of secrets found. 
  1302.  
  1303. Variable: total_monsters
  1304.  
  1305.   float total_monsters;  // counter
  1306.  
  1307. Total number of monsters that were spawned, since the begining of the level. 
  1308.  
  1309. Variable: killed_monsters
  1310.  
  1311.   float killed_monsters;  // counter
  1312.  
  1313. Store the total number of monsters killed. 
  1314.  
  1315. Variable: parm1...parm16
  1316.  
  1317.   float parm1; // items bit flag (IT_SHOTGUN | IT_AXE )
  1318.   float parm2; // health
  1319.   float parm3; // armorvalue
  1320.   float parm4, parm5, parm6, parm7; // ammo
  1321.   float parm8; // weapon 
  1322.   float parm9; // armortype*100
  1323.   float parm10, parm11, parm12, parm13, parm14, parm15, parm16;
  1324.  
  1325. Those parameters seem to be a bit of hack. They are used when a client connects.
  1326. Spawnparms are used to encode information about clients across server level changes 
  1327.  
  1328.  
  1329.  
  1330. Functions that are mandatory in Quake-C
  1331.  
  1332. These functions must be defined in Quake C, since they are invoked by Quake under certain conditions.
  1333.  
  1334. Misc
  1335.  
  1336. void main();
  1337.  
  1338. Only used for testing progs. 
  1339.  
  1340. void StartFrame();
  1341.  
  1342. Called at the start of each frame. 
  1343.  
  1344. Behavior of players
  1345.  
  1346. void PlayerPreThink();
  1347.  
  1348. Called with self=player, for every frame, before physics are run. 
  1349.  
  1350. void PlayerPostThink();
  1351.  
  1352. Called with self=player, for every frame, after physics are run. 
  1353.  
  1354. Management of network game clients
  1355.  
  1356. void ClientKill();
  1357.  
  1358. Called when a player suicides. 
  1359.  
  1360. void ClientConnect();
  1361.  
  1362. Called when a player connects to a server, but also, for every player, when a new level starts.
  1363. It is used to announces the new player to every other players. 
  1364.  
  1365. void PutClientInServer();
  1366.  
  1367. Call after setting the parm1... parm16. 
  1368.  
  1369. void ClientDisconnect();
  1370.  
  1371. Called when a player disconnects from a server
  1372. Announce that the player has left the game. 
  1373.  
  1374. void SetNewParms(); 
  1375.  
  1376. Called when a client first connects to a server. Sets parm1...parm16 so that they can be saved off for restarts. 
  1377.  
  1378. void SetChangeParms();
  1379.  
  1380. Call to set parms for self so they can? 
  1381.  
  1382. 6.      Model pragma
  1383. ________________________________________________________________________________
  1384.  
  1385. (Derived from information published by Steve Tietze)
  1386.  
  1387. Here are a few definitions that are commonly found in the Quake-C code defining the behavior of animated models
  1388. (monsters, players, etc...). 
  1389.  
  1390. Most of this information is not interpreted by the Quake-C compiler, but it's useful for the program modelgen that
  1391. generates the models. 
  1392.  
  1393. Model name
  1394.  
  1395. $modelname name
  1396.  
  1397. name is the name of the model file defining the object.
  1398. ex: $name armor 
  1399.  
  1400. directory
  1401.  
  1402. $cd dir
  1403.  
  1404. Specify the directory where your model file (.MDL) is located.
  1405. ex: $cd /evil/models/armor 
  1406.  
  1407. Special animation flags
  1408.  
  1409. $flags  rotation
  1410.  
  1411. This field is not interpreted by Quake-C, but it's useful for the program modelgen that generates the models.
  1412. Rotation of the object. 
  1413. ex: $flags 8
  1414. Possible values for the flags: 
  1415.  
  1416.     8: the object keeps rotating, like armors. 
  1417.     other values are not known yet 
  1418.  
  1419. Origin
  1420.  
  1421. $origin x y z
  1422.  
  1423. This field is not interpreted by Quake-C, but it's useful for the program modelgen that generates the models.
  1424. Location of the object within the bounding box, in the quake editor.
  1425. ex: $origin 0 0 8 
  1426.  
  1427. Scale factor
  1428.  
  1429. $scale number
  1430.  
  1431. This field is not interpreted by Quake-C, but it's useful for the program modelgen that generates the models.
  1432. number comes from the texmake number that is generated.
  1433. You can use different values if you want.
  1434. ex: $scale 4 
  1435.  
  1436. Base
  1437.  
  1438. $base  object
  1439.  
  1440. This field is not interpreted by Quake-C, but it's useful for the program modelgen that generates the models.
  1441. object is the name of a model file, that will be used as a kind of starting position, for animation. 
  1442.  
  1443. Skin file
  1444.  
  1445. $skin  skinfile
  1446.  
  1447. This field is not interpreted by Quake-C, but it's useful for the program modelgen that generates the models.
  1448. skinfile is the name (without extension) of the .lbm file that defines the skin of the object, as generated by the program
  1449. texmake. 
  1450.  
  1451. Frame definitions
  1452.  
  1453. $frame  frame1 frame2 ...
  1454.  
  1455. This defines several animation frames of the object.
  1456. For every animation frame defined, you must also define a Quake-C function, that will be called during this animation
  1457. frame. For instance:
  1458.  
  1459. $frame walk1 walk2 walk3 walk4
  1460. void() man_walk1 = [ $walk1, man_walk2 ] { ... some code ... };
  1461. void() man_walk2 = [ $walk2, man_walk3 ] { ... some code ... };
  1462. void() man_walk3 = [ $walk3, man_walk4 ] { ... some code ... };
  1463. void() man_walk4 = [ $walk4, man_walk1 ] { ... some code ... };
  1464.  
  1465. In the brackets, the first parameter defines the name of the frame (as found in the model file), and the second parameter
  1466. defined the function that is to be executed in the next frame (by setting the value of self.nextthink).
  1467.  
  1468. Most of these functions do nothing special, but some can be very complex (for instance, the functions that are called when
  1469. the monster tries to see a player).
  1470.  
  1471. 7.      Network protocol
  1472. ________________________________________________________________________________
  1473.  
  1474. Quake-C is not supposed to handle a lot of network messages, since most are already handled in C. 
  1475.  
  1476. However, builtin functions have not been built for every kind of messages in the Quake protocol, so you migth end-up composing protocol messages in Quake-C. I highly recommend that you build a single function to handle a given message type, because the structure of those messages might change, and then all your code would have to be checked for bugs. 
  1477.  
  1478. By that way, id software didn't even bothered to write a function to generate temporary entites, though they keep using this message. It's still a long way to ISO 9001, I'm afraid. 
  1479.  
  1480. Definitions related to protocol messages
  1481.  
  1482. Values: How messages are sent
  1483.  
  1484. MSG_BROADCAST = 0;  // unreliable message, sent to all
  1485. MSG_ONE = 1;       // reliable message, sent to msg_entity
  1486. MSG_ALL = 2;       // reliable message, sent to all
  1487. MSG_INIT = 3;   // write to the init string
  1488.  
  1489.     Use unreliable (but fast) messages, when it's of no importance that a client misses the message.
  1490.     examples: sound, explosions, monster deaths, taunts....
  1491.     Use reliable messages when it's very important that every client sees the message, or a game incoherency might
  1492.     happen.
  1493.     examples: shots, player deaths, door moves, game ends ... and CD track changes!. 
  1494.  
  1495. Values: Type of message
  1496.  
  1497. These are some of message types defined in the Quake network protocol. 
  1498.  
  1499. SVC_SETVIEWPORT = 5;
  1500. SVC_SETANGLES = 10;
  1501. SVC_TEMPENTITY = 23;
  1502. SVC_KILLEDMONSTER = 27;
  1503. SVC_FOUNDSECRET = 28;
  1504. SVC_INTERMISSION = 30;
  1505. SVC_FINALE = 31;
  1506. SVC_CDTRACK = 32;
  1507. SVC_SELLSCREEN = 33;
  1508. SVC_UPDATE = 128;
  1509.  
  1510. Some message structures
  1511.  
  1512. Here are some of the messages defined in the Quake network protocol.
  1513.  
  1514. Beware, the structure of those messages might change in future version (Satan forbids!).
  1515.  
  1516. Message: Set View Position
  1517.  
  1518.   msg_entity = player
  1519.   WriteByte (MSG_ONE, SVC_SETVIEWPORT);
  1520.   WriteEntity( MSG_ONE, camera);
  1521.  
  1522. This message is meant for a single client player. It sets the view position to the position of the entity camera. 
  1523.  
  1524. Message: Set View Angles
  1525.  
  1526.   msg_entity = player
  1527.   WriteByte (MSG_ONE, SVC_SETVIEWANGLES);
  1528.   WriteAngle( MSG_ONE, camera.angles_x); 
  1529.   WriteAngle( MSG_ONE, camera.angles_y);
  1530.   WriteAngle( MSG_ONE, camera.angles_z);
  1531.  
  1532. This message is meant for a single client player. It set the orientation of it's view to the same orientation than the entity
  1533. camera. 
  1534.  
  1535. Message: Temporary Entity
  1536.  
  1537.   WriteByte (MSG_BROADCAST, SVC_TEMPENTITY);
  1538.   WriteByte (MSG_BROADCAST, entityname);
  1539.   WriteCoord (MSG_BROADCAST, origin_x);
  1540.   WriteCoord (MSG_BROADCAST, origin_y);
  1541.   WriteCoord (MSG_BROADCAST, origin_z);
  1542.  
  1543. Message: Set CD Track
  1544.  
  1545.   WriteByte (MSG_ALL, SVC_CDTRACK);
  1546.   WriteByte (MSG_ALL, val1);        // CD start track
  1547.   WriteByte (MSG_ALL, val2);        // CD end track
  1548.  
  1549. Message: Final Message
  1550.  
  1551.   WriteByte (MSG_ALL, SVC_FINALE);
  1552.   WriteString (MSG_ALL, "any text you like\n");
  1553.  
  1554. Message: Sell Screen
  1555.  
  1556. WriteByte (MSG_ALL, SVC_SELLSCREEN);
  1557.  
  1558. Shows the infamous sell screen (like you needed it to understand). 
  1559.  
  1560. Message: Inter Mission
  1561.  
  1562. WriteByte (MSG_ALL, SVC_INTERMISSION);
  1563.  
  1564. Shows the inter mission camera view. 
  1565.  
  1566. Message: Killed Monster
  1567.  
  1568. WriteByte (MSG_ALL, SVC_KILLEDMONSTER);
  1569.  
  1570. Increase by one the count of killed monsters, as available to the client. Can be displayed with showscores. 
  1571.  
  1572. Message: Found Secrets
  1573.  
  1574. WriteByte (MSG_ALL, SVC_FOUNDSECRET);
  1575.  
  1576. Increase by one the count of secrets founds. 
  1577.  
  1578. Message: Update Entity
  1579.  
  1580. This message has a rather complex structure. I already generated some valid update messages, but since the message
  1581. structure seems highly susceptible to change in the next versions of Quake, I would recommend that you never use such
  1582. messages: as a matter of fact, Quake itslef is very capable of generating all the required messages... unless you start
  1583. creating deathmatch cameras or the like. 
  1584.  
  1585.  
  1586. 8.      Network Builtin functions
  1587. ________________________________________________________________________________
  1588.  
  1589.  
  1590. Beware: when generating messages, you had better respect the format of the existing messages. Otherwise the game
  1591. clients might not be able to interpret them (and will likely crash).
  1592.  
  1593. The functions below all write to clients (players connected via the network, or the local player).
  1594.  
  1595. Global variable for network messages
  1596.  
  1597. Variable: msg_entity
  1598.  
  1599. entity  msg_entity;
  1600.  
  1601. If you want to send a message to just one entity e, then set msg_entity= e and send the message with flag MSG_ONE,
  1602. instead of MSG_ALL.
  1603. Never used. Maybe it doesn't even work. 
  1604.  
  1605. Builtin functions for composing network messages
  1606.  
  1607. Function: WriteByte
  1608.  
  1609. void WriteByte(float to, float value)
  1610.        to = see messages
  1611.  
  1612. Function: WriteChar
  1613.  
  1614. void WriteChar(float to, float value)
  1615.        to = see messages
  1616.  
  1617. Function: WriteShort
  1618.  
  1619. void WriteShort(float to, float value)
  1620.        to = see messages
  1621.  
  1622. Function: WriteLong
  1623.  
  1624. void WriteLong(float to, float value)
  1625.        to = see messages
  1626.  
  1627. Function: WriteCoord
  1628.  
  1629. void WriteCoord(float to, float value)
  1630.        to = see messages
  1631.  
  1632. Function: WriteAngle
  1633.  
  1634. void WriteAngle(float to, float value)
  1635.        to = see messages
  1636.  
  1637. This function writes a single byte, that represents 256*(angle/380). 
  1638.  
  1639. Function: WriteString
  1640.  
  1641. void WriteString(float to, string value)
  1642.        to = see messages
  1643.  
  1644. This function writes a string, terminated by \0 (the null character in C). 
  1645.  
  1646. Function: WriteEntity
  1647.  
  1648. void WriteEntity(float to, entity value)
  1649.        to = see messages
  1650.  
  1651. This function writes an entity reference, taking two bytes. 
  1652.  
  1653. 9.      Tips & tricks
  1654. ________________________________________________________________________________
  1655.  
  1656. Here are some characteristics of Quake-C that you had better be aware of. 
  1657.  
  1658. The names of variable and functions must be unique
  1659.  
  1660. The names of functions, variables and fields must be unique. For instance, you cannot define a variable with the same
  1661. name as a field. However, local variables can be defined more than once (they had better!). 
  1662.  
  1663. Composition of function is not supported
  1664.  
  1665. Since all the functions use a single parameter marshaling area, and a single global variable to store their reture result, you
  1666. should NEVER try to call a function within another function call.
  1667.  
  1668. Example: printing the coordinate of entity self 
  1669.  
  1670.     sprintf(self, vtos( self.origin ));
  1671.  
  1672. will fail miserably (sending the message somewhere in hell), so it should be replaced by: 
  1673.  
  1674.     text = vtos( self.origin );
  1675.     sprintf(self, text);
  1676.  
  1677. Unfortunately, this also applies to operators: 
  1678.  
  1679.    sum = anglestovec( 45) + anglestovec( 90);
  1680.  
  1681. will fail an should be replaced by: 
  1682.  
  1683.    sum = anglestovec( 45);
  1684.    sum = sum + anglestovec( 90);
  1685.  
  1686. Actually, Quake-C is rather lame as a compiler, and you will probably make hundred of little mistakes like that, that the compiler will not warn you of. But remember Quake-C was built for "performance", not ease of use. And also that it wasn't designed by people from the MIT. Remember also that you got it for free... you can always get gcc (the Gnu C Compiler) for the same price ;-) 
  1687.  
  1688. You cannot initialise variable with default values.
  1689.  
  1690. If you give a default value to a quake-C variable, this variable will be considered as a constant. And since the value of
  1691. constants is not supposed to change, your program may not work properly after that. 
  1692.  
  1693. Coordinates are relative to the world.
  1694.  
  1695. All the geometry (coordinate positions, directions, angles) are relative to the world. They are never relative to a given
  1696. object. To know the direction an object is facing, you have to require calculation of the v_front vector (respectively
  1697. v_right and v_up for the right, and the top). 
  1698.  
  1699.  
  1700.  
  1701. Frequently Asked Questions about Quake-C
  1702.  
  1703. How do I change the viewpoint?
  1704.  
  1705. You would like that a given player sees through the eyes of another entity. This commonly happens at the end of the level
  1706. (all players see through a camera), or when the player head is severed (gibbed), or when a player is invisible (he only
  1707. exists as his eyes).
  1708.  
  1709. But the example above work by changing the player entity, and what you want is probably just to see through a camera
  1710. (Duke3D) or a missile (Descent).
  1711.  
  1712. This operation is known in the Quake network protocol as a setview message. But nowhere it's defined in Quake-C, and
  1713. there's no function to change the view port. So the solution is to encode a set view port message, followed by a set view
  1714. angles message (to take the orientation of the camera). 
  1715.  
  1716. This works fine, except that if, for some reason, the entity you are using as a camera was not previously declared to the
  1717. client, then the view port will be set to '0 0 0', which is usually somewhere in the void. 
  1718.  
  1719. How do I teleport a player into another server
  1720.  
  1721. A trick by Steven Lang (tiger@ecis.com)
  1722.  
  1723.     // In the slipgate touch function
  1724.     // other = entity that touched
  1725.     if(other.classname == "player")
  1726.       stuffcmd(other, "connect server.address\n");  // send command
  1727.  
  1728. When the slipgate is touched, the entity jumps to another server.
  1729.  
  1730. Trouble: the player stats and weapons won't be preserved, and the player would be dumped to the console if the other server was full or not available.
  1731. That's why John Carmack, will rewrite the code of Quake.exe to implement his Quake World proposal, and advanced server with all kinds of goodies... permission lists, ability to block an IP, etc. (info from quake-c list).
  1732.  
  1733. How do I manipulate strings in Quake-C?
  1734.  
  1735. Well, you can have any kind of strings, as long as they cannot be changed. 
  1736.  
  1737. "In Ford we trust" (Brave New World). 
  1738.  
  1739. Mind you, pr_comp.c, defines only operations = == != on strings.
  1740.  
  1741. How to read string variables, or text messages?
  1742.  
  1743. Well, if you know, tell, that would make a nice addition to this specs.
  1744.  
  1745. How do I move an entity in Quake-C?
  1746.  
  1747. You have better not touch it's position, else some stuff in the C code might not be valid anymore. So you call the
  1748. setposition() built-in function. 
  1749.  
  1750. How to change the velocity of an entity (make it bounce off walls)?
  1751.  
  1752. Information by Greg Lewis.
  1753.  
  1754. It seems that an entity's velocity can't be changed in the Touch function of the entity. Making the calculations there will be of no use. So just set entity.movetype to MOVETYPE_BOUNCE, entity.nextthink to 0.1 (to let it bounce off), and set entity.think to the name of a function that, when called 0.1 second later, will set entity.velocity to the right direction. 
  1755.  
  1756. How to calculate the direction a player is facing?
  1757.  
  1758. Assuming the player is self, the entity field self.angles contains the orientation angles of the player (as set by moving the mouse). 
  1759.  
  1760. Then the function makeverctors( self.angles) will calculate three vectors, that point in the direction the player is facing, but also to the right of the player (strafing direction) and to the direction the player is standing. 
  1761.  
  1762. Note that those vectors are normalised to 1, so if you want to know what lays 100 units in front of the player, use self.origin + 100 * facing. 
  1763.  
  1764. How to send a message to a client when he logs in?
  1765.  
  1766. It has been noticed that using a sprint() in function ClientConnect just plain doesn't send any message at all. Maybe the client is not ready to receive messages at this point. 
  1767.  
  1768. However, Doug Keenan (doug.keegan@tamu.edu) has reported he could send such a text message by putting the sprint() close to the begining of the ClientConnect function. It doesn't work at the end, apparently. 
  1769.  
  1770.  
  1771. Writing Quake-C code
  1772.  
  1773. Here are some suggestions that you should really consider when writing Quake-C code. Well, there are no obligations,
  1774. but that would make life simpler for others when they read your code (and thus for you when you read theirs).
  1775.  
  1776. I assume here that you want to develop code that others can re-use, or that can be mixed seamlessly with codes written by
  1777. others.
  1778.  
  1779. (If you are reinventing the whole world all by yourself, you hardly need any help or counsels. By the way, the first command is +light). 
  1780.  
  1781.   1.Please put comments in your code.
  1782.     Of course, the real gurus don't need comments. They understand raw Quake-C, even compiled. They can even imagine all the parts of your code
  1783.     before they read them. Even before you write them. But actually, they seldom read your code. Only normal people do. 
  1784.   2.Please tag the begining and end of your modifications, if you are fixing a code from someone else.
  1785.     Also put a date, and put a reason for the fix. Example:
  1786.  
  1787.            // Patch by Nezu The Unworthy  8/3/96 
  1788.            // Gimme a chance to win a deathmatch
  1789.            if(self.name != "nezu")
  1790.              self.frag = self.frag - 10;
  1791.            // Patch End
  1792.       
  1793.  
  1794.   3.Each time you create a new function, a new variable or a new field, please give it a name that will not conflict with
  1795.     function or variable defined by others.
  1796.     A rather sure way to do this is to prefix every name with some abvreviated module name, or you initials, or whatever
  1797.     rare combination of three or four letter. Example: 
  1798.  
  1799.          void() NTU_think =  // Nezu The Unworthy starts thinking
  1800.          {
  1801.             self.skin = 1;   // turn red and boil
  1802.          };
  1803.          
  1804.  
  1805.   4.Each time you implement some set of related functions, you should create a new Quake-C module, and give it a
  1806.     name different from the existing ones.
  1807.     Please do not use one of the module names used by id software, this would be confusing. Try to be original, else we
  1808.     might end-up with two hundred modules called impulse.qc. 
  1809.   5.When you want to distribute some modified Quake-C programs: 
  1810.         include a file_id.diz file explaining in 5 lines what your patch does, and where it should be stored in the archives
  1811.         (this file is to be read by system administrators) 
  1812.         include a readme.txt file explaining in details what your patch does, how it does it, and what common files you
  1813.         had to modify. 
  1814.         include the .qc modules that you created from scratch. 
  1815.         For the modules you modified, please let them pass through the utilities diff (see below), so that the original file
  1816.         can be patched the utility patch. even if it has been modified since. 
  1817.         Do not distribute modified .qc modules. Future versions of Quake will contain different code, and all your work
  1818.         would then be lost. 
  1819.   6.You should compile and distribute a version of your code, as a single PROGS.DAT file, to be used by those who just
  1820.     wanna have fun. Don't forget them, they largely overnumber the people who directly deal with Quake-C. 
  1821.   7.Upload your Quake-C patches to the primary quake ftp site at ftp.cdrom.com.
  1822.     Maybe if it's good enough it will also appear in the Quake-C code repository. 
  1823.  
  1824. Using Diff and Patch
  1825.  
  1826. Information by Jeff Epler (jepler@cse.unl.edu)
  1827.  
  1828. You can find a DOS version of diff and patch on all the major ftp archives, for instance Simtelnet (mirrored at
  1829. ftp://oak.oakland.edu/pub/simtelnet). 
  1830.  
  1831. For a Win32 (windows95 and NT) version, see diffutils.zip and patch.zip. 
  1832.  
  1833. The full documentation for diff and patch is available on www.ai.mit.edu, but here are some shortened instructions: 
  1834.  
  1835. To make a diff:
  1836. . start with yourdir/ with an entire working set of .qc files, and v101qc/
  1837. with the virgin qc files from id.
  1838. . diff -ur --new-file v101qc yourdir > patchfil
  1839.  
  1840. To patch with a diff:
  1841. . copy everything in v101qc (or yourdir if you want to add these patches to
  1842. your already-customized setup) to newdir
  1843. . change to newdir
  1844. . patch -p1 < patchfil
  1845. . Look for any "rejected" patches and apply them by hand using your
  1846. favorite 2-window text editor.  These should be few or none if the author
  1847. kept his changes well-structured or you patched from exactly the same
  1848. source he diffed from.
  1849.  
  1850. 10.     Types
  1851. ________________________________________________________________________________
  1852.  
  1853. Simple Types
  1854.  
  1855. Type: void
  1856.  
  1857. An empty result, mostly used for definition of procedures (i.e. functions that return no result at all). 
  1858.  
  1859. Type: float
  1860.  
  1861. A floating point value.
  1862.  
  1863. Floats are also used to store booleans (TRUE, FALSE) or integer values linke counters, or bit flags.
  1864.  
  1865.     Valid syntax: 12  1.6   0.5   -100  
  1866.     Invalid syntax: .5
  1867.  
  1868. A parsing ambiguity is present with negative constants. "a-5" will be parsed as "a", then "-5", causing an error. Separate
  1869. the - from the digits with a space "a - 5" to get the proper behavior. 
  1870.  
  1871. Type: vector
  1872.  
  1873. A vector, made of 3 float coordinates. 
  1874. Used to represent positions or directions in 3D space. 
  1875. Valid syntax: '0 0 0' or '20.5 -10 0.00001' 
  1876.  
  1877. Note the simple quotes around the vector. Do not use double quotes, they are reserved for strings.
  1878.  
  1879. If you declare a vector foobar, then you can access it's x, y and z fields with: foobar_x, foobar_y,foobar_z. 
  1880.  
  1881. Type: string
  1882.  
  1883. Represents a character string. 
  1884. Used to indicate file names, or messages to be broadcast to players. 
  1885. Valid syntax: "maps/jrwiz1.bsp" or "ouch!\n" 
  1886. Use \n for newline. 
  1887.  
  1888. Type: entity
  1889.  
  1890. The reference of an entity in the game, like things, players, monsters.
  1891. For instance, this is the type of the entities self and other. 
  1892.  
  1893. The entity type is a structured type, made of fields.
  1894. A description of each field is available. 
  1895.  
  1896.  
  1897.  
  1898. Field types
  1899.  
  1900. Countrary to the other types, the entity type is a reference to an instance of a structured object, that contains many informations of totally different kinds.
  1901.  
  1902. To access all these informations conveniently, they are stored as fields of the entity object, and each field is given a name and a type, that makes it distinct of the others.
  1903.  
  1904. Some of the fields do not store value, but instead they store the function to be executed in certain conditions. They are called the methods that can be aplied to the object.
  1905.  
  1906. If Quake-C was an object oriented programming language, those method functions and would be distinguished from the other fields. And, above all, you would be able to create new object types, with their own fields.
  1907.  
  1908. As Quake-C stands currently, all the field definitions are definitions of entity fields. So anywhere in your code you could add definition of new fields, and the compiler would interpret them as an extension of the entity definition.
  1909.  
  1910. Here are all the possible definitions of entity fields, with their types: 
  1911.  
  1912.     .float field_name;
  1913.     .string field_name;
  1914.     .vector field_name;
  1915.     .entity field_name;
  1916.  
  1917. Reserved field types (beware of the hack!)
  1918.  
  1919. In the first file read by the Quake-C compiler, defs.qc, there must be a definition for the entity fields, and world fields. This definition is hard coded. You had better not touch it, or you will have to recompile Quake itself. 
  1920.  
  1921. The globals are defined before the special definition void end_sys_globals; The entity fields are defined before the special definition void end_sys_fields;
  1922.  
  1923. It's not important if you don't understand the nonsense above. It's an ugly hack. Just don't modify defs.qc before those
  1924. two tags, and you won't be in trouble.
  1925.  
  1926.  
  1927.  
  1928. 11.     Compilation of Quake-C
  1929. ________________________________________________________________________________
  1930.  
  1931. The language is strongly typed and there are no casts.
  1932.  
  1933. Source files are processed sequentially without dumping any state, so if a defs file is the first one processed, the definitions will be available to all other files.
  1934.  
  1935. Error recovery during compilation is minimal. It will skip to the next global definition, so you will never see more than one error at a time in a given function. All compilation aborts after ten error messages.
  1936.  
  1937. Names can be defined multiple times until they are defined with an initialization, allowing functions to be prototyped before their definition. 
  1938.  
  1939.     // in headers
  1940.     void()      MyFunction;             // the prototype
  1941.     // later
  1942.     void()      MyFunction =            // the initialization
  1943.     { dprint ("we're here\n"); };
  1944.  
  1945. Beware of the Quake-C compiler
  1946.  
  1947.  
  1948.  
  1949.  
  1950. 12.     Execution of Quake-C
  1951. ________________________________________________________________________________
  1952.  
  1953. Code execution is initiated by C code in quake from two main places: the timed think routines for periodic control, and the touch function when two objects impact each other. 
  1954.  
  1955. Execution is also caused by a few uncommon events, like the addition of a new client to an existing server. 
  1956.  
  1957. There is a runnaway counter that stops a program if 100000 statements are executed, assuming it is in an infinite loop. 
  1958.  
  1959. It is acceptable to change the system set global variables. This is usually done to pose as another entity by changing self and calling a function. 
  1960.  
  1961. The interpretation is fairly efficient, but it is still over an order of magnitude slower than compiled C code. All time consuming operations should be made into built in functions. 
  1962.  
  1963. A profile counter is kept for each function, and incremented for each interpreted instruction inside that function. The "profile" console command in Quake will dump out the top 10 functions, then clear all the counters. The "profile all" command will dump sorted stats for every function that has been executed. 
  1964.  
  1965.  
  1966. 13. Examples
  1967. ________________________________________________________________________________
  1968.         
  1969.         These are examples taken from the QuakeC patch archives. Two of them are made by me. 
  1970.  
  1971. 13.1 Looping between all monster
  1972.  
  1973. float() Pet_FindTarget =
  1974. {
  1975.     local entity    client;
  1976.     local float    r;
  1977.         local entity head, selected;
  1978.     local float dist;
  1979.  
  1980.  
  1981.  
  1982.         dist = 10000;
  1983.     selected = world;
  1984.     head = findradius(self.origin, 10000);
  1985.     while(head)
  1986.     {
  1987.         if( (head.health > 1) && (head != self) && (head != self.owner))
  1988.         {
  1989.             traceline(self.origin,head.origin,TRUE,self);
  1990.             if ( (trace_fraction >= 1) && (vlen(head.origin - self.origin) < dist) && (head.owner != self.owner))
  1991.             {
  1992.                 selected = head;
  1993.                 dist = vlen(head.origin - self.origin);
  1994.             }
  1995.         }
  1996.         head = head.chain;
  1997.     }
  1998.     if (selected != world)
  1999.     {
  2000.         sprint (self.owner,"Pet attacking -> ");
  2001.         if (selected.classname == "player")
  2002.         {
  2003.             sprint (self.owner,selected.netname);
  2004.             sprint (selected,self.owner.netname);
  2005.             sprint (selected," sent one of his minions after you!\n");
  2006.         }
  2007.         else
  2008.             sprint (self.owner,selected.classname);
  2009.         sprint (self.owner,"\n");
  2010.                 self.enemy = selected;
  2011.                 FoundTarget ();
  2012.  
  2013.                 return TRUE;
  2014.     }
  2015.  
  2016.  
  2017.     if (self.goalentity != self.owner)
  2018.     {
  2019.         self.goalentity = self.owner;
  2020.         self.think = self.th_run;
  2021.     }
  2022.     self.ideal_yaw = vectoyaw(self.owner.origin - self.origin);
  2023.     self.nextthink = time+0.1;
  2024.     return FALSE;
  2025. };
  2026.  
  2027. 13.2 Creating a new entities
  2028.  
  2029. void(entity myself) ActivateHolo =
  2030. {
  2031.     local entity    newholo;
  2032.  
  2033.     newholo = spawn();
  2034.     newholo.solid = SOLID_NOT;
  2035.     newholo.movetype = MOVETYPE_NOCLIP;
  2036.     newholo.origin = myself.origin;
  2037.     newholo.angles = myself.angles;
  2038.     newholo.colormap = myself.colormap;
  2039.     setmodel (newholo, "progs/player.mdl");
  2040.     newholo.classname = "holo";
  2041.     newholo.owner=myself;
  2042.     newholo.frame=13;
  2043.     newholo.nextthink = time + 8;    
  2044.     newholo.think = RemoveHolo;
  2045.     myself.currentammo = myself.ammo_cells = myself.ammo_cells - 10;
  2046.     myself.items = myself.items | IT_HOLO;
  2047.     stuffcmd (newholo.owner, "bf\n");
  2048.     sprint(newholo.owner,"holograph activated\n");
  2049. };
  2050.  
  2051. 13.3 Setting point of view
  2052.  
  2053. void(entity me, entity camera) NezuSetViewPoint =
  2054. {
  2055.   // Set view point
  2056.   msg_entity = me;                         // target of message
  2057.   WriteByte (MSG_ONE, SVC_SETVIEWPORT);    // 5 = SVC_SETVIEWPORT;  
  2058.   WriteEntity (MSG_ONE, camera);           // view port
  2059.   // Also set angles, otherwise it feels strange
  2060.   // NezuSetViewAngle(me, camera.angles);
  2061.   WriteByte (MSG_ONE, SVC_SETVIEWANGLES);  // 10 = SVC_SETVIEWANGLES
  2062.   WriteAngle(MSG_ONE, camera.angles_x);    // tilt 
  2063.   WriteAngle(MSG_ONE, camera.angles_y);    // yaw
  2064.   WriteAngle(MSG_ONE, camera.angles_z);    // flip
  2065. };
  2066.  
  2067. 13.4 Teleporting
  2068.  
  2069. void() Teleport_to_bomb =
  2070. {
  2071.     local entity oldself,bdest;
  2072.  
  2073.     bdest=spawn();
  2074.     bdest.origin = self.telebomb.origin + '0 0 27';
  2075.  
  2076.     // Blow up the bomb...
  2077.     oldself=self;
  2078.     self=self.telebomb;
  2079.     GrenadeExplode();
  2080.     self=oldself;
  2081.  
  2082.  
  2083.     // Teleport to the bomb's old location
  2084.  
  2085.     if(self.health <= 0)  {
  2086.         remove(bdest);
  2087.         return;
  2088.     }
  2089.  
  2090.     // Recreating the "teleport_touch" function here, once again
  2091.  
  2092.     spawn_tfog (bdest.origin);
  2093.  
  2094.     spawn_tfog (bdest.origin);
  2095.     spawn_tdeath (bdest.origin,self);
  2096.  
  2097.     setorigin (self,bdest.origin);
  2098.     
  2099.     self.teleport_time = time + 1;  // Longer teleport recovery time
  2100.     self.flags = self.flags - self.flags & FL_ONGROUND;
  2101.  
  2102.     remove(bdest);
  2103. };
  2104.  
  2105. 13.5 Throwing your eyes
  2106.  
  2107.         if (self.impulse == 254)
  2108.         {
  2109.                 local vector v;
  2110.                 
  2111.                 eyes = spawn();  
  2112.                 setmodel (eyes,"progs/eyes.mdl");
  2113.                 eyes.movetype = MOVETYPE_BOUNCE;
  2114.                 eyes.solid = SOLID_BBOX;
  2115.                 eyes.effects = eyes.effects | EF_DIMLIGHT;
  2116.                 msg_entity = self;                         
  2117.                                            
  2118.                 WriteByte (MSG_ONE, SVC_SETVIEWPORT);    
  2119.                 WriteEntity (MSG_ONE, eyes);           
  2120.                 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);  
  2121.                 WriteAngle(MSG_ONE, self.angles_x);    
  2122.                 WriteAngle(MSG_ONE, self.angles_y);    
  2123.                 WriteAngle(MSG_ONE, self.angles_z);    
  2124.                 
  2125.                 makevectors (self.v_angle);
  2126.  
  2127.                 if (self.v_angle_x)
  2128.                     eyes.velocity = v_forward*600 + v_up * 200 + crandom()*v_right*10 + crandom()*v_up*10;
  2129.                 else
  2130.                 {             
  2131.                     eyes.velocity = aim(self, 10000);
  2132.                         eyes.velocity = eyes.velocity * 600;
  2133.                         eyes.velocity_z = 200;
  2134.                 }
  2135.  
  2136.                 eyes.avelocity = '300 300 300';
  2137.  
  2138.                 eyes.angles = vectoangles(eyes.velocity);
  2139.     
  2140.                 setsize (eyes, '-3 -3 -3', '3 3 3');       
  2141.                 setorigin (eyes, self.origin);
  2142.     
  2143.         }
  2144.         if (self.impulse == 253)
  2145.         {
  2146.                 local vector v;
  2147.  
  2148.                 msg_entity = self;                         
  2149.                 WriteByte (MSG_ONE, SVC_SETVIEWPORT);    
  2150.                 WriteEntity (MSG_ONE, self);           
  2151.                 WriteByte (MSG_ONE, SVC_SETVIEWANGLES);  
  2152.                 v = vectoangles(eyes.origin - self.origin);
  2153.                 WriteAngle(MSG_ONE, v_x);    
  2154.                 WriteAngle(MSG_ONE, v_y);    
  2155.                 WriteAngle(MSG_ONE, v_z);
  2156.                 remove(eyes);
  2157.         }
  2158.  
  2159. 13.6 Radar
  2160.  
  2161.         if (cvar("temp1")==1)
  2162.         {
  2163.                 local entity head,selected;
  2164.                 local float min,dist;
  2165.  
  2166.                 if (radar_time==0) radar_time=time;
  2167.                 if (time>=radar_time) 
  2168.                 {
  2169.                         min=2000;
  2170.                         head = findradius(self.origin,1000);
  2171.                         selected = world;
  2172.                         
  2173.                         while (head)
  2174.                         {
  2175.                                 dist = vlen(self.origin - head.origin);
  2176.                                 if( (head.health > 1) && (head != self) && (head != self.owner) && (dist<min) )
  2177.                                 {          
  2178.                                         min=dist;
  2179.                                         selected=head;
  2180.                                 }
  2181.                                 head = head.chain;
  2182.                         }
  2183.                         sound (selected, CHAN_AUTO, "radar.wav", 1, ATTN_NORM);
  2184.                         radar_time = min / 600;
  2185.                         radar_time = radar_time + time;
  2186.                 }
  2187.         }
  2188.  
  2189. ________________________________________________________________________________
  2190.  
  2191.