1 /*
2 ===========================================================================
3 Copyright (C) 1999-2005 Id Software, Inc.
4 Copyright (C) 2000-2006 Tim Angus
5 
6 This file is part of Tremulous.
7 
8 Tremulous is free software; you can redistribute it
9 and/or modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
12 
13 Tremulous is distributed in the hope that it will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Tremulous; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21 ===========================================================================
22 */
23 
24 /*****************************************************************************
25  * name:		be_ea.c
26  *
27  * desc:		elementary actions
28  *
29  * $Archive: /MissionPack/code/botlib/be_ea.c $
30  *
31  *****************************************************************************/
32 
33 #include "../qcommon/q_shared.h"
34 #include "l_memory.h"
35 #include "l_script.h"
36 #include "l_precomp.h"
37 #include "l_struct.h"
38 #include "botlib.h"
39 #include "be_interface.h"
40 
41 #define MAX_USERMOVE				400
42 #define MAX_COMMANDARGUMENTS		10
43 #define ACTION_JUMPEDLASTFRAME		128
44 
45 bot_input_t *botinputs;
46 
47 //===========================================================================
48 //
49 // Parameter:				-
50 // Returns:					-
51 // Changes Globals:		-
52 //===========================================================================
EA_Say(int client,char * str)53 void EA_Say(int client, char *str)
54 {
55 	botimport.BotClientCommand(client, va("say %s", str) );
56 } //end of the function EA_Say
57 //===========================================================================
58 //
59 // Parameter:				-
60 // Returns:					-
61 // Changes Globals:		-
62 //===========================================================================
EA_SayTeam(int client,char * str)63 void EA_SayTeam(int client, char *str)
64 {
65 	botimport.BotClientCommand(client, va("say_team %s", str));
66 } //end of the function EA_SayTeam
67 //===========================================================================
68 //
69 // Parameter:				-
70 // Returns:					-
71 // Changes Globals:		-
72 //===========================================================================
EA_Tell(int client,int clientto,char * str)73 void EA_Tell(int client, int clientto, char *str)
74 {
75 	botimport.BotClientCommand(client, va("tell %d, %s", clientto, str));
76 } //end of the function EA_SayTeam
77 //===========================================================================
78 //
79 // Parameter:				-
80 // Returns:					-
81 // Changes Globals:		-
82 //===========================================================================
EA_UseItem(int client,char * it)83 void EA_UseItem(int client, char *it)
84 {
85 	botimport.BotClientCommand(client, va("use %s", it));
86 } //end of the function EA_UseItem
87 //===========================================================================
88 //
89 // Parameter:				-
90 // Returns:					-
91 // Changes Globals:		-
92 //===========================================================================
EA_DropItem(int client,char * it)93 void EA_DropItem(int client, char *it)
94 {
95 	botimport.BotClientCommand(client, va("drop %s", it));
96 } //end of the function EA_DropItem
97 //===========================================================================
98 //
99 // Parameter:				-
100 // Returns:					-
101 // Changes Globals:		-
102 //===========================================================================
EA_UseInv(int client,char * inv)103 void EA_UseInv(int client, char *inv)
104 {
105 	botimport.BotClientCommand(client, va("invuse %s", inv));
106 } //end of the function EA_UseInv
107 //===========================================================================
108 //
109 // Parameter:			-
110 // Returns:				-
111 // Changes Globals:		-
112 //===========================================================================
EA_DropInv(int client,char * inv)113 void EA_DropInv(int client, char *inv)
114 {
115 	botimport.BotClientCommand(client, va("invdrop %s", inv));
116 } //end of the function EA_DropInv
117 //===========================================================================
118 //
119 // Parameter:			-
120 // Returns:				-
121 // Changes Globals:		-
122 //===========================================================================
EA_Gesture(int client)123 void EA_Gesture(int client)
124 {
125 	bot_input_t *bi;
126 
127 	bi = &botinputs[client];
128 
129 	bi->actionflags |= ACTION_GESTURE;
130 } //end of the function EA_Gesture
131 //===========================================================================
132 //
133 // Parameter:				-
134 // Returns:					-
135 // Changes Globals:		-
136 //===========================================================================
EA_Command(int client,char * command)137 void EA_Command(int client, char *command)
138 {
139 	botimport.BotClientCommand(client, command);
140 } //end of the function EA_Command
141 //===========================================================================
142 //
143 // Parameter:			-
144 // Returns:				-
145 // Changes Globals:		-
146 //===========================================================================
EA_SelectWeapon(int client,int weapon)147 void EA_SelectWeapon(int client, int weapon)
148 {
149 	bot_input_t *bi;
150 
151 	bi = &botinputs[client];
152 
153 	bi->weapon = weapon;
154 } //end of the function EA_SelectWeapon
155 //===========================================================================
156 //
157 // Parameter:			-
158 // Returns:				-
159 // Changes Globals:		-
160 //===========================================================================
EA_Attack(int client)161 void EA_Attack(int client)
162 {
163 	bot_input_t *bi;
164 
165 	bi = &botinputs[client];
166 
167 	bi->actionflags |= ACTION_ATTACK;
168 } //end of the function EA_Attack
169 //===========================================================================
170 //
171 // Parameter:			-
172 // Returns:				-
173 // Changes Globals:		-
174 //===========================================================================
EA_Talk(int client)175 void EA_Talk(int client)
176 {
177 	bot_input_t *bi;
178 
179 	bi = &botinputs[client];
180 
181 	bi->actionflags |= ACTION_TALK;
182 } //end of the function EA_Talk
183 //===========================================================================
184 //
185 // Parameter:			-
186 // Returns:				-
187 // Changes Globals:		-
188 //===========================================================================
EA_Use(int client)189 void EA_Use(int client)
190 {
191 	bot_input_t *bi;
192 
193 	bi = &botinputs[client];
194 
195 	bi->actionflags |= ACTION_USE;
196 } //end of the function EA_Use
197 //===========================================================================
198 //
199 // Parameter:			-
200 // Returns:				-
201 // Changes Globals:		-
202 //===========================================================================
EA_Respawn(int client)203 void EA_Respawn(int client)
204 {
205 	bot_input_t *bi;
206 
207 	bi = &botinputs[client];
208 
209 	bi->actionflags |= ACTION_RESPAWN;
210 } //end of the function EA_Respawn
211 //===========================================================================
212 //
213 // Parameter:			-
214 // Returns:				-
215 // Changes Globals:		-
216 //===========================================================================
EA_Jump(int client)217 void EA_Jump(int client)
218 {
219 	bot_input_t *bi;
220 
221 	bi = &botinputs[client];
222 
223 	if (bi->actionflags & ACTION_JUMPEDLASTFRAME)
224 	{
225 		bi->actionflags &= ~ACTION_JUMP;
226 	} //end if
227 	else
228 	{
229 		bi->actionflags |= ACTION_JUMP;
230 	} //end if
231 } //end of the function EA_Jump
232 //===========================================================================
233 //
234 // Parameter:			-
235 // Returns:				-
236 // Changes Globals:		-
237 //===========================================================================
EA_DelayedJump(int client)238 void EA_DelayedJump(int client)
239 {
240 	bot_input_t *bi;
241 
242 	bi = &botinputs[client];
243 
244 	if (bi->actionflags & ACTION_JUMPEDLASTFRAME)
245 	{
246 		bi->actionflags &= ~ACTION_DELAYEDJUMP;
247 	} //end if
248 	else
249 	{
250 		bi->actionflags |= ACTION_DELAYEDJUMP;
251 	} //end if
252 } //end of the function EA_DelayedJump
253 //===========================================================================
254 //
255 // Parameter:			-
256 // Returns:				-
257 // Changes Globals:		-
258 //===========================================================================
EA_Crouch(int client)259 void EA_Crouch(int client)
260 {
261 	bot_input_t *bi;
262 
263 	bi = &botinputs[client];
264 
265 	bi->actionflags |= ACTION_CROUCH;
266 } //end of the function EA_Crouch
267 //===========================================================================
268 //
269 // Parameter:			-
270 // Returns:				-
271 // Changes Globals:		-
272 //===========================================================================
EA_Walk(int client)273 void EA_Walk(int client)
274 {
275 	bot_input_t *bi;
276 
277 	bi = &botinputs[client];
278 
279 	bi->actionflags |= ACTION_WALK;
280 } //end of the function EA_Walk
281 //===========================================================================
282 //
283 // Parameter:			-
284 // Returns:				-
285 // Changes Globals:		-
286 //===========================================================================
EA_Action(int client,int action)287 void EA_Action(int client, int action)
288 {
289 	bot_input_t *bi;
290 
291 	bi = &botinputs[client];
292 
293 	bi->actionflags |= action;
294 } //end of function EA_Action
295 //===========================================================================
296 //
297 // Parameter:			-
298 // Returns:				-
299 // Changes Globals:		-
300 //===========================================================================
EA_MoveUp(int client)301 void EA_MoveUp(int client)
302 {
303 	bot_input_t *bi;
304 
305 	bi = &botinputs[client];
306 
307 	bi->actionflags |= ACTION_MOVEUP;
308 } //end of the function EA_MoveUp
309 //===========================================================================
310 //
311 // Parameter:			-
312 // Returns:				-
313 // Changes Globals:		-
314 //===========================================================================
EA_MoveDown(int client)315 void EA_MoveDown(int client)
316 {
317 	bot_input_t *bi;
318 
319 	bi = &botinputs[client];
320 
321 	bi->actionflags |= ACTION_MOVEDOWN;
322 } //end of the function EA_MoveDown
323 //===========================================================================
324 //
325 // Parameter:			-
326 // Returns:				-
327 // Changes Globals:		-
328 //===========================================================================
EA_MoveForward(int client)329 void EA_MoveForward(int client)
330 {
331 	bot_input_t *bi;
332 
333 	bi = &botinputs[client];
334 
335 	bi->actionflags |= ACTION_MOVEFORWARD;
336 } //end of the function EA_MoveForward
337 //===========================================================================
338 //
339 // Parameter:			-
340 // Returns:				-
341 // Changes Globals:		-
342 //===========================================================================
EA_MoveBack(int client)343 void EA_MoveBack(int client)
344 {
345 	bot_input_t *bi;
346 
347 	bi = &botinputs[client];
348 
349 	bi->actionflags |= ACTION_MOVEBACK;
350 } //end of the function EA_MoveBack
351 //===========================================================================
352 //
353 // Parameter:			-
354 // Returns:				-
355 // Changes Globals:		-
356 //===========================================================================
EA_MoveLeft(int client)357 void EA_MoveLeft(int client)
358 {
359 	bot_input_t *bi;
360 
361 	bi = &botinputs[client];
362 
363 	bi->actionflags |= ACTION_MOVELEFT;
364 } //end of the function EA_MoveLeft
365 //===========================================================================
366 //
367 // Parameter:			-
368 // Returns:				-
369 // Changes Globals:		-
370 //===========================================================================
EA_MoveRight(int client)371 void EA_MoveRight(int client)
372 {
373 	bot_input_t *bi;
374 
375 	bi = &botinputs[client];
376 
377 	bi->actionflags |= ACTION_MOVERIGHT;
378 } //end of the function EA_MoveRight
379 //===========================================================================
380 //
381 // Parameter:			-
382 // Returns:				-
383 // Changes Globals:		-
384 //===========================================================================
EA_Move(int client,vec3_t dir,float speed)385 void EA_Move(int client, vec3_t dir, float speed)
386 {
387 	bot_input_t *bi;
388 
389 	bi = &botinputs[client];
390 
391 	VectorCopy(dir, bi->dir);
392 	//cap speed
393 	if (speed > MAX_USERMOVE) speed = MAX_USERMOVE;
394 	else if (speed < -MAX_USERMOVE) speed = -MAX_USERMOVE;
395 	bi->speed = speed;
396 } //end of the function EA_Move
397 //===========================================================================
398 //
399 // Parameter:			-
400 // Returns:				-
401 // Changes Globals:		-
402 //===========================================================================
EA_View(int client,vec3_t viewangles)403 void EA_View(int client, vec3_t viewangles)
404 {
405 	bot_input_t *bi;
406 
407 	bi = &botinputs[client];
408 
409 	VectorCopy(viewangles, bi->viewangles);
410 } //end of the function EA_View
411 //===========================================================================
412 //
413 // Parameter:			-
414 // Returns:				-
415 // Changes Globals:		-
416 //===========================================================================
EA_EndRegular(int client,float thinktime)417 void EA_EndRegular(int client, float thinktime)
418 {
419 /*
420 	bot_input_t *bi;
421 	int jumped = qfalse;
422 
423 	bi = &botinputs[client];
424 
425 	bi->actionflags &= ~ACTION_JUMPEDLASTFRAME;
426 
427 	bi->thinktime = thinktime;
428 	botimport.BotInput(client, bi);
429 
430 	bi->thinktime = 0;
431 	VectorClear(bi->dir);
432 	bi->speed = 0;
433 	jumped = bi->actionflags & ACTION_JUMP;
434 	bi->actionflags = 0;
435 	if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME;
436 */
437 } //end of the function EA_EndRegular
438 //===========================================================================
439 //
440 // Parameter:			-
441 // Returns:				-
442 // Changes Globals:		-
443 //===========================================================================
EA_GetInput(int client,float thinktime,bot_input_t * input)444 void EA_GetInput(int client, float thinktime, bot_input_t *input)
445 {
446 	bot_input_t *bi;
447 //	int jumped = qfalse;
448 
449 	bi = &botinputs[client];
450 
451 //	bi->actionflags &= ~ACTION_JUMPEDLASTFRAME;
452 
453 	bi->thinktime = thinktime;
454 	Com_Memcpy(input, bi, sizeof(bot_input_t));
455 
456 	/*
457 	bi->thinktime = 0;
458 	VectorClear(bi->dir);
459 	bi->speed = 0;
460 	jumped = bi->actionflags & ACTION_JUMP;
461 	bi->actionflags = 0;
462 	if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME;
463 	*/
464 } //end of the function EA_GetInput
465 //===========================================================================
466 //
467 // Parameter:			-
468 // Returns:				-
469 // Changes Globals:		-
470 //===========================================================================
EA_ResetInput(int client)471 void EA_ResetInput(int client)
472 {
473 	bot_input_t *bi;
474 	int jumped = qfalse;
475 
476 	bi = &botinputs[client];
477 	bi->actionflags &= ~ACTION_JUMPEDLASTFRAME;
478 
479 	bi->thinktime = 0;
480 	VectorClear(bi->dir);
481 	bi->speed = 0;
482 	jumped = bi->actionflags & ACTION_JUMP;
483 	bi->actionflags = 0;
484 	if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME;
485 } //end of the function EA_ResetInput
486 //===========================================================================
487 //
488 // Parameter:			-
489 // Returns:				-
490 // Changes Globals:		-
491 //===========================================================================
EA_Setup(void)492 int EA_Setup(void)
493 {
494 	//initialize the bot inputs
495 	botinputs = (bot_input_t *) GetClearedHunkMemory(
496 									botlibglobals.maxclients * sizeof(bot_input_t));
497 	return BLERR_NOERROR;
498 } //end of the function EA_Setup
499 //===========================================================================
500 //
501 // Parameter:			-
502 // Returns:				-
503 // Changes Globals:		-
504 //===========================================================================
EA_Shutdown(void)505 void EA_Shutdown(void)
506 {
507 	FreeMemory(botinputs);
508 	botinputs = NULL;
509 } //end of the function EA_Shutdown
510