Nuclide
Software Development Kit for id Technology (BETA)
Loading...
Searching...
No Matches
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 GiveItem(string);
143 nonvirtual bool GiveExactItem(ncItem);
145 nonvirtual bool RemoveItem(string);
147 nonvirtual bool AddItem(ncItem);
149 nonvirtual ncItem GetItem(string);
151 nonvirtual bool HasItem(string);
153 nonvirtual bool HasExactItem(ncItem);
155 nonvirtual bool RemoveAllItems(bool);
157 nonvirtual bool RemoveAllWeapons(void);
159 nonvirtual bool RemoveWeaponInSlot(int);
161 nonvirtual bool DropWeaponInSlot(int);
163 nonvirtual string GetCurrentWeapon(void);
165 nonvirtual void SwitchToWeapon(string);
167 nonvirtual void SwitchToExactWeapon(ncWeapon);
168 nonvirtual void SwitchToBestWeapon(bool);
169
170 nonvirtual void LaunchProjectile(string, bool, float);
171 nonvirtual bool PlantCharge(string);
172
174 virtual ncWeapon SortWeaponChain(void);
176 nonvirtual ncWeapon GetNextWeapon(void);
178 nonvirtual ncWeapon GetPreviousWeapon(void);
180 nonvirtual ncWeapon GetLastWeapon(void);
181
182 virtual void AddedItemCallback(ncItem);
183 virtual void SpawnKey(string,string);
184 virtual void ReloadCachedAttributes(void);
185 virtual void SetAnimationPrefix(string animPrefix);
186
187#ifdef CLIENT
188 virtual void ReceiveEvent(float eventID);
189#endif
190
191#ifdef SERVER
192 /* overrides */
193 virtual void Save(float);
194 virtual void Restore(string,string);
195 virtual void RestoreComplete(void);
196 virtual void Respawn(void);
197 virtual void Spawned(void);
198 virtual void Input(entity, string, string);
199 virtual void DebugDraw(void);
200 virtual void OnRemoveEntity(void);
201 virtual void Death(entity inflictor, entity attacker, int damagePoints, vector dir, vector absImpactPos, int hitBody);
202
204 virtual void SelectNewSchedule(void);
205 nonvirtual void ThinkSchedules(void);
206
208 nonvirtual bool CancelSchedule(void);
209 nonvirtual void PerformSchedule(string);
210 nonvirtual void MessageSchedule(string);
211 nonvirtual bool IsPerforming(void);
212
213 nonvirtual int PathNodeCount(void);
214 nonvirtual int PathCurrentNode(void);
215 nonvirtual vector PathDestination(void);
216
218 nonvirtual ncEntity MakeCorpse(float deathSequence);
219
220 /* methods we'd like others to override */
222 virtual bool CanCrouch(void);
224 nonvirtual vector GetRouteMovevalues(void);
226 nonvirtual vector GetRouteDirection(void);
228 nonvirtual void SetMoveSpeedScale(float);
230 nonvirtual float GetMoveSpeedScale(void);
231
233 virtual void RouteEnded(void);
235 virtual void RouteClear(void);
237 virtual void CheckRouteProgression(void);
239 virtual void RouteToPosition(vector);
241 virtual void RouteToPositionDenyFlags(vector, int);
243 virtual void ChasePath(string startPath);
245 virtual void CheckRouteProgression_Path(void);
247 virtual void Physics_Run(void);
248#endif
249
250 virtual void FiredWeapon(string, string);
251 nonvirtual void __FiredWeapon(string, string);
252
253 virtual void Event_DrawWeapon(void);
254 virtual void Event_FireWeapon(void);
255 virtual void Event_ReloadWeaponStart(void);
256 virtual void Event_ReloadWeapon(void);
257 virtual void Event_ReloadWeaponEnd(void);
258 virtual void Event_HolsterWeapon(void);
259
260
261
262private:
263
264
265 nonvirtual float __ActForPrefix(string actName, string animPrefix, string emotionString);
266
267#ifdef SERVER
268 bool m_pvsSleep;
269
270 /* pathfinding */
271 int m_pathfindingNodeCount;
272 int m_pathfindingCurrentNode;
273 nodeslist_t *m_pathfindingGraph;
274 vector m_pathfindingDestination;
275 string m_pathTarget;
276 ncEntity m_pathEntity;
277 float m_timeUntilDroppingRoute;
278 vector m_pathfindingLastPos;
279 entity m_followingEntity;
280 float m_moveSpeedKey;
281 string m_mindset;
282 entity m_hook;
283#endif
284
285 /* These are defined in side defs\*.def, ammo_types and ammo_names */
286 int m_ammoTypes[MAX_AMMO_TYPES];
287 float activeweapon;
288 NETWORKED_FLOAT(m_itemStart)
289 NETWORKED_FLOAT(m_currentStamina)
290 float m_weaponCookingTime;
291
292 /* networking/prediction */
293 ncWeapon m_activeWeapon_net;
294
295 /* non-state heavy cached values, reloaded frequently. */
296 string m_sndStepLadderLeft;
297 string m_sndStepLadderRight;
298 string m_sndDeath;
299 string m_sndFall;
300 string m_sndPainSmall;
301 string m_sndPainMedium;
302 string m_sndPainLarge;
303 string m_sndPainHuge;
304 string m_sndLandSoft;
305 string m_sndLandHard;
306 string m_sndHitArmor;
307 string m_sndHitFlesh;
308 string m_sndAirGaspHeavy;
309 string m_sndAirGaspLight;
310 string m_sndNoAir;
311 string m_sndTeleportExit;
312 string m_sndTeleportStart;
313 string m_sndWaterExit;
314 string m_sndWaterEnter;
315 string m_sndWaterWade;
316 string m_sndWaterSwim;
317 string m_sndBurn;
318 string m_sndHealthtake;
319 string m_sndUseDeny;
320 string m_sndUseSuccess;
321 string m_sndJump;
322
323 /* recalculate these */
324 float m_actIdle;
325 float m_actIdleCrouch;
326 float m_actIdleProne;
327 float m_actWalk;
328 float m_actWalkCrouch;
329 float m_actWalkProne;
330 float m_actRun;
331 float m_actJump;
332 float m_actAim;
333 float m_actDraw;
334 float m_actAttack;
335 float m_actReloadStart;
336 float m_actReload;
337 float m_actReloadEnd;
338 float m_actHolster;
339 int m_boneSpine;
340 int m_torsoFirst;
341 int m_torsoLast;
342 int m_torsoTwistYaw;
343};
344
345/* for now here to make debugging easier */
346.ncItem m_itemList;
347.ncWeapon m_activeWeapon;
348.ncWeapon m_firstWeapon;
349.bool _isActor;
350
351void ncActor_ListInventory(ncActor);
This entity class represents an object with choreographed/free-form movement.
Definition Actor.h:93
nonvirtual bool AddItem(ncItem)
Adds the specified ncItem to the inventory.
Definition Actor.qc:1957
virtual void FiredWeapon(string, string)
Definition Actor.qc:115
nonvirtual int PathCurrentNode(void)
Definition Actor.qc:627
virtual void Restore(string, string)
Similar to ncIO::SpawnKey() but for save-game fields.
Definition Actor.qc:379
virtual void Event_DrawWeapon(void)
Definition Actor.qc:122
virtual bool CanProne(void)
Overridable: Returns whether the client can prone, with the commands +prone and goprone.
Definition Actor.qc:305
virtual void SetAnimationPrefix(string animPrefix)
Definition Actor.qc:71
virtual void Respawn(void)
Server: Called when the entity first spawns or when game-logic requests the entity to return to its o...
Definition Actor.qc:578
virtual void Event_FireWeapon(void)
Definition Actor.qc:128
virtual void SelectNewSchedule(void)
Overridable: Called regularily to select a new schedule to perform.
Definition Actor.qc:555
nonvirtual bool CancelSchedule(void)
Forces a named schedule to be performed.
Definition Actor.qc:586
nonvirtual float GetMoveSpeedScale(void)
Returns the movement speed scale.
Definition Actor.qc:1217
nonvirtual int PathNodeCount(void)
Definition Actor.qc:621
virtual void CheckRouteProgression_Path(void)
Internal use only.
Definition Actor.qc:838
nonvirtual bool RemoveItem(string)
Removes a named ncItem from the inventory Returns false when impossible.
Definition Actor.qc:1759
nonvirtual bool IsLeaning(void)
Returns true when the entity is leaning.
Definition Actor.qc:293
nonvirtual bool UseAmmo(int, int)
Uses ammo up of a specified type.
Definition Actor.qc:1372
nonvirtual ncItem GetItem(string)
Returns true or false depending on if the entity has the named item.
Definition Actor.qc:1440
virtual void AddedItemCallback(ncItem)
Definition Actor.qc:1477
virtual void RestoreComplete(void)
Called when the entity has been successfully restored from a savegame file.
Definition Actor.qc:527
virtual void Input(entity, string, string)
Called when we are being prompted by another object/function with an input message.
Definition Actor.qc:663
virtual void Event_ReloadWeapon(void)
Definition Actor.qc:138
virtual void Event_ReloadWeaponStart(void)
Definition Actor.qc:133
virtual void DebugDraw(void)
Definition Actor.qc:1083
nonvirtual void SwitchToWeapon(string)
Switches the entity to use the desired weapon.
Definition Actor.qc:1916
virtual bool CanCrouch(void)
Returns if this class is capable of crouching.
nonvirtual bool RemoveAllWeapons(void)
Removes all weapons from the inventory.
Definition Actor.qc:1867
nonvirtual bool RemoveAllItems(bool)
Removes all items from the inventory.
Definition Actor.qc:1823
nonvirtual void ThinkSchedules(void)
Definition Actor.qc:547
nonvirtual bool HasExactItem(ncItem)
Returns true or false depending on if the entity has the exact item.
Definition Actor.qc:1404
nonvirtual float GetStamina(void)
Definition Actor.qc:263
nonvirtual ncWeapon GetNextWeapon(void)
Retrieve the 'next' weapon in the inventory, sorted by SortWeaponChain().
Definition Actor.qc:2078
virtual void ReceiveEvent(float eventID)
Definition Actor.qc:156
virtual void OnRemoveEntity(void)
Handles what happens before the entity gets removed from the client game.
Definition Actor.qc:1185
virtual void Save(float)
Handles saving a copy of this entity to a given filehandle.
Definition Actor.qc:343
nonvirtual bool HasAmmo(int, int)
Returns whether or not the entity has enough of the specified ammo and type.
Definition Actor.qc:1388
nonvirtual vector PathDestination(void)
Definition Actor.qc:633
nonvirtual bool DropWeaponInSlot(int)
Drops the first item in someones specified inventory slot, placing it into the world in front of them...
Definition Actor.qc:1730
virtual bool CanCrouch(void)
Overridable: Returns whether the client can crouch, with the commands +crouch and gocrouch.
Definition Actor.qc:317
virtual void RouteToPositionDenyFlags(vector, int)
When called, will plot a route to a given world coordinate and start moving, ignoring any links that ...
Definition Actor.qc:1107
nonvirtual void SwitchToBestWeapon(bool)
Definition Actor.qc:1645
nonvirtual ncWeapon GetLastWeapon(void)
Retrieve the 'last' weapon they had chosen.
Definition Actor.qc:2106
nonvirtual bool HasItem(string)
Returns true or false depending on if the entity has the named item.
Definition Actor.qc:1471
virtual void Spawned(void)
Called when the entity is fulled initialized.
Definition Actor.qc:457
nonvirtual bool GiveItem(string)
Adds a named ncItem to the inventory.
Definition Actor.qc:1565
virtual void ReloadCachedAttributes(void)
Shared: Called on launch/reload to read variables from defaults.
Definition Actor.qc:180
nonvirtual vector GetRouteDirection(void)
Returns the current movement direction.
Definition Actor.qc:1046
nonvirtual bool RemoveWeaponInSlot(int)
Removes the first item in someones specified inventory slot.
Definition Actor.qc:1701
virtual bool CanSprint(void)
Overridable: Returns whether the client can sprint, with the command +sprint.
Definition Actor.qc:299
virtual void Event_HolsterWeapon(void)
Definition Actor.qc:148
virtual float GetBackSpeed(void)
Overridable: Returns the desired maximum backwardss movement speed.
Definition Actor.qc:336
virtual bool CanLean(void)
Overridable: Returns whether the client can lean, with the commands +leanleft and +leanright.
Definition Actor.qc:311
nonvirtual bool GiveAmmo(int, int)
Gives ammo up of a specified type.
Definition Actor.qc:1345
virtual void Physics_Run(void)
Overridable: Called when the entity is ready to move.
Definition Actor.qc:1223
nonvirtual bool MaxAmmo(int)
Returns whether the specified type is maxed out.
Definition Actor.qc:1319
nonvirtual void __FiredWeapon(string, string)
Definition Actor.qc:167
nonvirtual ncWeapon GetPreviousWeapon(void)
Retrieve the 'previous' weapon in the inventory, sorted by SortWeaponChain().
Definition Actor.qc:2092
virtual void RouteClear(void)
When called, will wipe any memory of an ongoing route.
Definition Actor.qc:1193
virtual void Death(entity inflictor, entity attacker, int damagePoints, vector dir, vector absImpactPos, int hitBody)
Called when the health is equal or below 0.
Definition Actor.qc:540
nonvirtual bool IsPerforming(void)
Definition Actor.qc:572
virtual void ChasePath(string startPath)
When called, will start following a path_corner.
Definition Actor.qc:1171
nonvirtual void PerformSchedule(string)
Definition Actor.qc:608
nonvirtual int GetReserveAmmo(int)
Returns the amount of reserve ammo of a given type.
Definition Actor.qc:1308
virtual void RouteEnded(void)
Called when the object is done moving to its destination.
Definition Actor.qc:832
nonvirtual string GetCurrentWeapon(void)
Returns the name of the current weapon.
Definition Actor.qc:1906
nonvirtual bool PlantCharge(string)
Definition Actor.qc:1267
nonvirtual bool IsCrouching(void)
Returns true when the entity is ducked/crouching.
Definition Actor.qc:269
virtual void SpawnKey(string, string)
This method handles entity key/value pairs on map load.
Definition Actor.qc:254
nonvirtual void LaunchProjectile(string, bool, float)
Definition Actor.qc:1239
nonvirtual vector GetRouteMovevalues(void)
Returns the current movement values in a single vector (x = fwd, y = rt, y = up)
Definition Actor.qc:1009
nonvirtual bool IsStanding(void)
Returns true when the entity is standing, walking.
Definition Actor.qc:281
nonvirtual void SwitchToExactWeapon(ncWeapon)
Switches the entity to use the desired weapon.
Definition Actor.qc:1945
nonvirtual void MessageSchedule(string)
Definition Actor.qc:599
virtual float GetSideSpeed(void)
Overridable: Returns the desired maximum side movement speed.
Definition Actor.qc:330
virtual void Event_ReloadWeaponEnd(void)
Definition Actor.qc:143
nonvirtual void SetMoveSpeedScale(float)
Sets the scale on the movement before physics are run.
Definition Actor.qc:1211
nonvirtual ncEntity MakeCorpse(float deathSequence)
Call to make a corpse of this actor.
Definition Actor.qc:639
virtual float GetForwardSpeed(void)
Overridable: Returns the desired maximum forward movement speed.
Definition Actor.qc:324
nonvirtual bool IsProne(void)
Returns true when the entity is ducked/crouching.
Definition Actor.qc:275
nonvirtual bool IsSprinting(void)
Returns true when the entity is running.
Definition Actor.qc:287
nonvirtual bool GiveExactItem(ncItem)
Definition Actor.qc:1489
void ncActor(void)
Definition Actor.qc:18
virtual ncWeapon SortWeaponChain(void)
Returns the first weapon in the chain, while ensuring the inventory is sorted.
Definition Actor.qc:1963
virtual void RouteToPosition(vector)
When called, will plot a route to a given world coordinate and start moving.
Definition Actor.qc:1077
virtual void CheckRouteProgression(void)
Internal use only.
Definition Actor.qc:860
void ncEntity(void)
The constructor.
Definition Entity.qc:29
This entity class represents inventory items, weapons.
Definition Item.h:138
void ncSurfacePropEntity(void)
Definition SurfacePropEntity.qc:18
This entity class represents weapon based items.
Definition Weapon.h:305