Nuclide
Software Development Kit for id Tech
NSBot.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016-2023 Vera Visions LLC.
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
14 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15*/
16
17#define COST_INFINITE 99999
18
25#define BOTROUTE_DESTINATION -1
27#define BOTROUTE_END -2
28
30typedef enum
31{
36
38typedef enum
39{
46
53{
54public:
55
56 void NSBot(void);
57
58#ifdef SERVER
59 virtual void SetState(botstate_t);
60 virtual botstate_t GetState(void);
61 virtual botpersonality_t GetPersonality(void);
62
63 virtual float GetForwardSpeed(void);
64 virtual float GetSideSpeed(void);
65 virtual float GetBackSpeed(void);
66
67 virtual void ChatSay(string);
68 virtual void ChatSayTeam(string);
69 virtual void Pain(entity, entity, int, vector, int);
70 virtual void RouteClear(void);
71 virtual void WeaponThink(void);
72 virtual void WeaponAttack(void);
73 virtual void SeeThink(void);
74 virtual void BrainThink(int, int);
75 virtual void RunAI(void);
76 virtual void CreateObjective(void);
77 virtual void CheckRoute(void);
78 virtual void PreFrame(void);
79 virtual void PostFrame(void);
80 virtual void UseButton(void);
81 virtual void SetEnemy(entity);
82 virtual float GetRunSpeed(void);
83 virtual float GetWalkSpeed(void);
84 nonvirtual void ForceWeaponAttack(vector, float);
85
86 virtual void SetName(string);
87
88
90 nonvirtual void SetInfoKey(string, string);
91
93 nonvirtual void SetInfoKeyFloat(string, float);
94#endif
95
97 nonvirtual string GetInfoKey(string);
99 nonvirtual float GetInfoKeyFloat(string);
100
101#ifdef SERVER
102private:
103 /* routing */
104 float m_flLastDist;
105
106 float m_flNodeGiveup;
107 entity m_eDestination;
108
109 /* combat */
110 entity m_eTarget;
111 int m_iAttackMode;
112 float m_flAttackTime;
113
114 /* items */
115 int m_iOldItems;
116
117 /* visual */
118 float m_flSeeTime;
119
120 /* personality and state */
121 botstate_t m_bsState;
122 botpersonality_t m_bpPersonality;
123
124 /* cache, these are just here so we won't have to calc them often */
125 float m_flEnemyDist;
126 weapontype_t m_wtWeaponType;
127 vector m_vecLastPOI;
128 float m_flForceWeaponAttack;
129 vector m_vecForceWeaponAttackPos;
130#endif
131};
132
133#ifdef SERVER
135entity Bot_AddQuick(void);
136void BotLib_Init(void);
137
139void
141{
142 vector x = hsvToRGB(random() * 360, 100, 100);
143 float top = x[2] + (x[1] << 8) + (x[0] << 16);
144 x = hsvToRGB(random() * 360, 100, 100);
145 float bottom = x[2] + (x[1] << 8) + (x[0] << 16);
146 forceinfokey(target, "topcolor", sprintf("0x%x", top));
147 forceinfokey(target, "bottomcolor", sprintf("0x%x", bottom));
148}
149#endif
150 // end of bot
@ BOT_PERSONALITY_DEFENSIVE
this bot will always prefer to stay behind
Definition: NSBot.h:34
@ BOT_PERSONALITY_AGRESSIVE
this bot will always prefer to be attacking
Definition: NSBot.h:33
@ BOT_PERSONALITY_NORMAL
this bot will be dynamic
Definition: NSBot.h:32
@ BOT_STATE_IDLE
this should rarely happen
Definition: NSBot.h:40
@ BOT_STATE_DEFENDING
this is for when bots stay put and stay around spawn, or their teams goalitem
Definition: NSBot.h:42
@ BOT_STATE_FLEEING
this is for when the AI should just get as far away as possible
Definition: NSBot.h:44
@ BOT_STATE_PATROLLING
this is basically most deathmatch cases
Definition: NSBot.h:41
@ BOT_STATE_ATTACKING
this is for when bots go to the enemy spawn, or to the enemy team's goalitem
Definition: NSBot.h:43
weapontype_t
Definition: NSNavAI.h:33
This entity class represents an object with choreographed/free-form movement.
Definition: NSNavAI.h:50
A virtual multiplayer opponent.
Definition: NSBot.h:53
virtual void CheckRoute(void)
Internal use only.
Definition: NSBot.qc:188
virtual void WeaponAttack(void)
Definition: combat.qc:79
nonvirtual void SetInfoKeyFloat(string, float)
Server: Floating point based version of SetInfoKey().
Definition: NSBot.qc:541
virtual void PreFrame(void)
Definition: NSBot.qc:508
void NSBot(void)
Definition: NSBot.qc:574
nonvirtual void SetInfoKey(string, string)
Server: Set the value of an InfoKey.
Definition: NSBot.qc:535
virtual void CreateObjective(void)
Definition: NSBot.qc:283
virtual void ChatSayTeam(string)
Definition: chat.qc:24
nonvirtual void ForceWeaponAttack(vector, float)
Definition: combat.qc:135
virtual void BrainThink(int, int)
Definition: NSBot.qc:79
virtual float GetBackSpeed(void)
Overridable: Returns the desired maximum backwardss movement speed.
Definition: NSBot.qc:66
virtual void RunAI(void)
Definition: NSBot.qc:289
virtual void SetEnemy(entity)
Definition: combat.qc:47
virtual void ChatSay(string)
Definition: chat.qc:18
nonvirtual string GetInfoKey(string)
Get the string value of an InfoKey.
Definition: NSBot.qc:548
virtual float GetForwardSpeed(void)
Overridable: Returns the desired maximum forward movement speed.
Definition: NSBot.qc:54
virtual void SetName(string)
Definition: NSBot.qc:526
virtual void Pain(entity, entity, int, vector, int)
Called whenever the entity receives damage.
Definition: combat.qc:18
virtual void SetState(botstate_t)
Definition: NSBot.qc:30
virtual void PostFrame(void)
Definition: NSBot.qc:513
nonvirtual float GetInfoKeyFloat(string)
Floating point based version of GetInfoKey().
Definition: NSBot.qc:561
virtual void RouteClear(void)
When called, will wipe any memory of an ongoing route.
Definition: NSBot.qc:72
virtual float GetRunSpeed(void)
Definition: NSBot.qc:48
virtual void SeeThink(void)
Definition: NSBot.qc:123
virtual float GetSideSpeed(void)
Overridable: Returns the desired maximum side movement speed.
Definition: NSBot.qc:60
virtual botpersonality_t GetPersonality(void)
Definition: NSBot.qc:36
virtual float GetWalkSpeed(void)
Definition: NSBot.qc:42
virtual botstate_t GetState(void)
Definition: NSBot.qc:24
virtual void WeaponThink(void)
Definition: combat.qc:59
virtual void UseButton(void)
Definition: NSBot.qc:94
entity Bot_AddQuick(void)
Adds a bot to the game with some basic info.
Definition: cmd.qc:36
botpersonality_t
Bot Personality.
Definition: NSBot.h:31
void BotLib_Init(void)
Definition: NSBot.qc:626
void Bot_RandomColormap(NSBot target)
Applies random custom colors to the given bot entity.
Definition: NSBot.h:140
botstate_t
Bot State.
Definition: NSBot.h:39
vector hsvToRGB(float h, float s, float v)
Converts a Hue-Saturation-Value pair to an RGB vector.
Definition: math.h:219
string target
Definition: defs.h:23