520 lines
14 KiB
C++
520 lines
14 KiB
C++
|
|
||
|
/*****************************************************************************
|
||
|
* name: be_ea.c
|
||
|
*
|
||
|
* desc: elementary actions
|
||
|
*
|
||
|
* $Archive: /MissionPack/code/botlib/be_ea.c $
|
||
|
* $Author: Zaphod $
|
||
|
* $Revision: 5 $
|
||
|
* $Modtime: 11/22/00 8:50a $
|
||
|
* $Date: 11/22/00 8:55a $
|
||
|
*
|
||
|
*****************************************************************************/
|
||
|
|
||
|
#include "../game/q_shared.h"
|
||
|
#include "l_memory.h"
|
||
|
#include "l_script.h"
|
||
|
#include "l_precomp.h"
|
||
|
#include "l_struct.h"
|
||
|
#include "../game/botlib.h"
|
||
|
#include "be_interface.h"
|
||
|
|
||
|
#define MAX_USERMOVE 400
|
||
|
#define MAX_COMMANDARGUMENTS 10
|
||
|
#define ACTION_JUMPEDLASTFRAME 0x0800000//128
|
||
|
|
||
|
bot_input_t *botinputs;
|
||
|
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Say(int client, char *str)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, va("say %s", str) );
|
||
|
} //end of the function EA_Say
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_SayTeam(int client, char *str)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, va("say_team %s", str));
|
||
|
} //end of the function EA_SayTeam
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Tell(int client, int clientto, char *str)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, va("tell %d, %s", clientto, str));
|
||
|
} //end of the function EA_SayTeam
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_UseItem(int client, char *it)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, va("use %s", it));
|
||
|
} //end of the function EA_UseItem
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_DropItem(int client, char *it)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, va("drop %s", it));
|
||
|
} //end of the function EA_DropItem
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_UseInv(int client, char *inv)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, va("invuse %s", inv));
|
||
|
} //end of the function EA_UseInv
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_DropInv(int client, char *inv)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, va("invdrop %s", inv));
|
||
|
} //end of the function EA_DropInv
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Gesture(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_GESTURE;
|
||
|
} //end of the function EA_Gesture
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Command(int client, char *command)
|
||
|
{
|
||
|
botimport.BotClientCommand(client, command);
|
||
|
} //end of the function EA_Command
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_SelectWeapon(int client, int weapon)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->weapon = weapon;
|
||
|
} //end of the function EA_SelectWeapon
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Attack(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_ATTACK;
|
||
|
} //end of the function EA_Attack
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Alt_Attack(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_ALT_ATTACK;
|
||
|
} //end of the function EA_Alt_Attack
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_ForcePower(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_FORCEPOWER;
|
||
|
} //end of the function EA_ForcePower
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Talk(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_TALK;
|
||
|
} //end of the function EA_Talk
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Use(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_USE;
|
||
|
} //end of the function EA_Use
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Respawn(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_RESPAWN;
|
||
|
} //end of the function EA_Respawn
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Jump(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
if (bi->actionflags & ACTION_JUMPEDLASTFRAME)
|
||
|
{
|
||
|
bi->actionflags &= ~ACTION_JUMP;
|
||
|
} //end if
|
||
|
else
|
||
|
{
|
||
|
bi->actionflags |= ACTION_JUMP;
|
||
|
} //end if
|
||
|
} //end of the function EA_Jump
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_DelayedJump(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
if (bi->actionflags & ACTION_JUMPEDLASTFRAME)
|
||
|
{
|
||
|
bi->actionflags &= ~ACTION_DELAYEDJUMP;
|
||
|
} //end if
|
||
|
else
|
||
|
{
|
||
|
bi->actionflags |= ACTION_DELAYEDJUMP;
|
||
|
} //end if
|
||
|
} //end of the function EA_DelayedJump
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Crouch(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_CROUCH;
|
||
|
} //end of the function EA_Crouch
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Walk(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_WALK;
|
||
|
} //end of the function EA_Walk
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Action(int client, int action)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= action;
|
||
|
} //end of function EA_Action
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_MoveUp(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_MOVEUP;
|
||
|
} //end of the function EA_MoveUp
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_MoveDown(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_MOVEDOWN;
|
||
|
} //end of the function EA_MoveDown
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_MoveForward(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_MOVEFORWARD;
|
||
|
} //end of the function EA_MoveForward
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_MoveBack(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_MOVEBACK;
|
||
|
} //end of the function EA_MoveBack
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_MoveLeft(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_MOVELEFT;
|
||
|
} //end of the function EA_MoveLeft
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_MoveRight(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags |= ACTION_MOVERIGHT;
|
||
|
} //end of the function EA_MoveRight
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Move(int client, vec3_t dir, float speed)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
VectorCopy(dir, bi->dir);
|
||
|
//cap speed
|
||
|
if (speed > MAX_USERMOVE) speed = MAX_USERMOVE;
|
||
|
else if (speed < -MAX_USERMOVE) speed = -MAX_USERMOVE;
|
||
|
bi->speed = speed;
|
||
|
} //end of the function EA_Move
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_View(int client, vec3_t viewangles)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
VectorCopy(viewangles, bi->viewangles);
|
||
|
} //end of the function EA_View
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_EndRegular(int client, float thinktime)
|
||
|
{
|
||
|
/*
|
||
|
bot_input_t *bi;
|
||
|
int jumped = qfalse;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
bi->actionflags &= ~ACTION_JUMPEDLASTFRAME;
|
||
|
|
||
|
bi->thinktime = thinktime;
|
||
|
botimport.BotInput(client, bi);
|
||
|
|
||
|
bi->thinktime = 0;
|
||
|
VectorClear(bi->dir);
|
||
|
bi->speed = 0;
|
||
|
jumped = bi->actionflags & ACTION_JUMP;
|
||
|
bi->actionflags = 0;
|
||
|
if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME;
|
||
|
*/
|
||
|
} //end of the function EA_EndRegular
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_GetInput(int client, float thinktime, bot_input_t *input)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
// int jumped = qfalse;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
|
||
|
// bi->actionflags &= ~ACTION_JUMPEDLASTFRAME;
|
||
|
|
||
|
bi->thinktime = thinktime;
|
||
|
Com_Memcpy(input, bi, sizeof(bot_input_t));
|
||
|
|
||
|
/*
|
||
|
bi->thinktime = 0;
|
||
|
VectorClear(bi->dir);
|
||
|
bi->speed = 0;
|
||
|
jumped = bi->actionflags & ACTION_JUMP;
|
||
|
bi->actionflags = 0;
|
||
|
if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME;
|
||
|
*/
|
||
|
} //end of the function EA_GetInput
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_ResetInput(int client)
|
||
|
{
|
||
|
bot_input_t *bi;
|
||
|
int jumped = qfalse;
|
||
|
|
||
|
bi = &botinputs[client];
|
||
|
bi->actionflags &= ~ACTION_JUMPEDLASTFRAME;
|
||
|
|
||
|
bi->thinktime = 0;
|
||
|
VectorClear(bi->dir);
|
||
|
bi->speed = 0;
|
||
|
jumped = bi->actionflags & ACTION_JUMP;
|
||
|
bi->actionflags = 0;
|
||
|
if (jumped) bi->actionflags |= ACTION_JUMPEDLASTFRAME;
|
||
|
} //end of the function EA_ResetInput
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
int EA_Setup(void)
|
||
|
{
|
||
|
//initialize the bot inputs
|
||
|
botinputs = (bot_input_t *) GetClearedHunkMemory(
|
||
|
botlibglobals.maxclients * sizeof(bot_input_t));
|
||
|
return BLERR_NOERROR;
|
||
|
} //end of the function EA_Setup
|
||
|
//===========================================================================
|
||
|
//
|
||
|
// Parameter: -
|
||
|
// Returns: -
|
||
|
// Changes Globals: -
|
||
|
//===========================================================================
|
||
|
void EA_Shutdown(void)
|
||
|
{
|
||
|
FreeMemory(botinputs);
|
||
|
botinputs = NULL;
|
||
|
} //end of the function EA_Shutdown
|