==================
*/
-float HUD_Panel_CheckFlags(float showflags)
+bool HUD_Panel_CheckFlags(int showflags)
{
if ( HUD_Minigame_Showpanels() )
return showflags & PANEL_SHOW_MINIGAME;
float GetPlayerColorForce(int i);
float GetPlayerColor(int i);
-.float panel_showflags;
-const float PANEL_SHOW_NEVER = 0x00;
-const float PANEL_SHOW_MAINGAME = 0x01;
-const float PANEL_SHOW_MINIGAME = 0x02;
-const float PANEL_SHOW_ALWAYS = 0xff;
-float HUD_Panel_CheckFlags(float showflags);
+.int panel_showflags;
+const int PANEL_SHOW_NEVER = 0x00;
+const int PANEL_SHOW_MAINGAME = 0x01;
+const int PANEL_SHOW_MINIGAME = 0x02;
+const int PANEL_SHOW_ALWAYS = 0xff;
+bool HUD_Panel_CheckFlags(int showflags);
#define HUD_PANELS(HUD_PANEL) \
HUD_PANEL(WEAPONS , HUD_Weapons , weapons, PANEL_SHOW_MAINGAME ) \
}
// Check if the mouse is inside the given area
-float minigame_hud_mouse_in(vector pos, vector sz)
+bool minigame_hud_mouse_in(vector pos, vector sz)
{
return mousepos_x >= pos_x && mousepos_x < pos_x + sz_x &&
mousepos_y >= pos_y && mousepos_y < pos_y + sz_y ;
}
void HUD_MinigameMenu_CurrentButton();
-float auto_close_minigamemenu;
+bool auto_close_minigamemenu;
void deactivate_minigame()
{
if ( !active_minigame )
string minigame_getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
{
- float last_word;
+ int last_word;
string s;
- float take_until;
- float skip = 0;
+ int take_until;
+ int skip = 0;
s = getWrappedLine_remaining;
if ( take_until > strlen(s) )
take_until = strlen(s);
- float i;
- for ( i = 0; i < take_until; i++ )
+ for ( int i = 0; i < take_until; i++ )
if ( substring(s,i,1) == "\n" )
{
take_until = i;
}
vector minigame_drawstring_wrapped( float maxwidth, vector pos, string text,
- vector fontsize, vector color, float theAlpha, float drawflags, float align )
+ vector fontsize, vector color, float theAlpha, int drawflags, float align )
{
getWrappedLine_remaining = text;
vector mypos = pos;
}
vector minigame_drawcolorcodedstring_wrapped( float maxwidth, vector pos,
- string text, vector fontsize, float theAlpha, float drawflags, float align )
+ string text, vector fontsize, float theAlpha, int drawflags, float align )
{
getWrappedLine_remaining = text;
vector mypos = pos;
}
void minigame_drawstring_trunc(float maxwidth, vector pos, string text,
- vector fontsize, vector color, float theAlpha, float drawflags )
+ vector fontsize, vector color, float theAlpha, int drawflags )
{
string line = textShortenToWidth(text,maxwidth,fontsize,stringwidth_nocolors);
drawstring(pos, line, fontsize, color, theAlpha, drawflags);
}
void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text,
- vector fontsize, float theAlpha, float drawflags )
+ vector fontsize, float theAlpha, int drawflags )
{
string line = textShortenToWidth(text,maxwidth,fontsize,stringwidth_colors);
drawcolorcodedstring(pos, line, fontsize, theAlpha, drawflags);
}
void minigame_drawpic_centered( vector pos, string texture, vector sz,
- vector color, float thealpha, float drawflags )
+ vector color, float thealpha, int drawflags )
{
drawpic( pos-sz/2, texture, sz, color, thealpha, drawflags );
}
vector minigame_hud_denormalize_size(vector v, vector pos, vector mySize);
// Check if the mouse is inside the given area
-float minigame_hud_mouse_in(vector pos, vector sz);
+bool minigame_hud_mouse_in(vector pos, vector sz);
// Like drawstring, but wrapping words to fit maxwidth
// returns the size of the drawn area
// align selects the string alignment (0 = left, 0.5 = center, 1 = right)
vector minigame_drawstring_wrapped( float maxwidth, vector pos, string text,
- vector fontsize, vector color, float theAlpha, float drawflags, float align );
+ vector fontsize, vector color, float theAlpha, int drawflags, float align );
// Like drawcolorcodedstring, but wrapping words to fit maxwidth
// returns the size of the drawn area
// align selects the string alignment (0 = left, 0.5 = center, 1 = right)
vector minigame_drawcolorcodedstring_wrapped( float maxwidth, vector pos,
- string text, vector fontsize, float theAlpha, float drawflags, float align );
+ string text, vector fontsize, float theAlpha, int drawflags, float align );
// Like drawstring but truncates the text to fit maxwidth
void minigame_drawstring_trunc(float maxwidth, vector pos, string text,
- vector fontsize, vector color, float theAlpha, float drawflags );
+ vector fontsize, vector color, float theAlpha, int drawflags );
// Like drawcolorcodedstring but truncates the text to fit maxwidth
void minigame_drawcolorcodedstring_trunc(float maxwidth, vector pos, string text,
- vector fontsize, float theAlpha, float drawflags );
+ vector fontsize, float theAlpha, int drawflags );
// like drawpic but pos represent the center rather than the topleft corner
void minigame_drawpic_centered( vector pos, string texture, vector sz,
- vector color, float thealpha, float drawflags );
+ vector color, float thealpha, int drawflags );
// Get full path of a minigame texture
string minigame_texture(string name);
// Helper click action for collapsible entries
// returns true when you have to create the sub-entries
-float HUD_MinigameMenu_Click_ExpandCollapse()
+bool HUD_MinigameMenu_Click_ExpandCollapse()
{
entity e;
if ( self.flags & 2 )
{
if ( HUD_MinigameMenu_Click_ExpandCollapse() )
{
- float i;
entity e;
entity prev = self;
- for(i = 0; i < maxclients; ++i)
+ for(int i = 0; i < maxclients; ++i)
{
if ( player_localnum != i && playerslots[i] && GetPlayerName(i) != "" &&
!findfloat(world,minigame_playerslot,i+1) && playerslots[i].ping )
}
}
// Whether the minigame menu panel is open
-float HUD_MinigameMenu_IsOpened()
+bool HUD_MinigameMenu_IsOpened()
{
return !!HUD_MinigameMenu_entries;
}
HUD_MinigameMenu_DrawEntry(panel_pos,_("Minigames"),hud_fontsize*2,'0.25 0.47 0.72');
panel_pos_y += hud_fontsize_y*2;
- entity e;
vector color;
vector offset;
float itemh;
vector imgsz = '22 22 0'; // NOTE: if changed, edit where HUD_MinigameMenu_activeitem is selected
- for ( e = HUD_MinigameMenu_entries; e != world; e = e.list_next )
+ for ( entity e = HUD_MinigameMenu_entries; e != world; e = e.list_next )
{
color = e.colormod;
}
else
{
-
if(bInputType == 0) {
if(nPrimary == K_ALT) hudShiftState |= S_ALT;
if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
// allow some binds
string con_keys;
- float keys;
- float i;
con_keys = findkeysforcommand("toggleconsole", 0);
- keys = tokenize(con_keys); // findkeysforcommand returns data for this
- for (i = 0; i < keys; ++i)
+ int keys = tokenize(con_keys); // findkeysforcommand returns data for this
+ for (int i = 0; i < keys; ++i)
{
if(nPrimary == stof(argv(i)))
return false;
cursorsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
}
-float HUD_Minigame_Showpanels()
+bool HUD_Minigame_Showpanels()
{
return HUD_MinigameMenu_IsOpened() && ( autocvar__hud_configure || minigame_isactive() );
}
------------------
SVQC:
- float minigame_event_<id>(entity minigame, string event, ...count)
+ int minigame_event_<id>(entity minigame, string event, ...count)
see ../minigames.qh for a detailed explanation
CSQC:
void minigame_hud_board_<id>(vector pos, vector mySize)
draws the game status panel inside the rectangle defined by pos and mySize
(That rectangle is expressed in window coordinates)
This panel shows eg scores, captured pieces and so on
- float minigame_event_<id>(entity minigame, string event, ...count)
+ int minigame_event_<id>(entity minigame, string event, ...count)
see ../minigames.qh for a detailed explanation
Managing entities
-const float NMM_TURN_PLACE = 0x0100; // player has to place a piece on the board
-const float NMM_TURN_MOVE = 0x0200; // player has to move a piece by one tile
-const float NMM_TURN_FLY = 0x0400; // player has to move a piece anywhere
-const float NMM_TURN_TAKE = 0x0800; // player has to take a non-mill piece
-const float NMM_TURN_TAKEANY=0x1000; // combine with NMM_TURN_TAKE, can take mill pieces
-const float NMM_TURN_WIN = 0x2000; // player has won
-const float NMM_TURN_TYPE = 0xff00;
-const float NMM_TURN_TEAM1 = 0x0001;
-const float NMM_TURN_TEAM2 = 0x0002;
-const float NMM_TURN_TEAM = 0x00ff;
+const int NMM_TURN_PLACE = 0x0100; // player has to place a piece on the board
+const int NMM_TURN_MOVE = 0x0200; // player has to move a piece by one tile
+const int NMM_TURN_FLY = 0x0400; // player has to move a piece anywhere
+const int NMM_TURN_TAKE = 0x0800; // player has to take a non-mill piece
+const int NMM_TURN_TAKEANY=0x1000; // combine with NMM_TURN_TAKE, can take mill pieces
+const int NMM_TURN_WIN = 0x2000; // player has won
+const int NMM_TURN_TYPE = 0xff00;
+const int NMM_TURN_TEAM1 = 0x0001;
+const int NMM_TURN_TEAM2 = 0x0002;
+const int NMM_TURN_TEAM = 0x00ff;
-const float NMM_PIECE_DEAD = 0x0; // captured by the enemy
-const float NMM_PIECE_HOME = 0x1; // not yet placed
-const float NMM_PIECE_BOARD = 0x2; // placed on the board
+const int NMM_PIECE_DEAD = 0x0; // captured by the enemy
+const int NMM_PIECE_HOME = 0x1; // not yet placed
+const int NMM_PIECE_BOARD = 0x2; // placed on the board
-.float nmm_tile_distance;
+.int nmm_tile_distance;
.entity nmm_tile_piece;
.string nmm_tile_hmill;
.string nmm_tile_vmill;
// build a string containing the indices of the tile to check for a horizontal mill
string nmm_tile_build_hmill(entity tile)
{
- float number = minigame_tile_number(tile.netname);
- float letter = minigame_tile_letter(tile.netname);
+ int number = minigame_tile_number(tile.netname);
+ int letter = minigame_tile_letter(tile.netname);
if ( number == letter || number+letter == 6 )
{
- float add = letter < 3 ? 1 : -1;
+ int add = letter < 3 ? 1 : -1;
return strcat(tile.netname," ",
minigame_tile_buildname(letter+add*tile.nmm_tile_distance,number)," ",
minigame_tile_buildname(letter+add*2*tile.nmm_tile_distance,number) );
// build a string containing the indices of the tile to check for a vertical mill
string nmm_tile_build_vmill(entity tile)
{
- float letter = minigame_tile_letter(tile.netname);
- float number = minigame_tile_number(tile.netname);
+ int letter = minigame_tile_letter(tile.netname);
+ int number = minigame_tile_number(tile.netname);
if ( letter == number || letter+number == 6 )
{
- float add = number < 3 ? 1 : -1;
+ int add = number < 3 ? 1 : -1;
return strcat(tile.netname," ",
minigame_tile_buildname(letter,number+add*tile.nmm_tile_distance)," ",
minigame_tile_buildname(letter,number+add*2*tile.nmm_tile_distance) );
// \param id Tile index (eg: a1)
// \param minig Owner minigame instance
// \param distance Distance from adjacent tiles
-void nmm_spawn_tile(string id, entity minig, float distance)
+void nmm_spawn_tile(string id, entity minig, int distance)
{
// TODO global variable + list_next for simpler tile loops
entity e = spawn();
// \param minig Owner minigame instance
// \param offset Index offset (eg: 1 to start the square at b2, 0 at a1 etc.)
// \param skip Number of indices to skip between tiles (eg 1: a1, a3)
-void nmm_spawn_tile_square( entity minig, float offset, float skip )
+void nmm_spawn_tile_square( entity minig, int offset, int skip )
{
- float letter = offset;
- float number = offset;
- float i, j;
- for ( i = 0; i < 3; i++ )
+ int letter = offset;
+ int number = offset;
+ for ( int i = 0; i < 3; i++ )
{
number = offset;
- for ( j = 0; j < 3; j++ )
+ for ( int j = 0; j < 3; j++ )
{
if ( i != 1 || j != 1 )
nmm_spawn_tile(strzone(minigame_tile_buildname(letter,number)),minig, skip+1);
}
// Check whether two tiles are adjacent
-float nmm_tile_adjacent(entity tile1, entity tile2)
+bool nmm_tile_adjacent(entity tile1, entity tile2)
{
- float dnumber = fabs ( minigame_tile_number(tile1.netname) - minigame_tile_number(tile2.netname) );
- float dletter = fabs ( minigame_tile_letter(tile1.netname) - minigame_tile_letter(tile2.netname) );
+ int dnumber = fabs ( minigame_tile_number(tile1.netname) - minigame_tile_number(tile2.netname) );
+ int dletter = fabs ( minigame_tile_letter(tile1.netname) - minigame_tile_letter(tile2.netname) );
return ( dnumber == 0 && ( dletter == 1 || dletter == tile1.nmm_tile_distance ) ) ||
( dletter == 0 && ( dnumber == 1 || dnumber == tile1.nmm_tile_distance ) );
}
// Returns 1 if there is at least 1 free adjacent tile
-float nmm_tile_canmove(entity tile)
+bool nmm_tile_canmove(entity tile)
{
entity e = world;
while ( ( e = findentity(e,owner,tile.owner) ) )
if ( e.classname == "minigame_nmm_tile" && !e.nmm_tile_piece
&& nmm_tile_adjacent(e,tile) )
{
- return 1;
+ return true;
}
- return 0;
+ return false;
}
// Check if the given tile id appears in the string
-float nmm_in_mill_string(entity tile, string s)
+bool nmm_in_mill_string(entity tile, string s)
{
- float argc = tokenize(s);
- float i;
- for ( i = 0; i < argc; i++ )
+ int argc = tokenize(s);
+ for ( int i = 0; i < argc; i++ )
{
entity e = nmm_find_tile(tile.owner,argv(i));
if ( !e || !e.nmm_tile_piece || e.nmm_tile_piece.team != tile.nmm_tile_piece.team )
- return 0;
+ return false;
}
- return 1;
+ return true;
}
// Check if a tile is in a mill
-float nmm_in_mill(entity tile)
+bool nmm_in_mill(entity tile)
{
return tile.nmm_tile_piece && (
nmm_in_mill_string(tile,tile.nmm_tile_hmill) ||
#ifdef SVQC
// Find a NMM piece matching some of the given flags and team number
-entity nmm_find_piece(entity start, entity minigame, float teamn, float pieceflags)
+entity nmm_find_piece(entity start, entity minigame, int teamn, int pieceflags)
{
entity e = start;
while ( ( e = findentity(e,owner,minigame) ) )
}
// Count NMM pieces matching flags and team number
-float nmm_count_pieces(entity minigame, float teamn, float pieceflags)
+int nmm_count_pieces(entity minigame, int teamn, int pieceflags)
{
- float n = 0;
+ int n = 0;
entity e = world;
while (( e = nmm_find_piece(e,minigame, teamn, pieceflags) ))
n++;
}
// required function, handle server side events
-float minigame_event_nmm(entity minigame, string event, ...)
+int minigame_event_nmm(entity minigame, string event, ...)
{
if ( event == "start" )
{
minigame.minigame_flags = NMM_TURN_PLACE|NMM_TURN_TEAM1;
nmm_init_tiles(minigame);
- float i;
entity e;
- for ( i = 0; i < 7; i++ )
+ for ( int i = 0; i < 7; i++ )
{
e = msle_spawn(minigame,"minigame_board_piece");
e.team = 1;
}
else if ( event == "join" )
{
- float n = 0;
+ int n = 0;
entity e;
for ( e = minigame.minigame_players; e; e = e.list_next )
n++;
else if ( event == "cmd" )
{
entity e = ...(0,entity);
- float argc = ...(1,float);
+ int argc = ...(1,int);
entity tile = world;
entity piece = world;
- float move_ok = 0;
+ bool move_ok = false;
if ( e && argc >= 2 && argv(0) == "move" &&
( minigame.minigame_flags & NMM_TURN_TEAM ) == e.team )
tile = nmm_find_tile(minigame,argv(1));
if ( !tile )
{
- move_ok = 0;
+ move_ok = false;
}
else if ( minigame.minigame_flags & NMM_TURN_PLACE )
{
piece.minigame_flags = NMM_PIECE_BOARD;
piece.origin = tile.origin;
piece.SendFlags |= MINIG_SF_UPDATE;
- move_ok = 1;
+ move_ok = true;
}
}
else if ( minigame.minigame_flags & NMM_TURN_MOVE )
piece.origin = tile2.origin;
piece.SendFlags |= MINIG_SF_UPDATE;
tile = tile2;
- move_ok = 1;
+ move_ok = true;
}
}
piece.origin = tile2.origin;
piece.SendFlags |= MINIG_SF_UPDATE;
tile = tile2;
- move_ok = 1;
+ move_ok = true;
}
}
tile.nmm_tile_piece = world;
piece.minigame_flags = NMM_PIECE_DEAD;
piece.SendFlags |= MINIG_SF_UPDATE;
- move_ok = 1;
+ move_ok = true;
}
}
- float nextteam = e.team % 2 + 1;
- float npieces = nmm_count_pieces(minigame,nextteam,NMM_PIECE_HOME|NMM_PIECE_BOARD);
+ int nextteam = e.team % 2 + 1;
+ int npieces = nmm_count_pieces(minigame,nextteam,NMM_PIECE_HOME|NMM_PIECE_BOARD);
if ( npieces < 3 )
{
if ( !(minigame.minigame_flags & NMM_TURN_TAKE) && nmm_in_mill(tile) )
{
minigame.minigame_flags = NMM_TURN_TAKE|e.team;
- float takemill = NMM_TURN_TAKEANY;
+ int takemill = NMM_TURN_TAKEANY;
entity f = world;
while ( ( f = findentity(f,owner,minigame) ) )
if ( f.classname == "minigame_nmm_tile" && f.nmm_tile_piece &&
vector nmm_boardsize;
// whether the given tile is a valid selection
-float nmm_valid_selection(entity tile)
+bool nmm_valid_selection(entity tile)
{
if ( ( tile.owner.minigame_flags & NMM_TURN_TEAM ) != minigame_self.team )
- return 0; // not our turn
+ return false; // not our turn
if ( tile.owner.minigame_flags & NMM_TURN_PLACE )
return !tile.nmm_tile_piece; // need to put a piece on an empty spot
if ( tile.owner.minigame_flags & NMM_TURN_MOVE )
{
if ( tile.nmm_tile_piece && tile.nmm_tile_piece.team == minigame_self.team &&
nmm_tile_canmove(tile) )
- return 1; // movable tile
+ return true; // movable tile
if ( nmm_fromtile ) // valid destination
return !tile.nmm_tile_piece && nmm_tile_adjacent(nmm_fromtile,tile);
- return 0;
+ return false;
}
if ( tile.owner.minigame_flags & NMM_TURN_FLY )
{
if ( tile.owner.minigame_flags & NMM_TURN_TAKE )
return tile.nmm_tile_piece && tile.nmm_tile_piece.team != minigame_self.team &&
( (tile.owner.minigame_flags & NMM_TURN_TAKEANY) || !nmm_in_mill(tile) );
- return 0;
+ return false;
}
// whether it should highlight valid tile selections
-float nmm_draw_avaliable(entity tile)
+bool nmm_draw_avaliable(entity tile)
{
if ( ( tile.owner.minigame_flags & NMM_TURN_TEAM ) != minigame_self.team )
- return 0;
+ return false;
if ( (tile.owner.minigame_flags & NMM_TURN_TAKE) )
- return 1;
+ return true;
if ( (tile.owner.minigame_flags & (NMM_TURN_FLY|NMM_TURN_MOVE)) && nmm_fromtile )
return !tile.nmm_tile_piece;
- return 0;
+ return false;
}
// Required function, draw the game board
nmm_fromtile = world;
}
-string nmm_turn_to_string(float turnflags)
+string nmm_turn_to_string(int turnflags)
{
if ( turnflags & NMM_TURN_WIN )
{
}
// Required function, handle client events
-float minigame_event_nmm(entity minigame, string event, ...)
+int minigame_event_nmm(entity minigame, string event, ...)
{
if ( event == "activate" )
{
}
else if ( event == "key_pressed" && (minigame.minigame_flags&NMM_TURN_TEAM) == minigame_self.team )
{
- switch ( ...(0,float) )
+ switch ( ...(0,int) )
{
case K_RIGHTARROW:
case K_KP_RIGHTARROW:
}
return 0;
}
- else if ( event == "mouse_pressed" && ...(0,float) == K_MOUSE1 )
+ else if ( event == "mouse_pressed" && ...(0,int) == K_MOUSE1 )
{
nmm_make_move(minigame);
return 1;
}
else if ( event == "network_receive" )
{
- if ( self.classname == "minigame_board_piece" && ( ...(1,float) & MINIG_SF_UPDATE ) )
+ if ( self.classname == "minigame_board_piece" && ( ...(1,int) & MINIG_SF_UPDATE ) )
{
entity e;
string tileid = "";
}
}
}
- else if ( self.classname == "minigame" && ( ...(1,float) & MINIG_SF_UPDATE ) )
+ else if ( self.classname == "minigame" && ( ...(1,int) & MINIG_SF_UPDATE ) )
{
self.message = nmm_turn_to_string(self.minigame_flags);
if ( self.minigame_flags & minigame_self.team )
-const float TTT_TURN_PLACE = 0x0100; // player has to place a piece on the board
-const float TTT_TURN_WIN = 0x0200; // player has won
-const float TTT_TURN_DRAW = 0x0400; // no moves are possible
-const float TTT_TURN_NEXT = 0x0800; // a player wants to start a new match
-const float TTT_TURN_TYPE = 0x0f00; // turn type mask
+const int TTT_TURN_PLACE = 0x0100; // player has to place a piece on the board
+const int TTT_TURN_WIN = 0x0200; // player has won
+const int TTT_TURN_DRAW = 0x0400; // no moves are possible
+const int TTT_TURN_NEXT = 0x0800; // a player wants to start a new match
+const int TTT_TURN_TYPE = 0x0f00; // turn type mask
-const float TTT_TURN_TEAM1 = 0x0001;
-const float TTT_TURN_TEAM2 = 0x0002;
-const float TTT_TURN_TEAM = 0x000f; // turn team mask
+const int TTT_TURN_TEAM1 = 0x0001;
+const int TTT_TURN_TEAM2 = 0x0002;
+const int TTT_TURN_TEAM = 0x000f; // turn team mask
// send flags
-const float TTT_SF_PLAYERSCORE = MINIG_SF_CUSTOM; // send minigame_player scores (won matches)
-const float TTT_SF_SINGLEPLAYER = MINIG_SF_CUSTOM<<1;// send minigame.ttt_ai
+const int TTT_SF_PLAYERSCORE = MINIG_SF_CUSTOM; // send minigame_player scores (won matches)
+const int TTT_SF_SINGLEPLAYER = MINIG_SF_CUSTOM<<1;// send minigame.ttt_ai
-.float ttt_npieces; // (minigame) number of pieces on the board (simplifies checking a draw)
-.float ttt_nexteam; // (minigame) next team (used to change the starting team on following matches)
-.float ttt_ai; // (minigame) when non-zero, singleplayer vs AI
+.int ttt_npieces; // (minigame) number of pieces on the board (simplifies checking a draw)
+.int ttt_nexteam; // (minigame) next team (used to change the starting team on following matches)
+.int ttt_ai; // (minigame) when non-zero, singleplayer vs AI
// find tic tac toe piece given its tile name
entity ttt_find_piece(entity minig, string tile)
}
// Checks if the given piece completes a row
-float ttt_winning_piece(entity piece)
+bool ttt_winning_piece(entity piece)
{
- float number = minigame_tile_number(piece.netname);
- float letter = minigame_tile_letter(piece.netname);
+ int number = minigame_tile_number(piece.netname);
+ int letter = minigame_tile_letter(piece.netname);
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(0,number)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(1,number)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(2,number)).team == piece.team )
- return 1;
+ return true;
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(letter,0)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(letter,1)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(letter,2)).team == piece.team )
- return 1;
+ return true;
if ( number == letter )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(0,0)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(1,1)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(2,2)).team == piece.team )
- return 1;
+ return true;
if ( number == 2-letter )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(0,2)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(1,1)).team == piece.team )
if ( ttt_find_piece(piece.owner,minigame_tile_buildname(2,0)).team == piece.team )
- return 1;
+ return true;
- return 0;
+ return false;
}
// check if the tile name is valid (3x3 grid)
-float ttt_valid_tile(string tile)
+bool ttt_valid_tile(string tile)
{
if ( !tile )
return 0;
- float number = minigame_tile_number(tile);
- float letter = minigame_tile_letter(tile);
+ int number = minigame_tile_number(tile);
+ int letter = minigame_tile_letter(tile);
return 0 <= number && number < 3 && 0 <= letter && letter < 3;
}
// required function, handle server side events
-float minigame_event_ttt(entity minigame, string event, ...)
+int minigame_event_ttt(entity minigame, string event, ...)
{
switch(event)
{
}
case "join":
{
- float pl_num = minigame_count_players(minigame);
+ int pl_num = minigame_count_players(minigame);
// Don't allow joining a single player match
if ( (minigame.ttt_ai) && pl_num > 0 )
switch(argv(0))
{
case "move":
- ttt_move(minigame, ...(0,entity), ...(1,float) == 2 ? argv(1) : string_null );
+ ttt_move(minigame, ...(0,entity), ...(1,int) == 2 ? argv(1) : string_null );
return true;
case "next":
ttt_next_match(minigame,...(0,entity));
case "network_send":
{
entity sent = ...(0,entity);
- float sf = ...(1,float);
+ int sf = ...(1,int);
if ( sent.classname == "minigame_player" && (sf & TTT_SF_PLAYERSCORE ) )
{
WriteByte(MSG_ENTITY,sent.minigame_flags);
string ttt_curr_pos; // identifier of the tile under the mouse
vector ttt_boardpos; // HUD board position
vector ttt_boardsize;// HUD board size
-.float ttt_checkwin; // Used to optimize checks to display a win
+.int ttt_checkwin; // Used to optimize checks to display a win
// Required function, draw the game board
void minigame_hud_board_ttt(vector pos, vector mySize)
}
// Turn a set of flags into a help message
-string ttt_turn_to_string(float turnflags)
+string ttt_turn_to_string(int turnflags)
{
if ( turnflags & TTT_TURN_DRAW )
return _("Draw");
return "";
}
-const float TTT_AI_POSFLAG_A1 = 0x0001;
-const float TTT_AI_POSFLAG_A2 = 0x0002;
-const float TTT_AI_POSFLAG_A3 = 0x0004;
-const float TTT_AI_POSFLAG_B1 = 0x0008;
-const float TTT_AI_POSFLAG_B2 = 0x0010;
-const float TTT_AI_POSFLAG_B3 = 0x0020;
-const float TTT_AI_POSFLAG_C1 = 0x0040;
-const float TTT_AI_POSFLAG_C2 = 0x0080;
-const float TTT_AI_POSFLAG_C3 = 0x0100;
+const int TTT_AI_POSFLAG_A1 = 0x0001;
+const int TTT_AI_POSFLAG_A2 = 0x0002;
+const int TTT_AI_POSFLAG_A3 = 0x0004;
+const int TTT_AI_POSFLAG_B1 = 0x0008;
+const int TTT_AI_POSFLAG_B2 = 0x0010;
+const int TTT_AI_POSFLAG_B3 = 0x0020;
+const int TTT_AI_POSFLAG_C1 = 0x0040;
+const int TTT_AI_POSFLAG_C2 = 0x0080;
+const int TTT_AI_POSFLAG_C3 = 0x0100;
// convert a flag to a position
-string ttt_ai_piece_flag2pos(float pieceflag)
+string ttt_ai_piece_flag2pos(int pieceflag)
{
switch(pieceflag)
{
}
}
-float ttt_ai_checkmask(float piecemask, float checkflags)
+bool ttt_ai_checkmask(int piecemask, int checkflags)
{
return checkflags && (piecemask & checkflags) == checkflags;
}
// get the third flag if the mask matches two of them
-float ttt_ai_1of3(float piecemask, float flag1, float flag2, float flag3)
+int ttt_ai_1of3(int piecemask, int flag1, int flag2, int flag3)
{
if ( ttt_ai_checkmask(piecemask,flag1|flag2|flag3) )
return 0;
}
// Select a random flag in the mask
-float ttt_ai_random(float piecemask)
+int ttt_ai_random(int piecemask)
{
if ( !piecemask )
return 0;
- float i;
- float f = 1;
+ int f = 1;
RandomSelection_Init();
- for ( i = 0; i < 9; i++ )
+ for ( int i = 0; i < 9; i++ )
{
if ( piecemask & f )
RandomSelection_Add(world, f, string_null, 1, 1);
}
// Block/complete a 3 i na row
-float ttt_ai_block3 ( float piecemask, float piecemask_free )
+int ttt_ai_block3 ( int piecemask, int piecemask_free )
{
- float r = 0;
+ int r = 0;
r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_A1,TTT_AI_POSFLAG_A2,TTT_AI_POSFLAG_A3);
r |= ttt_ai_1of3(piecemask,TTT_AI_POSFLAG_B1,TTT_AI_POSFLAG_B2,TTT_AI_POSFLAG_B3);
// 1) tries to win the game if possible
// 2) tries to block the opponent if they have 2 in a row
// 3) places a piece randomly
-string ttt_ai_choose_simple(float piecemask_self, float piecemask_opponent, float piecemask_free )
+string ttt_ai_choose_simple(int piecemask_self, int piecemask_opponent, int piecemask_free )
{
- float move = 0;
+ int move = 0;
dprint("TTT AI: checking winning move\n");
if (( move = ttt_ai_block3(piecemask_self,piecemask_free) ))
* '---'---'---'
* A B C
*/
- float piecemask_self = 0;
- float piecemask_opponent = 0;
- float piecemask_free = 0;
- float pieceflag = 1;
+ int piecemask_self = 0;
+ int piecemask_opponent = 0;
+ int piecemask_free = 0;
+ int pieceflag = 1;
string pos;
- float i,j;
- for ( i = 0; i < 3; i++ )
- for ( j = 0; j < 3; j++ )
+ for ( int i = 0; i < 3; i++ )
+ for ( int j = 0; j < 3; j++ )
{
pos = minigame_tile_buildname(i,j);
entity piece = ttt_find_piece(minigame,pos);
}
// Required function, handle client events
-float minigame_event_ttt(entity minigame, string event, ...)
+int minigame_event_ttt(entity minigame, string event, ...)
{
switch(event)
{
{
if((minigame.minigame_flags & TTT_TURN_TEAM) == minigame_self.team)
{
- switch ( ...(0,float) )
+ switch ( ...(0,int) )
{
case K_RIGHTARROW:
case K_KP_RIGHTARROW:
}
case "mouse_pressed":
{
- if(...(0,float) == K_MOUSE1)
+ if(...(0,int) == K_MOUSE1)
{
ttt_make_move(minigame);
return true;
case "network_receive":
{
entity sent = ...(0,entity);
- float sf = ...(1,float);
+ int sf = ...(1,int);
if ( sent.classname == "minigame" )
{
if ( sf & MINIG_SF_UPDATE )
if ( (sf & TTT_SF_SINGLEPLAYER) )
{
- float ai = ReadByte();
- float spawnai = ai && !sent.ttt_ai;
+ int ai = ReadByte();
+ bool spawnai = ai && !sent.ttt_ai;
sent.ttt_ai = ai;
if ( spawnai )
}
// 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';
}
// Note: this is 0 based, useful for mathematical operations
// 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 +
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 )
}
// 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;
}
// 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;
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)
entity minigame_get_descriptor(string id);
// Get letter index of a tile name
-float minigame_tile_letter(string id);
+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,
// 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);
// 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);
// Get a tile name from indices
-string minigame_tile_buildname(float letter, float number);
+string minigame_tile_buildname(int letter, int number);
// 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);
// 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);
// 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);
// 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);
// count the number of players in a minigame session
-float minigame_count_players(entity minigame);
+int minigame_count_players(entity minigame);
/// For minigame sessions: minigame descriptor object
.entity descriptor;
/// Client events:
/// mouse_moved(vector mouse_pos)
/// return 1 to handle input, 0 to discard
-/// mouse_pressed/released(float K_Keycode)
+/// mouse_pressed/released(int K_Keycode)
/// return 1 to handle input, 0 to discard
/// note: see dpdefs/keycodes.qc for values
-/// key_pressed/released(float K_Keycode)
+/// key_pressed/released(int K_Keycode)
/// return 1 to handle input, 0 to discard
/// note: see dpdefs/keycodes.qc for values
/// activate()
/// executed when the minigame is activated for the current client
/// deactivate()
/// executed when the minigame is deactivated for the current client
-/// network_receive(entity received,float flags)
+/// network_receive(entity received,int flags)
/// executed each time a networked entity is received
/// note: when this is called self == ...(0,entity)
/// You can use the MINIG_SF_ constants to check the send flags
/// return the player team number to accept the new player, 0 to discard
/// part(entity player)
/// executed when a player is going to leave the session
-/// network_send(entity sent,float flags)
+/// network_send(entity sent,int flags)
/// executed each time a networked entity is sent
/// note: when this is called self == ...(0,entity)
/// You can use the MINIG_SF_ constants to check the send flags
/// IMPORTANT: always read in client everything you send from the server!
-/// cmd(entity minigame_player, float argc, string command)
+/// cmd(entity minigame_player, int argc, string command)
/// self = client entity triggering this
/// argv(n) = console token
/// argc: number of console tokens
/// command: full command string
/// triggered when a player does "cmd minigame ..." with some unrecognized command
/// return 1 if the minigame has handled the command
-/// impulse(entity minigame_player,float impulse)
+/// impulse(entity minigame_player,int impulse)
/// self = client entity triggering this
/// triggered when a player does "impulse ..."
/// return 1 if the minigame has handled the impulse
-.float(entity,string,...) minigame_event;
+.int(entity,string,...) minigame_event;
// For run-time gameplay entities: Whether to be removed when the game is deactivated
-.float minigame_autoclean;
+.bool minigame_autoclean;
// For run-time gameplay entities: some place to store flags safely
-.float minigame_flags;
+.int minigame_flags;
// Send flags, set to .SendFlags on networked entities to send entity information
// Flag values for customized events must be powers of 2 in the range
// [MINIG_SF_CUSTOM, MINIG_SF_MAX] (inclusive)
-const float MINIG_SF_CREATE = 0x01; // Create a new object
-const float MINIG_SF_UPDATE = 0x02; // miscellaneous entity update
-const float MINIG_SF_CUSTOM = 0x10; // a customized networked event
-const float MINIG_SF_MAX = 0x80; // maximum flag value sent over the network
-const float MINIG_SF_ALL = 0xff; // use to resend everything
+const int MINIG_SF_CREATE = 0x01; // Create a new object
+const int MINIG_SF_UPDATE = 0x02; // miscellaneous entity update
+const int MINIG_SF_CUSTOM = 0x10; // a customized networked event
+const int MINIG_SF_MAX = 0x80; // maximum flag value sent over the network
+const int MINIG_SF_ALL = 0xff; // use to resend everything
// Spawn linked entity on the server or local entity on the client
#include "minigame/all.qh"
-float msle_id(string class_name);
-string msle_classname(float id);
+int msle_id(string class_name);
+string msle_classname(int id);
#endif
// Send an entity to a client
// only use on minigame entities or entities with a minigame owner
-float minigame_SendEntity(entity to, float sf)
+bool minigame_SendEntity(entity to, int sf)
{
WriteByte(MSG_ENTITY, ENT_CLIENT_MINIGAME);
WriteByte(MSG_ENTITY, sf);
minigame_ent.minigame_event(minigame_ent,"network_send",self,sf);
- return 1;
+ return true;
}
#undef FIELD
}
}
-float minigame_CheckSend()
+bool minigame_CheckSend()
{
entity e;
for ( e = self.owner.minigame_players; e != world; e = e.list_next )
if ( e.minigame_players == other )
- return 1;
- return 0;
+ return true;
+ return false;
}
-float minigame_addplayer(entity minigame_session, entity player)
+int minigame_addplayer(entity minigame_session, entity player)
{
if ( player.active_minigame )
{
minigame_rmplayer(player.active_minigame,player);
}
- float mgteam = minigame_session.minigame_event(minigame_session,"join",player);
+ int mgteam = minigame_session.minigame_event(minigame_session,"join",player);
if ( mgteam )
{
return world;
}
-float MinigameImpulse(float imp)
+bool MinigameImpulse(int imp)
{
entity e = minigame_find_player(self);
if ( imp && self.active_minigame && e )
{
return self.active_minigame.minigame_event(self.active_minigame,"impulse",e,imp);
}
- return 0;
+ return false;
}
-void ClientCommand_minigame(float request, float argc, string command)
+void ClientCommand_minigame(int request, int argc, string command)
{
if ( !autocvar_sv_minigames )
{
{
entity e = minigame_find_player(self);
string subcommand = substring(command,argv_end_index(0),-1);
- float arg_c = tokenize_console(subcommand);
+ int arg_c = tokenize_console(subcommand);
if ( self.active_minigame.minigame_event(self.active_minigame,"cmd",e,arg_c,subcommand) )
return;
// Only sends entities to players who joined the minigame
// Use on customizeentityforclient for gameplay entities
-float minigame_CheckSend();
+bool minigame_CheckSend();
// Check for minigame impulses
-float MinigameImpulse(float imp);
+bool MinigameImpulse(int imp);
// Parse a client command ( cmd minigame ... )
-void ClientCommand_minigame(float request, float argc, string command);
+void ClientCommand_minigame(int request, int argc, string command);
// Find the minigame_player entity for the given client entity
entity minigame_find_player(entity client);
entity minigame_sessions;
-float minigame_SendEntity(entity to, float sf);
-
-var void remove(entity e);
+bool minigame_SendEntity(entity to, int sf);
#endif
.string nent_iconargs;
#define MULTIICON_INFO(default,name,strnum,flnum,args,hudargs,iconargs,icon,normal,gentle) \
NOTIF_ADD_AUTOCVAR(name, default) \
- float name; \
+ int name; \
void RegisterNotification_##name() \
{ \
SET_FIELD_COUNT(name, NOTIF_FIRST, NOTIF_INFO_COUNT) \