X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=Introduction-to-QuakeC.md;h=3c17852f2a158154630e027448463a96b6959cb3;hb=968f2c9267ec9c6d18646ade0fa1d66e90a751e8;hp=27cc21bfc1a166d3a342883d34c98cc078769a00;hpb=3226f2beca23a865b4312d13241b381d2f489038;p=xonotic%2Fxonotic.wiki.git diff --git a/Introduction-to-QuakeC.md b/Introduction-to-QuakeC.md index 27cc21b..3c17852 100644 --- a/Introduction-to-QuakeC.md +++ b/Introduction-to-QuakeC.md @@ -126,8 +126,6 @@ vector This type is basically three floats together. By declaring a `vector v`, you also create three floats `v_x`, `v_y` and `v_z` (note the underscore) that contain the components of the vector. GMQCC also accepts dot notation to access these components: `v.x`, `v.y` and `v.z` -**COMPILER BUG:** Always use `entity.vector_x = float` instead of `entity.vector.x = float`, as the latter creates incorrect code! Reading from vectors is fine, however. - Vectors can be used with the usual mathematical operators in the usual way used in mathematics. For example, `vector + vector` simply returns the sum of the vectors, and `vector * float` scales the vector by the given factor. Multiplying two vectors yields their dot product of type float. Common functions to be used on vectors are `vlen` (vector length), `normalize` (vector divided by its length, i.e. a unit vector). @@ -671,6 +669,45 @@ vectoangles does not match makevectors The pitch angle is inverted between these two functions. You have to negate the pitch (i.e. the *x* component of the vector representing the euler angles) to make it fit the other function. As a rule of thumb, *vectoangles* returns angles as stored in the *angles* field (used to rotate entities for display), while *makevectors* expects angles as stored in the *v\_angle* field (used to transmit the direction the player is aiming). There is about just as much good reason in this as there is for 1:1 patch cables. Just deal with it. +bound +----- + +A bound is a variable that was previously free, but has been bound to a specific value or set of values. If x > upperlimit the upperlimit is returned, if x < lowerlimit then lowerlimit is returned, if lowerlimit < x < upperlimit then x is returned. That function returns an x value calling this way: +```c +bound(lower_limit, x, upper_limit) +``` + +Ternary operator +---------------- + +QuakeC allows ternary operators like in C: +```c +int a = 2; +int b = 3; +int c = 6; +int d = 8; +int max = (a > b) ? c : d; +``` +More [**info**](https://www.geeksforgeeks.org/conditional-or-ternary-operator-in-c-c/). + +There is a complex example using `bound` function with this operator: +```c +bound(1, ((hunter_count >= 1) ? hunter_count : floor(total * hunter_count)), total - 1); +bool wholenumber = (hunter_count >= 1) //is hunter count a specified whole number or percentage + +if (!wholenumber) //if hunters are defined with percentage count +{ + int z = total * hunter_count //wanted percentage amount from total is z + int y = floor(z) //round z downwards to nearest whole number +} + +int x = (wholenumber ? hunter_count : y) //if whole number was given use it, +//if not use y which is calculated above +bound(1, x, total - 1) //use the value x if it's above 1 but below (total - 1) +//Otherwise use the bounding value of that direction to quarantee that +//there is always at least 1 hunter and always at least 1 survivor +``` + Entry points ============ @@ -755,4 +792,4 @@ The server-side code calls the following entry points of the QuakeC code:
- **void SV\_ParseClientCommand(string command)**: handles commands sent by the client to the server using “cmd ...”. Unhandled commands can be passed to the built-in function *clientcommand* to execute the normal engine behaviour. -
+
\ No newline at end of file