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
18#define ACTOR_LOG imageToConsole("gfx/icon16/eye", ICN_SIZE, "Actor Log")
19
20/* TODO: serverinfo based checks for prediction reasons */
21var int autocvar_g_infiniteAmmo = 0i;
22var bool autocvar_ai_debugNav = false;
23
24void
25_ncActor_Log(string className, string functionName, float edictNum, string warnMessage)
26{
27 if (autocvar_g_logTimestamps)
28 printf("%s ^9%f ^5%s (%d) ^7: %s\n", ACTOR_LOG, time, functionName, edictNum, warnMessage);
29 else
30 printf("%s ^5%s (%d) ^7: %s\n", ACTOR_LOG, functionName, edictNum, warnMessage);
31}
32#define ncActor_Log(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _ncActor_Log(classname, __FUNC__, num_for_edict(this), sprintf(__VA_ARGS__))
33
34/* for AI identification purposes */
35typedef enum
36{
37 WPNTYPE_INVALID, /* no logic */
38 WPNTYPE_RANGED, /* will want to keep their distance mostly */
39 WPNTYPE_THROW, /* has to keep some distance, but not too far */
40 WPNTYPE_CLOSE, /* have to get really close */
41 WPNTYPE_FULLAUTO, /* for things that need to be held down */
42 WPNTYPE_SEMI /* semi automatic */
43} weapontype_t;
44
91class
93{
94
95public:
96 void ncActor(void);
97
99 virtual bool CanSprint(void);
101 virtual bool CanProne(void);
103 virtual bool CanCrouch(void);
105 virtual bool CanLean(void);
106
108 virtual float GetForwardSpeed(void);
110 virtual float GetSideSpeed(void);
112 virtual float GetBackSpeed(void);
113
114
115 nonvirtual float GetStamina(void);
116
118 nonvirtual bool IsCrouching(void);
120 nonvirtual bool IsProne(void);
122 nonvirtual bool IsStanding(void);
124 nonvirtual bool IsSprinting(void);
126 nonvirtual bool IsLeaning(void);
127
128 /* ammo handling */
130 nonvirtual bool MaxAmmo(int);
132 nonvirtual bool GiveAmmo(int, int);
134 nonvirtual bool UseAmmo(int, int);
136 nonvirtual bool HasAmmo(int, int);
138 nonvirtual int GetReserveAmmo(int);
139
140 /* inventory handling */
142 nonvirtual bool GiveNamedItem(string);
144 nonvirtual bool GiveExactItem(ncItem);
146 nonvirtual bool RemoveItem(ncItem);
148 nonvirtual bool RemoveNamedItem(string);
150 nonvirtual ncItem GetItem(string);
152 nonvirtual bool HasItem(string);
154 nonvirtual bool HasExactItem(ncItem);
156 nonvirtual bool RemoveAllItems(bool);
158 nonvirtual bool RemoveAllWeapons(void);
160 nonvirtual bool RemoveWeaponInSlot(int);
161
163 nonvirtual ncItem DropWeaponInSlot(int);
165 nonvirtual ncItem DropCurrentWeapon(void);
166
167 nonvirtual ncItem DropItem(ncItem);
168 nonvirtual ncItem DropNamedItem(string);
169
171 nonvirtual string GetCurrentWeapon(void);
173 nonvirtual void SwitchToWeapon(string);
175 nonvirtual void SwitchToExactWeapon(ncWeapon);
176 nonvirtual void SwitchToBestWeapon(bool);
177
178 nonvirtual void LaunchProjectile(string, bool, float);
179 nonvirtual bool PlantCharge(string);
180
182 virtual ncWeapon SortWeaponChain(void);
184 nonvirtual ncWeapon GetNextWeapon(void);
186 nonvirtual ncWeapon GetPreviousWeapon(void);
188 nonvirtual ncWeapon GetLastWeapon(void);
189
190 virtual void AddedItemCallback(ncItem);
191 virtual void SpawnKey(string,string);
192 virtual void ReloadCachedAttributes(void);
193 virtual void SetAnimationPrefix(string animPrefix);
194
195#ifdef CLIENT
196 virtual void ReceiveEvent(float eventID);
197#endif
198
199#ifdef SERVER
200 /* overrides */
201 virtual void Save(float);
202 virtual void Restore(string,string);
203 virtual void RestoreComplete(void);
204 virtual void Respawn(void);
205 virtual void Spawned(void);
206 virtual void Input(entity, string, string);
207 virtual void DebugDraw(void);
208 virtual void OnRemoveEntity(void);
209 virtual void Pain(entity inflictor, entity attacker, int damagePoints, vector dir, vector absImpactPos, int hitBody);
210 virtual void Death(entity inflictor, entity attacker, int damagePoints, vector dir, vector absImpactPos, int hitBody);
211
213 virtual void SelectNewSchedule(void);
214 nonvirtual void ThinkSchedules(void);
215
217 nonvirtual bool CancelSchedule(void);
218 nonvirtual void PerformSchedule(string);
219 nonvirtual void MessageSchedule(string);
220 nonvirtual bool IsPerforming(void);
221
222 nonvirtual int PathNodeCount(void);
223 nonvirtual int PathCurrentNode(void);
224 nonvirtual vector PathDestination(void);
225
227 nonvirtual ncEntity MakeCorpse(float deathSequence);
228
229 /* methods we'd like others to override */
231 virtual bool CanCrouch(void);
233 nonvirtual vector GetRouteMovevalues(void);
235 nonvirtual vector GetRouteDirection(void);
237 nonvirtual void SetMoveSpeedScale(float);
239 nonvirtual float GetMoveSpeedScale(void);
240
242 virtual void RouteEnded(void);
244 virtual void RouteClear(void);
246 virtual void CheckRouteProgression(void);
248 virtual void RouteToPosition(vector);
250 virtual void RouteToPositionDenyFlags(vector, int);
252 virtual void ChasePath(string startPath);
254 virtual void CheckRouteProgression_Path(void);
256 virtual void Physics_Run(void);
257#endif
258
259 virtual void FiredWeapon(string, string);
260 nonvirtual void __FiredWeapon(string, string);
261
262 virtual void Event_DrawWeapon(void);
263 virtual void Event_FireWeapon(void);
264 virtual void Event_ReloadWeaponStart(void);
265 virtual void Event_ReloadWeapon(void);
266 virtual void Event_ReloadWeaponEnd(void);
267 virtual void Event_HolsterWeapon(void);
268
269
270
271private:
272
273
274 nonvirtual float __ActForPrefix(string actName, string animPrefix, string emotionString);
275
276#ifdef SERVER
277 bool m_pvsSleep;
278
279 /* pathfinding */
280 int m_pathfindingNodeCount;
281 int m_pathfindingCurrentNode;
282 nodeslist_t *m_pathfindingGraph;
283 vector m_pathfindingDestination;
284 string m_pathTarget;
285 ncEntity m_pathEntity;
286 float m_timeUntilDroppingRoute;
287 vector m_pathfindingLastPos;
288 entity m_followingEntity;
289 float m_moveSpeedKey;
290 string m_mindset;
291 entity m_hook;
292#endif
293
294 /* These are defined in side defs\*.def, ammo_types and ammo_names */
295 int m_ammoTypes[MAX_AMMO_TYPES];
296 float activeweapon;
297 NETWORKED_FLOAT(m_itemStart)
298 NETWORKED_FLOAT(m_currentStamina)
299 float m_weaponCookingTime;
300
301 /* networking/prediction */
302 ncWeapon m_activeWeapon_net;
303
304 /* non-state heavy cached values, reloaded frequently. */
305 ncSoundDict m_sndStepLadderLeft;
306 ncSoundDict m_sndStepLadderRight;
307 ncSoundDict m_sndDeath;
308 ncSoundDict m_sndFall;
309 ncSoundDict m_sndPainSmall;
310 ncSoundDict m_sndPainMedium;
311 ncSoundDict m_sndPainLarge;
312 ncSoundDict m_sndPainHuge;
313 ncSoundDict m_sndLandSoft;
314 ncSoundDict m_sndLandHard;
315 ncSoundDict m_sndHitArmor;
316 ncSoundDict m_sndHitFlesh;
317 ncSoundDict m_sndAirGaspHeavy;
318 ncSoundDict m_sndAirGaspLight;
319 ncSoundDict m_sndNoAir;
320 ncSoundDict m_sndTeleportExit;
321 ncSoundDict m_sndTeleportStart;
322 ncSoundDict m_sndWaterExit;
323 ncSoundDict m_sndWaterEnter;
324 ncSoundDict m_sndWaterWade;
325 ncSoundDict m_sndWaterSwim;
326 ncSoundDict m_sndBurn;
327 ncSoundDict m_sndHealthtake;
328 ncSoundDict m_sndUseDeny;
329 ncSoundDict m_sndUseSuccess;
330 ncSoundDict m_sndJump;
331
332 /* recalculate these */
333 float m_actIdle;
334 float m_actIdleCrouch;
335 float m_actIdleProne;
336 float m_actWalk;
337 float m_actWalkCrouch;
338 float m_actWalkProne;
339 float m_actRun;
340 float m_actJump;
341 float m_actAim;
342 float m_actDraw;
343 float m_actAttack;
344 float m_actReloadStart;
345 float m_actReload;
346 float m_actReloadEnd;
347 float m_actHolster;
348 int m_boneSpine;
349 int m_torsoFirst;
350 int m_torsoLast;
351 int m_torsoTwistYaw;
352 int m_gibHealth;
353 entity m_lastCorpse;
354
355 /* taken from player, makes sense though */
356 float m_timeUnderwater;
357};
358
359/* for now here to make debugging easier */
360.ncItem m_itemList;
361.ncWeapon m_activeWeapon;
362.ncWeapon m_firstWeapon;
363.bool _isActor;
364
365void ncActor_ListInventory(ncActor);
This entity class represents an object with choreographed/free-form movement.
Definition: Actor.h:93
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:75
This entity class represents inventory items, weapons.
Definition: Item.h:138
Dictionary for sound effect definition.
Definition: SoundDict.h:39
This entity represents an ncRenderableEntity with interactive surface properties.
Definition: SurfacePropEntity.h:70
This entity class represents weapon based items.
Definition: Weapon.h:305
void ncWeapon(void)
Definition: Weapon.qc:18