Nuclide
Software Development Kit for id Technology
NSBot.h
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{
32 BOT_PERSONALITY_NORMAL,
33 BOT_PERSONALITY_AGRESSIVE,
34 BOT_PERSONALITY_DEFENSIVE
36
38typedef enum
39{
40 BOT_STATE_IDLE,
41 BOT_STATE_PATROLLING,
42 BOT_STATE_DEFENDING,
43 BOT_STATE_ATTACKING,
44 BOT_STATE_FLEEING
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, 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 BotPreFrame(void);
79 virtual void BotPostFrame(void);
80 virtual void AddedItemCallback(NSItem);
81 virtual void UseButton(void);
82 virtual void SetEnemy(entity);
83 virtual float GetRunSpeed(void);
84 virtual float GetWalkSpeed(void);
85 nonvirtual void ForceWeaponAttack(vector, float);
86
87 virtual void SetName(string);
88
89
91 nonvirtual void SetInfoKey(string, string);
92
94 nonvirtual void SetInfoKeyFloat(string, float);
95#endif
96
98 nonvirtual string GetInfoKey(string);
100 nonvirtual float GetInfoKeyFloat(string);
101
102#ifdef SERVER
103private:
104 /* routing */
105 float m_flLastDist;
106
107 float m_flNodeGiveup;
108 entity m_eDestination;
109
110 /* combat */
111 entity m_eTarget;
112 int m_iAttackMode;
113 float m_flAttackTime;
114
115 /* items */
116 int m_iOldItems;
117
118 /* visual */
119 float m_flSeeTime;
120
121 /* personality and state */
122 botstate_t m_bsState;
123 botpersonality_t m_bpPersonality;
124
125 /* cache, these are just here so we won't have to calc them often */
126 float m_flEnemyDist;
127 weapontype_t m_wtWeaponType;
128 vector m_vecLastPOI;
129 float m_flForceWeaponAttack;
130 vector m_vecForceWeaponAttackPos;
131#endif
132};
133
134#ifdef SERVER
136entity Bot_AddQuick(void);
137void BotLib_Init(void);
138
140void
142{
143 vector x = hsvToRGB(random() * 360, 100, 100);
144 float top = x[2] + (x[1] << 8) + (x[0] << 16);
145 x = hsvToRGB(random() * 360, 100, 100);
146 float bottom = x[2] + (x[1] << 8) + (x[0] << 16);
147 forceinfokey(target, "topcolor", sprintf("0x%x", top));
148 forceinfokey(target, "bottomcolor", sprintf("0x%x", bottom));
149}
150#endif
151 // end of bot
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 AddedItemCallback(NSItem)
Definition: NSBot.qc:518
virtual void WeaponAttack(void)
Definition: combat.qc:77
nonvirtual void SetInfoKeyFloat(string, float)
Server: Floating point based version of SetInfoKey().
Definition: NSBot.qc:543
void NSBot(void)
Definition: NSBot.qc:576
nonvirtual void SetInfoKey(string, string)
Server: Set the value of an InfoKey.
Definition: NSBot.qc:537
virtual void CreateObjective(void)
Definition: NSBot.qc:283
virtual void ChatSayTeam(string)
Definition: chat.qc:24
virtual void Pain(entity, entity, int, vector, vector, int)
Called whenever the entity receives damage.
Definition: combat.qc:18
nonvirtual void ForceWeaponAttack(vector, float)
Definition: combat.qc:133
virtual void BrainThink(int, int)
Definition: NSBot.qc:79
virtual void BotPostFrame(void)
Definition: NSBot.qc:513
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:550
virtual float GetForwardSpeed(void)
Overridable: Returns the desired maximum forward movement speed.
Definition: NSBot.qc:54
virtual void SetName(string)
Definition: NSBot.qc:528
virtual void SetState(botstate_t)
Definition: NSBot.qc:30
virtual void BotPreFrame(void)
Definition: NSBot.qc:508
nonvirtual float GetInfoKeyFloat(string)
Floating point based version of GetInfoKey().
Definition: NSBot.qc:563
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
This entity class represents inventory items, weapons.
Definition: NSItem.h:67
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:628
void Bot_RandomColormap(NSBot target)
Applies random custom colors to the given bot entity.
Definition: NSBot.h:141
botstate_t
Bot State.
Definition: NSBot.h:39