]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/minigames/minigames.qc
remove more unused fields
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigames.qc
index 46f0a9c574bd5fbbc643987e18784cc40eb1d616..227f3d9c63e42813798ecaf699a43ccebd55f5b1 100644 (file)
@@ -1,47 +1,46 @@
 #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
-float minigame_tile_letter(string id)
+int minigame_tile_letter(string id)
 {
        return str2chr(substring(id,0,1),0)-'a';
 }
 
 // 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
-float minigame_tile_number(string id)
+int minigame_tile_number(string id)
 {
        return stof(substring(id,1,-1)) -1 ;
 }
 
 // Get relative position of the center of a given tile
-vector minigame_tile_pos(string id, float rows, float columns)
+vector minigame_tile_pos(string id, int rows, int columns)
 {
-       return eX*(minigame_tile_letter(id)+0.5)/columns + 
+       return eX*(minigame_tile_letter(id)+0.5)/columns +
               eY - eY*(minigame_tile_number(id)+0.5)/rows;
 }
 
 // Get a tile name from indices
-string minigame_tile_buildname(float letter, float number)
+string minigame_tile_buildname(int letter, int number)
 {
        return strcat(chr2str('a'+letter),ftos(number+1));
 }
 
 // Get the id of a tile relative to the given one
-string minigame_relative_tile(string start_id, float dx, float dy, float rows, float columns)
+string minigame_relative_tile(string start_id, int dx, int dy, int rows, int columns)
 {
-       float letter = minigame_tile_letter(start_id);
-       float number = minigame_tile_number(start_id);
+       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 )
@@ -52,25 +51,31 @@ string minigame_relative_tile(string start_id, float dx, float dy, float rows, f
 }
 
 // Get tile name from a relative position (matches the tile covering a square area)
-string minigame_tile_name(vector pos, float rows, float columns)
+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
-               
-       float letter = floor(pos_x * columns);
-       float number = floor((1-pos_y) * rows);
+
+       int letter = floor(pos_x * columns);
+       int number = floor((1-pos_y) * rows);
        return minigame_tile_buildname(letter, number);
 }
 
 // Get the next team number (note: team numbers are between 1 and n_teams, inclusive)
-float minigame_next_team(float curr_team, float n_teams)
+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, float mgflags)
+void minigame_server_sendflags(entity ent, int mgflags)
 {
        #ifdef SVQC
                ent.SendFlags |= mgflags;
@@ -86,46 +91,53 @@ entity msle_spawn(entity minigame_session, string 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;
 }
 
-const float msle_base_id = 2;
-float msle_id(string class_name)
+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;
-       float i = msle_base_id;
+       int i = msle_base_id;
 #define MSLE(Name, Fields) i++; if ( class_name == #Name ) return i;
        MINIGAME_SIMPLELINKED_ENTITIES
 #undef MSLE
        return 0;
 }
 
-string msle_classname(float id)
+string msle_classname(int id)
 {
        if ( id == 1 ) return "minigame";
        if ( id == 2 ) return "minigame_player";
-       float i = msle_base_id;
+       int i = msle_base_id;
 #define MSLE(Name, Fields) i++; if ( id == i ) return #Name;
        MINIGAME_SIMPLELINKED_ENTITIES
 #undef MSLE
        return "";
 }
 
-float minigame_count_players(entity minigame)
+int minigame_count_players(entity minigame)
 {
-       float pl_num = 0;
+       int pl_num = 0;
        entity e;
 #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