From 105d75a4b5e92e929c12c7fde1a4398a51024b16 Mon Sep 17 00:00:00 2001 From: LegendaryGuard Date: Mon, 29 Mar 2021 22:37:07 +0000 Subject: [PATCH] Added bound function and Ternary operator --- Introduction-to-QuakeC.md | 41 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Introduction-to-QuakeC.md b/Introduction-to-QuakeC.md index 27cc21b..414679b 100644 --- a/Introduction-to-QuakeC.md +++ b/Introduction-to-QuakeC.md @@ -671,6 +671,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 +794,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 -- 2.39.2