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