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
20#define BOTROUTE_DESTINATION -1
22#define BOTROUTE_END -2
23
25typedef enum
26{
31
33typedef enum
34{
41
45{
46public:
47
48 void(void) NSBot;
49
50#ifdef SERVER
51 virtual void(botstate_t) SetState;
52 virtual botstate_t(void) GetState;
53 virtual botpersonality_t(void) GetPersonality;
54
55 virtual float GetForwardSpeed(void);
56 virtual float GetSideSpeed(void);
57 virtual float GetBackSpeed(void);
58
59 virtual void(string) ChatSay;
60 virtual void(string) ChatSayTeam;
61 virtual void(void) Pain;
62 virtual void(void) RouteClear;
63 virtual void(void) WeaponThink;
64 virtual void(void) WeaponAttack;
65 virtual void(void) SeeThink;
66 virtual void(int, int) BrainThink;
67 virtual void(void) RunAI;
68 virtual void(void) CreateObjective;
69 virtual void(void) CheckRoute;
70 virtual void(void) PreFrame;
71 virtual void(void) PostFrame;
72 virtual void(void) UseButton;
73 virtual void(entity) SetEnemy;
74 virtual float(void) GetRunSpeed;
75 virtual float(void) GetWalkSpeed;
76 nonvirtual void ForceWeaponAttack(vector, float);
77
78 virtual void(string) SetName;
79
80
82 nonvirtual void SetInfoKey(string, string);
83
85 nonvirtual void SetInfoKeyFloat(string, float);
86#endif
87
89 nonvirtual string GetInfoKey(string);
91 nonvirtual float GetInfoKeyFloat(string);
92
93#ifdef SERVER
94private:
95 /* routing */
96 int m_iNodes;
97 int m_iCurNode;
98 nodeslist_t *m_pRoute;
99 float m_flNodeGiveup;
100 float m_flLastDist;
101 entity m_eDestination;
102 vector m_vecLastNode;
103
104 /* combat */
105 entity m_eTarget;
106 int m_iAttackMode;
107 float m_flAttackTime;
108
109 /* items */
110 int m_iOldItems;
111
112 /* visual */
113 float m_flSeeTime;
114
115 /* personality and state */
116 botstate_t m_bsState;
117 botpersonality_t m_bpPersonality;
118
119 /* cache, these are just here so we won't have to calc them often */
120 float m_flEnemyDist;
121 weapontype_t m_wtWeaponType;
122 vector m_vecLastPOI;
123 float m_flForceWeaponAttack;
124 vector m_vecForceWeaponAttackPos;
125#endif
126};
127
128#ifdef SERVER
130entity Bot_AddQuick(void);
131void BotLib_Init(void);
132
134void
136{
137 vector x = hsvToRGB(random() * 360, 100, 100);
138 float top = x[2] + (x[1] << 8) + (x[0] << 16);
139 x = hsvToRGB(random() * 360, 100, 100);
140 float bottom = x[2] + (x[1] << 8) + (x[0] << 16);
141 forceinfokey(target, "topcolor", sprintf("0x%x", top));
142 forceinfokey(target, "bottomcolor", sprintf("0x%x", bottom));
143}
144#endif
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:26
@ BOT_PERSONALITY_DEFENSIVE
this bot will always prefer to stay behind
Definition: NSBot.h:29
@ BOT_PERSONALITY_AGRESSIVE
this bot will always prefer to be attacking
Definition: NSBot.h:28
@ BOT_PERSONALITY_NORMAL
this bot will be dynamic
Definition: NSBot.h:27
void BotLib_Init(void)
Definition: NSBot.qc:630
void Bot_RandomColormap(NSBot target)
Applies random custom colors to the given bot entity.
Definition: NSBot.h:135
botstate_t
Bot State.
Definition: NSBot.h:34
@ BOT_STATE_IDLE
this should rarely happen
Definition: NSBot.h:35
@ BOT_STATE_DEFENDING
this is for when bots stay put and stay around spawn, or their teams goalitem
Definition: NSBot.h:37
@ BOT_STATE_FLEEING
this is for when the AI should just get as far away as possible
Definition: NSBot.h:39
@ BOT_STATE_PATROLLING
this is basically most deathmatch cases
Definition: NSBot.h:36
@ BOT_STATE_ATTACKING
this is for when bots go to the enemy spawn, or to the enemy team's goalitem
Definition: NSBot.h:38
weapontype_t
Definition: NSNavAI.h:35
A virtual multiplayer opponent.
Definition: NSBot.h:45
virtual void(string) SetName
virtual void(void) CreateObjective
nonvirtual void SetInfoKeyFloat(string, float)
Server: Floating point based version of SetInfoKey().
Definition: NSBot.qc:541
virtual void(int, int) BrainThink
nonvirtual void SetInfoKey(string, string)
Server: Set the value of an InfoKey.
Definition: NSBot.qc:535
virtual float(void) GetRunSpeed
virtual void(void) Pain
virtual void(void) WeaponThink
virtual void(void) RouteClear
virtual void(botstate_t) SetState
nonvirtual void ForceWeaponAttack(vector, float)
Definition: combat.qc:135
virtual void(string) ChatSayTeam
virtual float(void) GetWalkSpeed
virtual float GetBackSpeed(void)
Overridable: Returns the desired maximum backwardss movement speed.
Definition: NSBot.qc:66
virtual void(string) ChatSay
virtual void(void) PreFrame
virtual botstate_t(void) GetState
virtual void(void) WeaponAttack
nonvirtual string GetInfoKey(string)
Get the string value of an InfoKey.
Definition: NSBot.qc:548
virtual void(void) CheckRoute
virtual float GetForwardSpeed(void)
Overridable: Returns the desired maximum forward movement speed.
Definition: NSBot.qc:54
virtual void(void) RunAI
virtual void(void) SeeThink
virtual void(entity) SetEnemy
nonvirtual float GetInfoKeyFloat(string)
Floating point based version of GetInfoKey().
Definition: NSBot.qc:561
virtual float GetSideSpeed(void)
Overridable: Returns the desired maximum side movement speed.
Definition: NSBot.qc:60
virtual void(void) UseButton
virtual void(void) PostFrame
void(void) NSBot
virtual botpersonality_t(void) GetPersonality
This entity class represents a moving/pathfinding object.
Definition: NSNavAI.h:50
virtual void RouteClear(void)
When called, will wipe any memory of an ongoing route.
Definition: NSNavAI.qc:458
virtual void CheckRoute(void)
Internal use only.
Definition: NSNavAI.qc:181
virtual void Pain(void)
Called whenever the entity receives damage.
Definition: NSSurfacePropEntity.qc:419
vector(vector) normalize
entity() spawn
string target
Definition: defs.h:23
vector hsvToRGB(float h, float s, float v)
Converts a Hue-Saturation-Value pair to an RGB vector.
Definition: math.h:213