Hosting and domain costs until October 2024 have been generously sponsored by dumptruck_ds. Thank you!
Editing QuakeC Globals
From Quake Wiki
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | Globals are variables that aren't entity specific and can be accessed from anywhere at any time. Much like fields, they're broken down into system globals and QuakeC globals. Valid global data types include <code>string</code>, <code>vector</code>, <code>float</code>, and <code>entity</code>. Globals are declared via: | + | Globals are variables that aren't entity specific and can be accessed from anywhere at any time. Much like fields, they're broken down into system globals and QuakeC globals. Valid global data types include <code>string</code>, <code>vector</code>, <code>float</code>, and <code>entity</code>. Function pointers are also allowed by specifying the return type and any parameters that need to be passed to it. The return type should be void if it doesn't return anything. Globals are declared via: |
datatype globalName; | datatype globalName; | ||
+ | returntype(datatype param1) globalFunction; | ||
+ | Global functions are less useful but have a possible usage with setting up world data processing. When setting a function pointer, only the name of the function is needed e.g. <code>globalFunction = MyFunction;</code>. It can then be called like any other function by invoking the pointer. | ||
− | System globals are globals defined within the engine itself and must be present for the game to work. These are always defined before anything else. The end of them is denoted by the <code> | + | System globals are globals defined within the engine itself and must be present for the game to work. These are always defined before anything else. The end of them is denoted by the void <code>end_sys_globals;</code> declaration. System globals must always be declared in the order defined within the vanilla QuakeC files as they are linked by memory offsets internally. Changing the order will break logic. |
− | QuakeC globals are standard globals that have no internal linkage and can be defined freely anywhere. | + | QuakeC globals are standard globals that have no internal linkage and can be defined freely anywhere. Note that these are not stored between maps and will be reset upon changing levels. |
− | |||
− | Note that these are not stored between maps and will be reset upon changing levels. | ||
== System Globals == | == System Globals == | ||
The following globals should be defined in the exact order of this list, otherwise memory offset errors can occur. | The following globals should be defined in the exact order of this list, otherwise memory offset errors can occur. | ||
− | *''entity'' '''self''' | + | *''entity'' '''self''' - The entity that the physics frame is currently processing. |
− | + | *''entity'' '''other''' - If a collision is occurring, this is the entity '''self''' is colliding with. This should only be used from <code>touch()</code> functions. | |
− | *''entity'' '''other''' | + | *''entity'' '''world''' - The default world entity. This entity's fields cannot be written to directly and it is considered null in conditional checks. |
− | + | *''float'' '''time''' - The current game time in seconds. | |
− | *''entity'' '''world''' | + | *''float'' '''frametime''' - The difference between the previous physics frame and the current one in seconds. |
− | + | *''float'' '''force_retouch''' - If greater than 0, relinks all entities into the world. Useful for getting entities to touch newly created triggers. This should be set to 2 to properly reset everything since setting it to 1 will only relink entities starting from the current '''self''' onward. | |
− | *''float'' '''time''' | + | *''string'' '''mapname''' - The name of the current map e.g. start, e2m1, etc. |
− | + | *''float'' '''deathmatch''' - If non-zero, PvP is enabled. If set to 2, uses the classic deathmatch rules. | |
− | *''float'' '''frametime''' | + | *''float'' '''coop''' - If non-zero, co-op is enabled. |
− | + | *''float'' '''teamplay''' - If non-zero while PvP is active, team PvP is enabled. If set to 1, friendly fire is disabled. | |
− | *''float'' '''force_retouch''' | + | *''float'' '''serverflags''' - Tracks the state of the game across the entire session. This doesn't get reset between level changes. The first 4 bits are reserved for the runes with each bit corresponding to its respective episode e.g. episode 1 is the first bit. If this is non-zero when going back to the start map, the player's inventory will be cleared. |
− | + | *''float'' '''total_secrets''' - The total secret count for the current map. | |
− | *''string'' '''mapname''' | + | *''float'' '''total_monsters''' - The total monster count for the current map. |
− | + | *''float'' '''found_secrets''' - How many secrets have been found in the current map. | |
− | *''float'' '''deathmatch''' | + | *''float'' '''killed_monsters''' - How many monsters have been killed in the current map. |
− | |||
− | *''float'' '''coop''' | ||
− | |||
− | *''float'' '''teamplay''' | ||
− | |||
− | *''float'' '''serverflags''' | ||
− | |||
− | *''float'' '''total_secrets''' | ||
− | |||
− | *''float'' '''total_monsters''' | ||
− | |||
− | *''float'' '''found_secrets''' | ||
− | |||
− | *''float'' '''killed_monsters''' | ||
− | |||
Parms store information about each player when moving between levels. Players have their own set of parms, but the globals act as an interface for setting them. These can be changed to however the modder wants to encode information, but below is how they're handled by default. | Parms store information about each player when moving between levels. Players have their own set of parms, but the globals act as an interface for setting them. These can be changed to however the modder wants to encode information, but below is how they're handled by default. | ||
− | *''float'' '''parm1''' | + | *''float'' '''parm1''' - Stores the player's '''items''' field minus any keys and power ups. |
− | + | *''float'' '''parm2''' - Stores the player's health. This is capped between 50 and 100. | |
− | *''float'' '''parm2''' | + | *''float'' '''parm3''' - Stores the amount of armor the player has. |
− | + | *''float'' '''parm4''' - Stores the amount of shells the player has. This has a minimum amount of 25. | |
− | *''float'' '''parm3''' | + | *''float'' '''parm5''' - Stores the amount of nails the player has. |
− | + | *''float'' '''parm6''' - Stores the amount of rockets the player has. | |
− | *''float'' '''parm4''' | + | *''float'' '''parm7''' - Stores the amount of cells the player has. |
− | + | *''float'' '''parm8''' - Stores the player's '''weapon''' field. | |
− | *''float'' '''parm5''' | + | *''float'' '''parm9''' - Stores the player's armor damage reduction multiplied by 100 to give two decimal places of accuracy (decimal places beyond this get discarded). |
− | |||
− | *''float'' '''parm6''' | ||
− | |||
− | *''float'' '''parm7''' | ||
− | |||
− | *''float'' '''parm8''' | ||
− | |||
− | *''float'' '''parm9''' | ||
− | |||
*''float'' '''parm10''' | *''float'' '''parm10''' | ||
*''float'' '''parm11''' | *''float'' '''parm11''' | ||
Line 66: | Line 42: | ||
*''float'' '''parm15''' | *''float'' '''parm15''' | ||
*''float'' '''parm16''' | *''float'' '''parm16''' | ||
− | :Unused | + | :-Unused |
The following are used by <code>makevectors()</code> to store the local axes that the function generates from the passed angles. | The following are used by <code>makevectors()</code> to store the local axes that the function generates from the passed angles. | ||
− | *''vector'' '''v_forward''' | + | *''vector'' '''v_forward''' - The facing direction of the passed angles. |
− | + | *''vector'' '''v_up''' - The direction pointing directly up from the facing direction of the passed angles. | |
− | *''vector'' '''v_up''' | + | *''vector'' '''v_right''' - The direction pointing directly to the right of the facing direction of the passed angles. |
− | |||
− | *''vector'' '''v_right''' | ||
− | |||
The following are used by <code>traceline()</code> to pass information from the function to QuakeC. | The following are used by <code>traceline()</code> to pass information from the function to QuakeC. | ||
− | *''float'' '''trace_allsolid''' | + | *''float'' '''trace_allsolid''' - If <code>TRUE</code>, the trace was stuck entirely in solids. |
− | + | *''float'' '''trace_startsolid''' - If <code>TRUE</code>, the trace started inside of a solid. | |
− | *''float'' '''trace_startsolid''' | + | *''float'' '''trace_fraction''' - The fraction of the total distance the trace traveled before stopping. Ranges from [0, 1]. |
− | + | *''vector'' '''trace_endpos''' - The position the trace stopped. | |
− | *''float'' '''trace_fraction''' | + | *''vector'' '''trace_plane_normal''' - The normal of the plane that the trace hit. |
− | + | *''float'' '''trace_plane_dist''' - The distance from the world origin of the plane that the trace hit. This is d in the plane equation ax + by + cz + d = 0. | |
− | *''vector'' '''trace_endpos''' | + | *''entity'' '''trace_ent''' - The entity that the trace hit. |
− | + | *''float'' '''trace_inopen''' - If <code>TRUE</code>, the trace traveled through open air. | |
− | *''vector'' '''trace_plane_normal''' | + | *''float'' '''trace_inwater''' - If <code>TRUE</code>, the trace traveled through a liquid. |
− | + | *''entity'' '''msg_entity''' - When sending a network message to a specific player via <code>MSG_ONE</code>, this is the player the message is sent to. | |
− | *''float'' '''trace_plane_dist''' | ||
− | |||
− | *''entity'' '''trace_ent''' | ||
− | |||
− | *''float'' '''trace_inopen''' | ||
− | |||
− | *''float'' '''trace_inwater''' | ||
− | |||
− | *''entity'' '''msg_entity''' | ||
− | |||
Below are a special set of global functions the engine calls. These have no internal definitions so the function body must be defined somewhere in QuakeC to work. As such, their functionality is entirely customizable. | Below are a special set of global functions the engine calls. These have no internal definitions so the function body must be defined somewhere in QuakeC to work. As such, their functionality is entirely customizable. | ||
− | *''void()'' '''main''' | + | *''void()'' '''main''' - Unused. |
− | + | *''void()'' '''StartFrame''' - Called at the start of every physics frame before anything else is processed. | |
− | *''void()'' '''StartFrame''' | + | *''void()'' '''PlayerPreThink''' - Called before the player's physics is ran. |
− | + | *''void()'' '''PlayerPostThink''' - Called after the player's physics is ran. | |
− | *''void()'' '''PlayerPreThink''' | + | *''void()'' '''ClientKill''' - Called when the player kills themselves via the console command. |
− | + | *''void()'' '''ClientConnect''' - Called when a player joins the game, either for the first time or from changing levels. | |
− | *''void()'' '''PlayerPostThink''' | + | *''void()'' '''PutClientInServer''' - Called when a player is set to spawn or respawn. |
− | + | *''void()'' '''ClientDisconnect''' - Called when a player leaves the game, either from disconnecting or changing levels. | |
− | *''void()'' '''ClientKill''' | + | *''void()'' '''SetNewParms''' - Sets the default parms for the player when they join the game for the first time or when respawning in deathmatch. |
− | + | *''void()'' '''SetChangeParms''' - Called when the player is about to change levels and their parms need to be set so they can be decoded when joining the new map. | |
− | *''void()'' '''ClientConnect''' | ||
− | |||
− | *''void()'' '''PutClientInServer''' | ||
− | |||
− | *''void()'' '''ClientDisconnect''' | ||
− | |||
− | *''void()'' '''SetNewParms''' | ||
− | |||
− | *''void()'' '''SetChangeParms''' | ||
− | |||
== QuakeC Globals == | == QuakeC Globals == | ||
Line 121: | Line 74: | ||
=== World Globals === | === World Globals === | ||
− | *''string'' '''string_null''' | + | *''string'' '''string_null''' - Null string. This differs from "" in that it's not considered a valid string in conditional checks while "" is. |
− | + | *''float'' '''skill''' - The current difficulty of the map. Can be one of the following: | |
− | *''float'' '''skill''' | + | :0 - Easy |
− | + | :1 - Normal | |
− | : | + | :2 - Hard |
− | : | + | :3 - Nightmare |
− | : | + | *''float'' '''framecount''' - The total number of physics frames the server has processed. |
− | : | + | *''float'' '''gameover''' - If <code>TRUE</code>, the server is changing levels and players should not be considered fully disconnected. |
− | *''float'' '''framecount''' | ||
− | |||
− | *''float'' '''gameover''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | === | + | === Entity Globals === |
− | + | *''entity'' '''activator''' - The entity that's considered the activator when calling <code>SUB_UseTargets()</code>. | |
− | + | *''entity'' '''damage_attacker''' - The source of the attack when an entity takes damage. | |
− | + | *''entity'' '''newmis''' - Set by <code>launch_spike()</code> to store the newly created projectile entity. | |
− | |||
− | *''entity'' '''activator''' | ||
− | |||
− | *''entity'' '''damage_attacker''' | ||
− | |||
− | *''entity'' '''newmis''' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Monster Entity Globals === | === Monster Entity Globals === | ||
− | *''float'' '''movedist''' | + | *''float'' '''movedist''' - When attempting to move, stores how far the current monster is trying to travel in map units. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− |