]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/client/Main.qc
Committed my CSQC stuff, let's see:
[divverent/nexuiz.git] / data / qcsrc / client / Main.qc
1 // --------------------------------------------------------------------------\r
2 // BEGIN REQUIRED CSQC FUNCTIONS\r
3 //include "main.qh"\r
4 \r
5 \r
6 void() menu_show_error =\r
7 {\r
8         drawstring('0 200', "ERROR - MENU IS VISIBLE BUT NO MENU WAS DEFINED!", '8 8 0', '1 0 0', 1, 0);\r
9 };\r
10 \r
11 // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load)\r
12 // Useful for precaching things\r
13 \r
14 void() menu_sub_null =\r
15 {\r
16 };\r
17 \r
18 void CSQC_Init(void)\r
19 {       \r
20         menu_visible = FALSE;\r
21         menu_show = menu_show_error;\r
22         menu_action = menu_sub_null;\r
23         //ctf_temp_1 = "";\r
24         localcmd("alias order \"cmd order $*\"");\r
25         //registercmd("ctf_menu");\r
26         registercmd("ons_map");\r
27         //registercmd("menu_action");\r
28 \r
29         gametype = 0;\r
30 \r
31         gps_start = world;\r
32 }\r
33 // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc)\r
34 void CSQC_Shutdown(void)\r
35 {\r
36 }\r
37 \r
38 // CSQC_ConsoleCommand : Used to parse commands in the console that have been registered with the "registercmd" function\r
39 // Return value should be 1 if CSQC handled the command, otherwise return 0 to have the engine handle it.\r
40 float CSQC_ConsoleCommand(string strMessage)\r
41 {\r
42         local float nReturn;\r
43                 nReturn = FALSE;\r
44                 \r
45         // Tokenize String\r
46         tokenize(strMessage);\r
47         \r
48         // Acquire Command\r
49         local string strCmd;\r
50         strCmd = argv(0);\r
51 \r
52         /*if(strCmd == "ctf_menu") {\r
53                 ctf_menu_show();\r
54                 nReturn = TRUE;\r
55                 } else*/\r
56         if(strCmd == "ons_map") {\r
57                 Cmd_ons_map();\r
58                 nReturn = TRUE;\r
59         }\r
60         \r
61         return nReturn;\r
62 }\r
63 // CSQC_InputEvent : Used to perform actions based on any key pressed, key released and mouse on the client.\r
64 // Return value should be 1 if CSQC handled the input, otherwise return 0 to have the input passed to the engine.\r
65 // All keys are in ascii.\r
66 // bInputType = 0 is key pressed, 1 is key released, 2 is mouse input.\r
67 // In the case of keyboard input, nPrimary is the ascii code, and nSecondary is 0.\r
68 // In the case of mouse input, nPrimary is xdelta, nSecondary is ydelta.\r
69 float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)\r
70 {\r
71         local float bSkipKey;\r
72         bSkipKey = false;\r
73         if(menu_visible)\r
74                 if(menu_action(bInputType, nPrimary, nSecondary))\r
75                         return TRUE;\r
76         return bSkipKey;\r
77 }\r
78 \r
79 // END REQUIRED CSQC FUNCTIONS\r
80 // --------------------------------------------------------------------------\r
81 \r
82 // --------------------------------------------------------------------------\r
83 // BEGIN OPTIONAL CSQC FUNCTIONS\r
84 \r
85 // CSQC_Ent_Update : Called every frame that the server has indicated an update to the SSQC / CSQC entity has occured.\r
86 // The only parameter reflects if the entity is "new" to the client, meaning it just came into the client's PVS.\r
87 void(float bIsNewEntity) CSQC_Ent_Update =\r
88 {\r
89         self.enttype = ReadByte();\r
90 \r
91         /*if (self.enttype == ENT_CLIENT)\r
92         {\r
93                 setmodelindex(self, ReadShort());\r
94                 self.origin_x = ReadCoord();\r
95                 self.origin_y = ReadCoord();\r
96                 self.origin_z = ReadCoord();\r
97                 self.angles_x = ReadCoord();\r
98                 self.angles_y = ReadCoord();\r
99                 self.angles_z = ReadCoord();\r
100                 self.velocity_x = ReadCoord();\r
101                 self.velocity_y = ReadCoord();\r
102                 self.velocity_z = ReadCoord();\r
103                 pmove_org = self.origin;\r
104                 pmove_vel = self.velocity;\r
105                 self.avelocity_x = ReadCoord();\r
106                 self.avelocity_y = ReadCoord();\r
107                 self.avelocity_z = ReadCoord();\r
108                 self.movetype = ReadShort();\r
109                 self.frame = ReadShort();\r
110                 self.flags = ReadShort();\r
111                 self.colormap = ReadShort();\r
112                 setorigin(self, self.origin); // relink\r
113                 if (bIsNewEntity)\r
114                 {\r
115                         setsize(self, '0 0 0', '0 0 0');\r
116                         self.drawmask = MASK_NORMAL;\r
117                         //self.think = Client_Think;\r
118                         //self.nextthink = time;\r
119                 }\r
120                 self.ctf_state = ReadByte();\r
121                 }*/\r
122         if(self.enttype == ENT_CLIENT_ENTCS)\r
123         {\r
124                 self.sv_entnum = ReadByte();\r
125                 self.origin_x = ReadCoord();\r
126                 self.origin_y = ReadCoord();\r
127                 self.angles_y = ReadCoord();\r
128                 self.origin_z = self.angles_x = self.angles_z = 0;\r
129 \r
130                 if(bIsNewEntity)\r
131                 {\r
132                         //print(strcat("Adding entity: ", ftos(self.sv_entnum), "\n"));\r
133                         self.chain = gps_start;\r
134                         gps_start = self;\r
135                 }\r
136         }\r
137         else\r
138                 error("unknown entity type in CSQC_Ent_Update\n");\r
139         \r
140 };\r
141 // CSQC_Ent_Remove : Called when the server requests a SSQC / CSQC entity to be removed.  Essentially call remove(self) as well.\r
142 void CSQC_Ent_Remove()\r
143 {\r
144         if(self.enttype == ENT_CLIENT_ENTCS)\r
145         {\r
146                 if(gps_start == self)\r
147                         gps_start = self.chain;\r
148                 else\r
149                 {\r
150                         local entity ent;\r
151                         ent = gps_start;\r
152                         \r
153                         while(ent.chain != self && ent.chain != world)\r
154                                 ent = ent.chain;\r
155                         if(ent.chain == self)\r
156                                 ent.chain = self.chain;\r
157                 }\r
158         }\r
159         remove(self);\r
160 }\r
161 \r
162 void Gamemode_Init()\r
163 {\r
164         local string mapinfo, infoline;\r
165         local float len;\r
166         local float file;\r
167         local vector mi_min, mi_max;\r
168         \r
169         gametype = cvar("gametype");\r
170         if(gametype == GAME_ONSLAUGHT) {\r
171                 if(!strcasecmp(substring(mapname, 0, 5), "maps/"))\r
172                         minimapname = substring(mapname, 5, 999);\r
173                 else\r
174                         minimapname = mapname;\r
175                 len = strlen(minimapname);\r
176                 if(!strcasecmp(substring(minimapname, len-4, 4), ".bsp"))\r
177                         minimapname = substring(minimapname, 0, len-4);\r
178                 \r
179                 mapinfo = strcat("maps/", minimapname, ".info");\r
180                 minimapname = strzone(strcat("gfx/", minimapname, "_mini.tga"));\r
181 \r
182                 mi_min = world.mins;\r
183                 mi_max = world.maxs;\r
184                 \r
185                 file = fopen(mapinfo, FILE_READ);\r
186                 if(file >= 0) {\r
187                         while((infoline = fgets(file))) {\r
188                                 if(!strncasecmp(infoline, "mins", 4)) {\r
189                                         mi_min = stov(substring(infoline, 5, 999));\r
190                                 } else if(!strncasecmp(infoline, "maxs", 4)) {\r
191                                         mi_max = stov(substring(infoline, 5, 999));\r
192                                 } else if(strncasecmp(infoline, "//", 2)) { // don't print comment-style lines\r
193                                         print(strcat("mapinfo: ", infoline, "\n"));\r
194                                 }\r
195                         }\r
196                 } else {\r
197                         print(strcat("^1Error: ^7Mapinfo file '", mapinfo, "' missing! Minimap will be screwed.\n"));\r
198                 }\r
199                 fclose(file);\r
200 \r
201                 print(strcat("Mins: ", vtos(mi_min), "    Maxs: ", vtos(mi_max), "\n"));\r
202                 \r
203                 mi_center = (mi_min + mi_max) * 0.5;\r
204                 mi_scale = mi_max - mi_min;\r
205                 \r
206                 \r
207                 print(strcat("Using ", minimapname, " as minimap.\n"));\r
208                 precache_pic(minimapname);\r
209                 precache_pic("gfx/ons-cp-neutral.tga");\r
210                 precache_pic("gfx/ons-cp-red.tga");\r
211                 precache_pic("gfx/ons-cp-blue.tga");\r
212                 precache_pic("gfx/ons-frame.tga");\r
213                 precache_pic("gfx/ons-frame-team.tga");\r
214         }\r
215 }\r
216 // CSQC_Parse_StuffCmd : Provides the stuffcmd string in the first parameter that the server provided.  To execute standard behavior, simply execute localcmd with the string.\r
217 void CSQC_Parse_StuffCmd(string strMessage)\r
218 {\r
219         localcmd(strMessage);\r
220         // watch for gametype changes!\r
221         if(gametype != cvar("gametype"))\r
222         {\r
223                 Gamemode_Init();\r
224         }\r
225 }\r
226 // CSQC_Parse_Print : Provides the print string in the first parameter that the server provided.  To execute standard behavior, simply execute print with the string.\r
227 void CSQC_Parse_Print(string strMessage)\r
228 {\r
229         print(strMessage);\r
230 }\r
231 // CSQC_Parse_CenterPrint : Provides the centerprint string in the first parameter that the server provided.  To execute standard behavior, simply execute cprint with the string.\r
232 void CSQC_Parse_CenterPrint(string strMessage)\r
233 {\r
234         cprint(strMessage);\r
235 }\r
236 // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer.\r
237 // You must ALWAYS first acquire the temporary ID, which is sent as a byte.\r
238 // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event.\r
239 float CSQC_Parse_TempEntity()\r
240 {\r
241         local float bHandled;\r
242                 bHandled  = true;\r
243         // Acquire TE ID\r
244         local float nTEID;\r
245                 nTEID = ReadByte();\r
246                 \r
247         switch(nTEID)\r
248         {\r
249                 //case TE_GUNSHOT:\r
250                 //      Do something cool with TE_GUNSHOT!\r
251                 //      break;\r
252                 default:\r
253                         // No special logic for this temporary entity; return 0 so the engine can handle it\r
254                         bHandled = false;\r
255                         break;\r
256         }\r
257                 \r
258         return bHandled;\r
259 }\r