X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=Introduction-to-QuakeC.md;h=414679b8da9c335580082ccd01346684510f285d;hb=0923c4ff6fea7af8276d0e04bf753c8e49d669a4;hp=27cc21bfc1a166d3a342883d34c98cc078769a00;hpb=3226f2beca23a865b4312d13241b381d2f489038;p=xonotic%2Fxonotic.wiki.git
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