1 #include "minigames.qh"
3 REGISTER_NET_LINKED(ENT_CLIENT_MINIGAME)
5 entity minigame_get_descriptor(string id)
7 FOREACH(Minigames, it.netname == id, return it);
11 // Get letter index of a tile name
12 int minigame_tile_letter(string id)
14 return str2chr(substring(id,0,1),0)-'a';
17 // Get number index of a tile name
18 // Note: this is 0 based, useful for mathematical operations
19 // Note: Since the tile notation starts from the bottom left,
20 // you may want to do number_of_rows - what_this_function_returns or something
21 int minigame_tile_number(string id)
23 return stof(substring(id,1,-1)) -1 ;
26 // Get relative position of the center of a given tile
27 vector minigame_tile_pos(string id, int rows, int columns)
29 return vec2((minigame_tile_letter(id) + 0.5) / columns,
30 (1 - (minigame_tile_number(id) + 0.5) / rows));
33 // Get a tile name from indices
34 string minigame_tile_buildname(int letter, int number)
36 return strcat(chr2str('a'+letter),ftos(number+1));
39 // Get the id of a tile relative to the given one
40 string minigame_relative_tile(string start_id, int dx, int dy, int rows, int columns)
42 int letter = minigame_tile_letter(start_id);
43 int number = minigame_tile_number(start_id);
44 letter = (letter+dx) % columns;
45 number = (number+dy) % rows;
47 letter = columns + letter;
49 number = rows + number;
50 return minigame_tile_buildname(letter, number);
53 // Get tile name from a relative position (matches the tile covering a square area)
54 string minigame_tile_name(vector pos, int rows, int columns)
56 if ( pos_x < 0 || pos_x > 1 || pos_y < 0 || pos_y > 1 )
59 int letter = floor(pos_x * columns);
60 int number = floor((1-pos_y) * rows);
61 return minigame_tile_buildname(letter, number);
64 // Get the next team number (note: team numbers are between 1 and n_teams, inclusive)
65 int minigame_next_team(int curr_team, int n_teams)
67 return curr_team % n_teams + 1;
70 // Get the previous team number
71 int minigame_prev_team(int curr_team, int n_teams)
73 return curr_team % n_teams - 1;
76 // set send flags only when on server
77 // (for example in game logic which can be used both in client and server
78 void minigame_server_sendflags(entity ent, int mgflags)
81 ent.SendFlags |= mgflags;
85 // Spawn linked entity on the server or local entity on the client
86 // This entity will be removed automatically when the minigame ends
87 entity msle_spawn(entity minigame_session, string class_name)
90 e.classname = class_name;
91 e.owner = minigame_session;
92 e.minigame_autoclean = 1;
94 setcefc(e, minigame_CheckSend);
95 Net_LinkEntity(e, false, 0, minigame_SendEntity);
100 const int msle_base_id = 2;
101 int msle_id(string class_name)
103 if ( class_name == "minigame" ) return 1;
104 if ( class_name == "minigame_player" ) return 2;
105 int i = msle_base_id;
106 #define MSLE(Name, Fields) i++; if ( class_name == #Name ) return i;
107 MINIGAME_SIMPLELINKED_ENTITIES
112 string msle_classname(int id)
114 if ( id == 1 ) return "minigame";
115 if ( id == 2 ) return "minigame_player";
116 int i = msle_base_id;
117 #define MSLE(Name, Fields) i++; if ( id == i ) return #Name;
118 MINIGAME_SIMPLELINKED_ENTITIES
123 int minigame_count_players(entity minigame)
128 for(e = minigame.minigame_players; e; e = e.list_next)
131 while( (e = findentity(e,owner,minigame)) )
132 if ( e.classname == "minigame_player" )
139 #include "cl_minigames.qc"
142 #include "sv_minigames.qc"