]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/minigames/minigame/all.qh
Add the new minigames
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / minigames / minigame / all.qh
1 #if defined(SVQC)
2 #include "../sv_minigames.qh"
3 #elif defined(CSQC)
4 #include "../cl_minigames.qh"
5 #endif
6
7 /**
8
9 How to create a minigame
10 ========================
11
12 Create a file for your minigame in this directory and #include it here.
13 (ttt.qc implements tic tac toe and can be used as an example)
14 and add your minigame to REGISTERED_MINIGAMES (see below)
15
16 Required functions
17 ------------------
18
19 SVQC:
20         int <id>_server_event(entity minigame, string event, ...count)
21                 see ../minigames.qh for a detailed explanation
22 CSQC:
23         void <id>_hud_board(vector pos, vector mySize)
24                 draws the main game board inside the rectangle defined by pos and mySize
25                 (That rectangle is expressed in window coordinates)
26         void <id>_hud_status(vector pos, vector mySize)
27                 draws the game status panel inside the rectangle defined by pos and mySize
28                 (That rectangle is expressed in window coordinates)
29                 This panel shows eg scores, captured pieces and so on
30         int <id>_client_event(entity minigame, string event, ...count)
31                 see ../minigames.qh for a detailed explanation
32
33 Managing entities
34 -----------------
35
36 You can link entities without having to worry about them if their classname
37 has been defined in MINIGAME_SIMPLELINKED_ENTITIES (see below)
38 Such entities can be spawned with msle_spawn and the system
39 will handle networking and cleanup automatically.
40 You'll still need to set .SendFlags according to what you specified in FIELD
41 in order for them to be sent, ../minigames.qh defines some constants to be
42 used as send flags for minigame entities:
43
44 * MINIG_SF_CREATE
45         Used when creating a new object, you can use this to define fields that don't change
46         Don't add MINIG_SF_CREATE to SendFlags on your own
47 * MINIG_SF_UPDATE
48         A miscellaneous update, can be safely used if the entity has just a few fields
49 * MINIG_SF_CUSTOM
50         Starting value for custom flags, since there are bit-wise flags, 
51         the following values shall be MINIG_SF_CUSTOM*2, MINIG_SF_CUSTOM*4 and MINIG_SF_CUSTOM*8.
52 * MINIG_SF_MAX
53         Maximum flag value that will be networked
54 * MINIG_SF_ALL
55         Mask matching all possible flags
56
57 Note: As of now, flags are sent as a single byte
58
59 Even for non-networked entities, the system provides a system to remove
60 automatically unneeded entities when the minigame is over, the requirement is
61 that .owner is set to the minigame session entity and .minigame_autoclean is true.
62 */
63
64 #include "nmm.qc"
65 #include "ttt.qc"
66 #include "c4.qc"
67 #include "pong.qc"
68 #include "qto.qc"
69 #include "ps.qc"
70 #include "pp.qc"
71
72 /**
73  * Registration:
74  *      MINIGAME(id,"Name")
75  *              id    (QuakeC symbol) Game identifier, used to find the functions explained above
76  *              "Name"(String)        Human readable name for the game, shown in the UI
77  */
78 #define REGISTERED_MINIGAMES \
79         MINIGAME(nmm, "Nine Men's Morris") \
80         MINIGAME(ttt, "Tic Tac Toe") \
81         MINIGAME(pong,"Pong") \
82         MINIGAME(c4,  "Connect Four") \
83         MINIGAME(qto, "Quinto") \
84         MINIGAME(ps,  "Peg Solitaire") \
85         MINIGAME(pp,  "Push-Pull") \
86         /*empty line*/
87
88 /**
89  * Set up automatic entity read/write functionality
90  * To ensure that everything is handled automatically, spawn on the server using msle_spawn
91  * Syntax:
92  *      MSLE(classname,Field...) \ 
93  *              classname: Identifier used to recognize the type of the entity
94  *                         (must be set as .classname on the sent entities)
95  *              Field... : List of FIELD calls
96  *      FIELD(sendflags, Type, field)
97  *              sendflags: Send flags that signal when this field has to be sent
98  *              Type     : Type of the entity field. Used to determine WriteX/ReadX functions.
99  *                         Follows a list of accepted values
100  *                      Byte
101  *                      Char
102  *                      Short
103  *                      Long
104  *                      Coord
105  *                      Angle
106  *                      String   Note: strzoned on client
107  *                      Float    Note: implemented as Write/Read Coord
108  *                      Vector   Note: implemented as Write/Read Coord on _x _y _z
109  *                      Vector2D Note: implemented as Write/Read Coord on _x _y
110  * Note:
111  *      classname and netname are always sent
112  *      MSLE stands for Minigame Simple Linked Entity
113  */
114 #define MINIGAME_SIMPLELINKED_ENTITIES \
115         MSLE(minigame_board_piece,FIELD(MINIG_SF_CREATE,Byte,team) FIELD(MINIG_SF_UPDATE, Short, minigame_flags) FIELD(MINIG_SF_UPDATE, Vector2D,origin)) \
116         MSLE(pong_paddle,FIELD(MINIG_SF_CREATE,Byte,team) FIELD(MINIG_SF_CREATE,Float,pong_length) FIELD(MINIG_SF_UPDATE,Vector2D,origin)) \
117         MSLE(pong_ball,FIELD(MINIG_SF_CREATE,Float,pong_length) FIELD(PONG_SF_BALLTEAM,Byte,team) FIELD(MINIG_SF_UPDATE, Vector2D, velocity) FIELD(MINIG_SF_UPDATE, Vector2D, origin)) \
118         MSLE(pong_ai, FIELD(MINIG_SF_CREATE,Byte,team) FIELD(PONG_SF_PLAYERSCORE, Long, pong_score)) \
119         /*empty line*/