1 #include "minigames.qh"
3 entity minigame_get_descriptor(string id)
6 for ( e = minigame_descriptors; e != world; e = e.list_next )
12 // Get letter index of a tile name
13 float minigame_tile_letter(string id)
15 return str2chr(substring(id,0,1),0)-'a';
18 // Get number index of a tile name
19 // Note: this is 0 based, useful for mathematical operations
20 // Note: Since the tile notation starts from the bottom left,
21 // you may want to do number_of_rows - what_this_function_returns or something
22 float minigame_tile_number(string id)
24 return stof(substring(id,1,-1)) -1 ;
27 // Get relative position of the center of a given tile
28 vector minigame_tile_pos(string id, float rows, float columns)
30 return eX*(minigame_tile_letter(id)+0.5)/columns +
31 eY - eY*(minigame_tile_number(id)+0.5)/rows;
34 // Get a tile name from indices
35 string minigame_tile_buildname(float letter, float number)
37 return strcat(chr2str('a'+letter),ftos(number+1));
40 // Get the id of a tile relative to the given one
41 string minigame_relative_tile(string start_id, float dx, float dy, float rows, float columns)
43 float letter = minigame_tile_letter(start_id);
44 float number = minigame_tile_number(start_id);
45 letter = (letter+dx) % columns;
46 number = (number+dy) % rows;
48 letter = columns + letter;
50 number = rows + number;
51 return minigame_tile_buildname(letter, number);
54 // Get tile name from a relative position (matches the tile covering a square area)
55 string minigame_tile_name(vector pos, float rows, float columns)
57 if ( pos_x < 0 || pos_x > 1 || pos_y < 0 || pos_y > 1 )
60 float letter = floor(pos_x * columns);
61 float number = floor((1-pos_y) * rows);
62 return minigame_tile_buildname(letter, number);
65 // Get the next team number (note: team numbers are between 1 and n_teams, inclusive)
66 float minigame_next_team(float curr_team, float n_teams)
68 return curr_team % n_teams + 1;
71 // set send flags only when on server
72 // (for example in game logic which can be used both in client and server
73 void minigame_server_sendflags(entity ent, float mgflags)
76 ent.SendFlags |= mgflags;
80 // Spawn linked entity on the server or local entity on the client
81 // This entity will be removed automatically when the minigame ends
82 entity msle_spawn(entity minigame_session, string class_name)
85 e.classname = class_name;
86 e.owner = minigame_session;
87 e.minigame_autoclean = 1;
89 e.customizeentityforclient = minigame_CheckSend;
90 Net_LinkEntity(e, false, 0, minigame_SendEntity);
95 const float msle_base_id = 2;
96 float msle_id(string class_name)
98 if ( class_name == "minigame" ) return 1;
99 if ( class_name == "minigame_player" ) return 2;
100 float i = msle_base_id;
101 #define MSLE(Name, Fields) i++; if ( class_name == #Name ) return i;
102 MINIGAME_SIMPLELINKED_ENTITIES
107 string msle_classname(float id)
109 if ( id == 1 ) return "minigame";
110 if ( id == 2 ) return "minigame_player";
111 float i = msle_base_id;
112 #define MSLE(Name, Fields) i++; if ( id == i ) return #Name;
113 MINIGAME_SIMPLELINKED_ENTITIES
118 float minigame_count_players(entity minigame)
123 for(e = minigame.minigame_players; e; e = e.list_next)
126 while( (e = findentity(e,owner,minigame)) )
127 if ( e.classname == "minigame_player" )