]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/minigames.qc
Fix FL_WEAPON flag overlapping FL_JUMPRELEASED. This unintentional change was introdu...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigames.qc
index a8daa44849b361676a6c36e1bd9bafcf16dc1bfe..0455e80867eb596cb12e83120a431b80708b505c 100644 (file)
@@ -1,12 +1,11 @@
 #include "minigames.qh"
 
+REGISTER_NET_LINKED(ENT_CLIENT_MINIGAME)
+
 entity minigame_get_descriptor(string id)
 {
-       entity e;
-       for ( e = minigame_descriptors; e != world; e = e.list_next )
-               if ( e.netname == id )
-                       return e;
-       return world;
+       FOREACH(Minigames, it.netname == id, return it);
+       return NULL;
 }
 
 // Get letter index of a tile name
@@ -17,7 +16,7 @@ int minigame_tile_letter(string id)
 
 // Get number index of a tile name
 // Note: this is 0 based, useful for mathematical operations
-// Note: Since the tile notation starts from the bottom left, 
+// Note: Since the tile notation starts from the bottom left,
 //     you may want to do number_of_rows - what_this_function_returns or something
 int minigame_tile_number(string id)
 {
@@ -27,8 +26,8 @@ int minigame_tile_number(string id)
 // Get relative position of the center of a given tile
 vector minigame_tile_pos(string id, int rows, int columns)
 {
-       return eX*(minigame_tile_letter(id)+0.5)/columns + 
-              eY - eY*(minigame_tile_number(id)+0.5)/rows;
+       return vec2((minigame_tile_letter(id) + 0.5) / columns,
+               (1 - (minigame_tile_number(id) + 0.5) / rows));
 }
 
 // Get a tile name from indices
@@ -56,7 +55,7 @@ string minigame_tile_name(vector pos, int rows, int columns)
 {
        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);
        return minigame_tile_buildname(letter, number);
@@ -68,6 +67,12 @@ int minigame_next_team(int curr_team, int n_teams)
        return curr_team % n_teams + 1;
 }
 
+// Get the previous team number
+int minigame_prev_team(int curr_team, int n_teams)
+{
+       return curr_team % n_teams - 1;
+}
+
 // set send flags only when on server
 // (for example in game logic which can be used both in client and server
 void minigame_server_sendflags(entity ent, int mgflags)
@@ -79,14 +84,12 @@ void minigame_server_sendflags(entity ent, int mgflags)
 
 // Spawn linked entity on the server or local entity on the client
 // This entity will be removed automatically when the minigame ends
-entity msle_spawn(entity minigame_session, string class_name)
+entity msle_spawn(entity minigame_session, entity e)
 {
-       entity e = spawn();
-       e.classname = class_name;
        e.owner = minigame_session;
        e.minigame_autoclean = 1;
        #ifdef SVQC
-               e.customizeentityforclient = minigame_CheckSend;
+               setcefc(e, minigame_CheckSend);
                Net_LinkEntity(e, false, 0, minigame_SendEntity);
        #endif
        return e;
@@ -122,10 +125,17 @@ int minigame_count_players(entity minigame)
 #ifdef SVQC
        for(e = minigame.minigame_players; e; e = e.list_next)
 #elif defined(CSQC)
-       e = world;
+       e = NULL;
        while( (e = findentity(e,owner,minigame)) )
                if ( e.classname == "minigame_player" )
 #endif
                pl_num++;
        return pl_num;
-}
\ No newline at end of file
+}
+
+#ifdef CSQC
+#include "cl_minigames.qc"
+#endif
+#ifdef SVQC
+#include "sv_minigames.qc"
+#endif