CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
CALL_ACCUMULATED_FUNCTION(RegisterHUD_Panels);
- initialize_minigames();
-
// precaches
Projectile_Precache();
mousepos_y >= pos_y && mousepos_y < pos_y + sz_y ;
}
-void initialize_minigames()
-{
- entity last_minig = world;
- entity minig;
- #define MINIGAME(name,nicename) \
- minig = spawn(); \
- minig.classname = "minigame_descriptor"; \
- minig.netname = strzone(strtolower(#name)); \
- minig.message = nicename; \
- minig.minigame_hud_board = name##_hud_board; \
- minig.minigame_hud_status = name##_hud_status; \
- minig.minigame_event = name##_client_event; \
- if ( !last_minig ) minigame_descriptors = minig; \
- else last_minig.list_next = minig; \
- last_minig = minig;
-
- REGISTERED_MINIGAMES
-
- #undef MINIGAME
-}
-
string minigame_texture_skin(string skinname, string name)
{
return sprintf("gfx/hud/%s/minigames/%s", skinname, name);
// For minigame_player: player server slot, don't use for anything else
.float minigame_playerslot;
-// register all minigames
-void initialize_minigames();
-
// client-side minigame session cleanup
void deactivate_minigame();
entityvar=world; \
while( (entityvar = findentity(entityvar,owner,active_minigame)) )
+
+void RegisterMinigames();
+const int MINIGAMES_MAX = 24;
+entity MINIGAMES[MINIGAMES_MAX], MINIGAMES_first, MINIGAMES_last;
+int MINIGAMES_COUNT;
+#define REGISTER_MINIGAME(name,nicename) \
+ REGISTER(RegisterMinigames, MINIGAME, MINIGAMES, MINIGAMES_COUNT, name, m_id, spawn()); \
+ void name##_hud_board(vector, vector); \
+ void name##_hud_status(vector, vector); \
+ int name##_client_event(entity, string, ...); \
+ REGISTER_INIT_POST(MINIGAME, name) { \
+ this.classname = "minigame_descriptor"; \
+ this.netname = strzone(strtolower(#name)); \
+ this.message = nicename; \
+ this.minigame_hud_board = name##_hud_board; \
+ this.minigame_hud_status = name##_hud_status; \
+ this.minigame_event = name##_client_event; \
+ } \
+ REGISTER_INIT(MINIGAME, name)
+REGISTER_REGISTRY(RegisterMinigames)
+
#endif
{SELFPARAM();
if ( HUD_MinigameMenu_Click_ExpandCollapse() )
{
- entity e;
entity curr;
entity prev = self;
- for ( e = minigame_descriptors; e != world; e = e.list_next )
+ FOREACH(MINIGAMES, true, LAMBDA(
{
curr = HUD_MinigameMenu_SpawnSubEntry(
- e.message, HUD_MinigameMenu_ClickCreate_Entry, self );
- curr.netname = e.netname;
- curr.model = strzone(minigame_texture(strcat(e.netname,"/icon")));
+ it.message, HUD_MinigameMenu_ClickCreate_Entry, self );
+ curr.netname = it.netname;
+ curr.model = strzone(minigame_texture(strcat(it.netname,"/icon")));
HUD_MinigameMenu_InsertEntry( curr, prev );
prev = curr;
- }
+ }));
}
}
#include "pp.qc"
#include "snake.qc"
-/**
- * Registration:
- * MINIGAME(id,"Name")
- * id (QuakeC symbol) Game identifier, used to find the functions explained above
- * "Name"(String) Human readable name for the game, shown in the UI
- */
-#define REGISTERED_MINIGAMES \
- MINIGAME(nmm, "Nine Men's Morris") \
- MINIGAME(ttt, "Tic Tac Toe") \
- MINIGAME(pong,"Pong") \
- MINIGAME(c4, "Connect Four") \
- MINIGAME(ps, "Peg Solitaire") \
- MINIGAME(pp, "Push-Pull") \
- MINIGAME(snake,"Snake") \
- /*empty line*/
-
/**
* Set up automatic entity read/write functionality
* To ensure that everything is handled automatically, spawn on the server using msle_spawn
+REGISTER_MINIGAME(c4, "Connect Four");
+
const float C4_TURN_PLACE = 0x0100; // player has to place a piece on the board
const float C4_TURN_WIN = 0x0200; // player has won
const float C4_TURN_DRAW = 0x0400; // no moves are possible
+REGISTER_MINIGAME(nmm, "Nine Men's Morris");
+
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
+REGISTER_MINIGAME(pong, "Pong");
+
// minigame flags
const int PONG_STATUS_WAIT = 0x0010; // waiting for players to join
const int PONG_STATUS_PLAY = 0x0020; // playing
+REGISTER_MINIGAME(pp, "Push-Pull");
+
const int PP_TURN_PLACE = 0x0100; // player has to place a piece on the board
const int PP_TURN_WIN = 0x0200; // player has won
const int PP_TURN_DRAW = 0x0400; // players have equal scores
+REGISTER_MINIGAME(ps, "Peg Solitaire");
+
const float PS_TURN_MOVE = 0x0100; // player has to click on a piece on the board
const float PS_TURN_WIN = 0x0200; // player has won
const float PS_TURN_DRAW = 0x0400; // player can make no more moves
+REGISTER_MINIGAME(snake, "Snake");
+
const float SNAKE_TURN_MOVE = 0x0100; // the snake is moving, player must control it
const float SNAKE_TURN_LOSS = 0x0200; // they did it?!
const float SNAKE_TURN_WAIT = 0x0400; // the snake is waiting for the player to make their first move and begin the game
+REGISTER_MINIGAME(ttt, "Tic Tac Toe");
+
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
entity minigame_get_descriptor(string id)
{
- entity e;
- for ( e = minigame_descriptors; e != world; e = e.list_next )
- if ( e.netname == id )
- return e;
+ FOREACH(MINIGAMES, true, LAMBDA(
+ {
+ if(it.netname == id)
+ return it;
+ }));
return world;
}
#ifndef MINIGAMES_H
#define MINIGAMES_H
-entity minigame_descriptors;
-
// previous node in a doubly linked list
.entity list_prev;
// next node in a linked list
}
}
-void initialize_minigames()
-{
- entity last_minig = world;
- entity minig;
- #define MINIGAME(name,nicename) \
- minig = spawn(); \
- minig.classname = "minigame_descriptor"; \
- minig.netname = #name; \
- minig.message = nicename; \
- minig.minigame_event = name##_server_event; \
- if ( !last_minig ) minigame_descriptors = minig; \
- else last_minig.list_next = minig; \
- last_minig = minig;
-
- REGISTERED_MINIGAMES
-
- #undef MINIGAME
-}
-
string invite_minigame(entity inviter, entity player)
{
if ( !inviter || !inviter.active_minigame )
}
else if ( minig_cmd == "list" )
{
- entity e;
- for ( e = minigame_descriptors; e != world; e = e.list_next )
- sprint(self,e.netname," (",e.message,") ","\n");
+ FOREACH(MINIGAMES, true, LAMBDA(
+ {
+ sprint(self,it.netname," (",it.message,") ","\n");
+ }));
return;
}
else if ( minig_cmd == "list-sessions" )
#ifndef SV_MINIGAMES_H
#define SV_MINIGAMES_H
-/// Initialize the minigame system
-void initialize_minigames();
-
/// Create a new minigame session
/// \return minigame session entity
entity start_minigame(entity player, string minigame );
bool minigame_SendEntity(entity to, int sf);
+void RegisterMinigames();
+const int MINIGAMES_MAX = 24;
+entity MINIGAMES[MINIGAMES_MAX], MINIGAMES_first, MINIGAMES_last;
+int MINIGAMES_COUNT;
+#define REGISTER_MINIGAME(name,nicename) \
+ REGISTER(RegisterMinigames, MINIGAME, MINIGAMES, MINIGAMES_COUNT, name, m_id, spawn()); \
+ int name##_server_event(entity, string, ...); \
+ REGISTER_INIT_POST(MINIGAME, name) { \
+ this.classname = "minigame_descriptor"; \
+ this.netname = strzone(strtolower(#name)); \
+ this.message = nicename; \
+ this.minigame_event = name##_server_event; \
+ } \
+ REGISTER_INIT(MINIGAME, name)
+REGISTER_REGISTRY(RegisterMinigames)
+
#endif
CALL_ACCUMULATED_FUNCTION(RegisterNotifications);
CALL_ACCUMULATED_FUNCTION(RegisterDeathtypes);
- initialize_minigames();
-
ServerProgsDB = db_load(strcat("server.db", autocvar_sessionid));
TemporaryDB = db_create();