]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/minigames.qc
take3: format 903 files
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigames.qc
index 6d14b258281f973a916b346ca9540776d75f7549..dea1c59fce8506225e8d0870e147d3d4b2f1eaed 100644 (file)
@@ -11,7 +11,7 @@ entity minigame_get_descriptor(string id)
 // Get letter index of a tile name
 int minigame_tile_letter(string id)
 {
-       return str2chr(substring(id,0,1),0)-'a';
+       return str2chr(substring(id, 0, 1), 0) - 'a';
 }
 
 // Get number index of a tile name
@@ -20,7 +20,7 @@ int minigame_tile_letter(string id)
 //     you may want to do number_of_rows - what_this_function_returns or something
 int minigame_tile_number(string id)
 {
-       return stof(substring(id,1,-1)) -1 ;
+       return stof(substring(id, 1, -1)) - 1;
 }
 
 // Get relative position of the center of a given tile
@@ -33,7 +33,7 @@ vector minigame_tile_pos(string id, int rows, int columns)
 // Get a tile name from indices
 string minigame_tile_buildname(int letter, int number)
 {
-       return strcat(chr2str('a'+letter),ftos(number+1));
+       return strcat(chr2str('a' + letter), ftos(number + 1));
 }
 
 // Get the id of a tile relative to the given one
@@ -41,23 +41,25 @@ string minigame_relative_tile(string start_id, int dx, int dy, int rows, int col
 {
        int letter = minigame_tile_letter(start_id);
        int number = minigame_tile_number(start_id);
-       letter = (letter+dx) % columns;
-       number = (number+dy) % rows;
-       if ( letter < 0 )
+       letter = (letter + dx) % columns;
+       number = (number + dy) % rows;
+       if (letter < 0) {
                letter = columns + letter;
-       if ( number < 0 )
+       }
+       if (number < 0) {
                number = rows + number;
+       }
        return minigame_tile_buildname(letter, number);
 }
 
 // Get tile name from a relative position (matches the tile covering a square area)
 string minigame_tile_name(vector pos, int rows, int columns)
 {
-       if ( pos_x < 0 || pos_x > 1 || pos_y < 0 || pos_y > 1 )
+       if (pos_x < 0 || pos_x > 1 || pos_y < 0 || pos_y > 1) {
                return ""; // no tile
-
+       }
        int letter = floor(pos_x * columns);
-       int number = floor((1-pos_y) * rows);
+       int number = floor((1 - pos_y) * rows);
        return minigame_tile_buildname(letter, number);
 }
 
@@ -77,9 +79,9 @@ int minigame_prev_team(int curr_team, int n_teams)
 // (for example in game logic which can be used both in client and server
 void minigame_server_sendflags(entity ent, int mgflags)
 {
-       #ifdef SVQC
-               ent.SendFlags |= mgflags;
-       #endif
+#ifdef SVQC
+       ent.SendFlags |= mgflags;
+#endif
 }
 
 // Spawn linked entity on the server or local entity on the client
@@ -90,20 +92,20 @@ entity msle_spawn(entity minigame_session, string class_name)
        e.classname = class_name;
        e.owner = minigame_session;
        e.minigame_autoclean = 1;
-       #ifdef SVQC
-               setcefc(e, minigame_CheckSend);
-               Net_LinkEntity(e, false, 0, minigame_SendEntity);
-       #endif
+#ifdef SVQC
+       setcefc(e, minigame_CheckSend);
+       Net_LinkEntity(e, false, 0, minigame_SendEntity);
+#endif
        return e;
 }
 
 const int msle_base_id = 2;
 int msle_id(string class_name)
 {
-       if ( class_name == "minigame" ) return 1;
-       if ( class_name == "minigame_player" ) return 2;
+       if (class_name == "minigame") { return 1; }
+       if (class_name == "minigame_player") { return 2; }
        int i = msle_base_id;
-#define MSLE(Name, Fields) i++; if ( class_name == #Name ) return i;
+#define MSLE(Name, Fields) i++; if (class_name == #Name) { return i; }
        MINIGAME_SIMPLELINKED_ENTITIES
 #undef MSLE
        return 0;
@@ -111,10 +113,10 @@ int msle_id(string class_name)
 
 string msle_classname(int id)
 {
-       if ( id == 1 ) return "minigame";
-       if ( id == 2 ) return "minigame_player";
+       if (id == 1) { return "minigame"; }
+       if (id == 2) { return "minigame_player"; }
        int i = msle_base_id;
-#define MSLE(Name, Fields) i++; if ( id == i ) return #Name;
+#define MSLE(Name, Fields) i++; if (id == i) { return #Name; }
        MINIGAME_SIMPLELINKED_ENTITIES
 #undef MSLE
        return "";
@@ -125,13 +127,14 @@ int minigame_count_players(entity minigame)
        int pl_num = 0;
        entity e;
 #ifdef SVQC
-       for(e = minigame.minigame_players; e; e = e.list_next)
+       for (e = minigame.minigame_players; e; e = e.list_next)
 #elif defined(CSQC)
        e = NULL;
-       while( (e = findentity(e,owner,minigame)) )
-               if ( e.classname == "minigame_player" )
+       while ((e = findentity(e, owner, minigame)))
+               if (e.classname == "minigame_player")
 #endif
-               pl_num++;
+       { pl_num++;
+       }
        return pl_num;
 }