1 #include "minigames.qh"
3 entity minigame_get_descriptor(string id)
5 FOREACH(MINIGAMES, true, LAMBDA(
13 // Get letter index of a tile name
14 int minigame_tile_letter(string id)
16 return str2chr(substring(id,0,1),0)-'a';
19 // Get number index of a tile name
20 // Note: this is 0 based, useful for mathematical operations
21 // Note: Since the tile notation starts from the bottom left,
22 // you may want to do number_of_rows - what_this_function_returns or something
23 int minigame_tile_number(string id)
25 return stof(substring(id,1,-1)) -1 ;
28 // Get relative position of the center of a given tile
29 vector minigame_tile_pos(string id, int rows, int columns)
31 return eX*(minigame_tile_letter(id)+0.5)/columns +
32 eY - eY*(minigame_tile_number(id)+0.5)/rows;
35 // Get a tile name from indices
36 string minigame_tile_buildname(int letter, int number)
38 return strcat(chr2str('a'+letter),ftos(number+1));
41 // Get the id of a tile relative to the given one
42 string minigame_relative_tile(string start_id, int dx, int dy, int rows, int columns)
44 int letter = minigame_tile_letter(start_id);
45 int number = minigame_tile_number(start_id);
46 letter = (letter+dx) % columns;
47 number = (number+dy) % rows;
49 letter = columns + letter;
51 number = rows + number;
52 return minigame_tile_buildname(letter, number);
55 // Get tile name from a relative position (matches the tile covering a square area)
56 string minigame_tile_name(vector pos, int rows, int columns)
58 if ( pos_x < 0 || pos_x > 1 || pos_y < 0 || pos_y > 1 )
61 int letter = floor(pos_x * columns);
62 int number = floor((1-pos_y) * rows);
63 return minigame_tile_buildname(letter, number);
66 // Get the next team number (note: team numbers are between 1 and n_teams, inclusive)
67 int minigame_next_team(int curr_team, int n_teams)
69 return curr_team % n_teams + 1;
72 // Get the previous team number
73 int minigame_prev_team(int curr_team, int n_teams)
75 return curr_team % n_teams - 1;
78 // set send flags only when on server
79 // (for example in game logic which can be used both in client and server
80 void minigame_server_sendflags(entity ent, int mgflags)
83 ent.SendFlags |= mgflags;
87 // Spawn linked entity on the server or local entity on the client
88 // This entity will be removed automatically when the minigame ends
89 entity msle_spawn(entity minigame_session, string class_name)
92 e.classname = class_name;
93 e.owner = minigame_session;
94 e.minigame_autoclean = 1;
96 e.customizeentityforclient = minigame_CheckSend;
97 Net_LinkEntity(e, false, 0, minigame_SendEntity);
102 const int msle_base_id = 2;
103 int msle_id(string class_name)
105 if ( class_name == "minigame" ) return 1;
106 if ( class_name == "minigame_player" ) return 2;
107 int i = msle_base_id;
108 #define MSLE(Name, Fields) i++; if ( class_name == #Name ) return i;
109 MINIGAME_SIMPLELINKED_ENTITIES
114 string msle_classname(int id)
116 if ( id == 1 ) return "minigame";
117 if ( id == 2 ) return "minigame_player";
118 int i = msle_base_id;
119 #define MSLE(Name, Fields) i++; if ( id == i ) return #Name;
120 MINIGAME_SIMPLELINKED_ENTITIES
125 int minigame_count_players(entity minigame)
130 for(e = minigame.minigame_players; e; e = e.list_next)
133 while( (e = findentity(e,owner,minigame)) )
134 if ( e.classname == "minigame_player" )