Nuclide
Software Development Kit for id Technology (BETA)
Actor.h
1/*
2 * Copyright (c) 2016-2024 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/* TODO: serverinfo based checks for prediction reasons */
18var bool autocvar_g_infiniteAmmo = false;
19
20var bool autocvar_ai_debugNav = false;
21void
22_ncActor_Log(string className, string functionName, float edictNum, string warnMessage)
23{
24 if (autocvar_g_logTimestamps)
25 printf("^9%f ^5%s (%d) ^7: %s\n", time, functionName, edictNum, warnMessage);
26 else
27 printf("^5%s (%d) ^7: %s\n", functionName, edictNum, warnMessage);
28}
29#define ncActor_Log(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _ncActor_Log(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
30
31/* for AI identification purposes */
32typedef enum
33{
34 WPNTYPE_INVALID, /* no logic */
35 WPNTYPE_RANGED, /* will want to keep their distance mostly */
36 WPNTYPE_THROW, /* has to keep some distance, but not too far */
37 WPNTYPE_CLOSE, /* have to get really close */
38 WPNTYPE_FULLAUTO, /* for things that need to be held down */
39 WPNTYPE_SEMI /* semi automatic */
40} weapontype_t;
41
70class
72{
73
74public:
75 void ncActor(void);
76
78 virtual bool CanSprint(void);
80 virtual bool CanProne(void);
82 virtual bool CanCrouch(void);
84 virtual bool CanLean(void);
85
87 virtual float GetForwardSpeed(void);
89 virtual float GetSideSpeed(void);
91 virtual float GetBackSpeed(void);
92
93
94 nonvirtual float GetStamina(void);
95
97 nonvirtual bool IsCrouching(void);
99 nonvirtual bool IsProne(void);
101 nonvirtual bool IsStanding(void);
103 nonvirtual bool IsSprinting(void);
105 nonvirtual bool IsLeaning(void);
106
107 /* ammo handling */
109 nonvirtual bool MaxAmmo(int);
111 nonvirtual bool GiveAmmo(int, int);
113 nonvirtual bool UseAmmo(int, int);
115 nonvirtual bool HasAmmo(int, int);
117 nonvirtual int GetReserveAmmo(int);
118
119 /* inventory handling */
121 nonvirtual bool GiveItem(string);
123 nonvirtual bool RemoveItem(string);
125 nonvirtual bool AddItem(ncItem);
127 nonvirtual bool HasItem(string);
129 nonvirtual bool HasExactItem(ncItem);
131 nonvirtual bool RemoveAllItems(bool);
133 nonvirtual bool RemoveAllWeapons(void);
135 nonvirtual string GetCurrentWeapon(void);
137 nonvirtual void SwitchToWeapon(string);
139 nonvirtual void SwitchToExactWeapon(ncWeapon);
140 nonvirtual void SwitchToBestWeapon(bool);
141
142 nonvirtual void LaunchProjectile(string, bool, float);
143 nonvirtual bool PlantCharge(string);
144
146 virtual ncWeapon SortWeaponChain(void);
148 nonvirtual ncWeapon GetNextWeapon(void);
150 nonvirtual ncWeapon GetPreviousWeapon(void);
152 nonvirtual ncWeapon GetLastWeapon(void);
153
154 virtual void AddedItemCallback(ncItem);
155 virtual void SpawnKey(string,string);
156
157#ifdef SERVER
158 /* overrides */
159 virtual void Save(float);
160 virtual void Restore(string,string);
161 virtual void RestoreComplete(void);
162 virtual void Spawned(void);
163 virtual void Input(entity, string, string);
164 virtual void DebugDraw(void);
165
167 virtual void SelectNewSchedule(void);
168 nonvirtual void ScheduleThink(void);
169
171 nonvirtual bool CancelSchedule(void);
172 nonvirtual void PerformSchedule(string);
173 nonvirtual void MessageSchedule(string);
174 nonvirtual bool IsPerforming(void);
175
176 /* methods we'd like others to override */
178 virtual bool CanCrouch(void);
180 nonvirtual vector GetRouteMovevalues(void);
182 nonvirtual vector GetRouteDirection(void);
184 nonvirtual void SetMoveSpeedScale(float);
186 nonvirtual float GetMoveSpeedScale(void);
187
189 virtual void RouteEnded(void);
191 virtual void RouteClear(void);
193 virtual void CheckRouteProgression(void);
195 virtual void RouteToPosition(vector);
197 virtual void RouteToPositionDenyFlags(vector, int);
199 virtual void ChasePath(string startPath);
201 virtual void CheckRouteProgression_Path(void);
203 virtual void Physics_Run(void);
204#endif
205
206private:
207#ifdef SERVER
208 /* pathfinding */
209 int m_iNodes;
210 int m_iCurNode;
211 nodeslist_t *m_pRoute;
212 vector m_vecLastNode;
213 vector m_vecTurnAngle;
214 string m_pathTarget;
215 ncEntity m_pathEntity;
216 float _m_flRouteGiveUp;
217 vector _m_vecRoutePrev;
218 vector m_vecRouteEntity;
219 entity m_eFollowing;
220 float m_flMoveSpeedKey;
221 string m_mindset;
222#endif
223
224 /* sounds, may even be predicted. */
225 string m_sndStepLadderLeft;
226 string m_sndStepLadderRight;
227 string m_sndDeath;
228 string m_sndFall;
229 string m_sndPainSmall;
230 string m_sndPainMedium;
231 string m_sndPainLarge;
232 string m_sndPainHuge;
233 string m_sndLandSoft;
234 string m_sndLandHard;
235 string m_sndHitArmor;
236 string m_sndHitFlesh;
237 string m_sndAirGaspHeavy;
238 string m_sndAirGaspLight;
239 string m_sndNoAir;
240 string m_sndTeleportExit;
241 string m_sndTeleportStart;
242 string m_sndWaterExit;
243 string m_sndWaterEnter;
244 string m_sndWaterWade;
245 string m_sndWaterSwim;
246 string m_sndBurn;
247 string m_sndHealthtake;
248 string m_sndUseDeny;
249 string m_sndUseSuccess;
250
251 float nadeCookingTime;
252 /* These are defined in side defs\*.def, ammo_types and ammo_names */
253 int m_iAmmoTypes[MAX_AMMO_TYPES];
254 ncWeapon m_activeWeapon_net;
255 float activeweapon;
256 NETWORKED_FLOAT(m_flFirstInventoryItem)
257 NETWORKED_FLOAT(m_flStamina)
258};
259
260/* for now here to make debugging easier */
261.ncItem m_itemList;
262.ncWeapon m_activeWeapon;
263.ncWeapon m_firstWeapon;
264
265void ncActor_ListInventory(ncActor);
266
This entity class represents an object with choreographed/free-form movement.
Definition: Actor.h:72
virtual bool CanCrouch(void)
Returns if this class is capable of crouching.
ncEntity is the lowest of the user-accessible entity class.
Definition: Entity.h:54
This entity class represents inventory items, weapons.
Definition: Item.h:67
This entity represents an ncRenderableEntity with interactive surface properties.
Definition: SurfacePropEntity.h:52
This entity class represents weapon based items.
Definition: Weapon.h:170
void ncWeapon(void)
Definition: Weapon.qc:18