Nuclide
Software Development Kit for id Tech
entities.h
Go to the documentation of this file.
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
18typedef enum
19{
41 ENT_FOG, /*<< of type env_fog */
42 ENT_STEAM, /*<< of type env_steam */
44 ENT_CASCADELIGHT, /*<< of type env_cascade_light */
67
68
72Entity_FindClosest(entity startTarget, string className)
73{
74 entity best = world;
75 float bestdist;
76 float dist;
77
78 bestdist = 9999999;
79
80 for (entity e = world; (e = find(e, classname, className));) {
81 dist = vlen(startTarget.origin - e.origin);
82
83 if (dist < bestdist) {
84 bestdist = dist;
85 best = e;
86 }
87 }
88
89 return best;
90}
91
92
96Entity_SelectRandom(string className)
97{
98 entity spot = world;
99 int max = 0i;
100
101 /* count the total number of entities of the desired class */
102 for (entity e = world; (e = find(e, ::classname, className));) {
103 max++;
104 }
105
106 /* immediately exit out if we've got none */
107 if (max < 1i) {
108 NSError("%S is not present on this map.", className);
109 return __NULL__;
110 }
111
112 /* select a random point */
113 for (int i = random(1, max); i > 0; i--) {
114 spot = find(spot, ::classname, className);
115 }
116
117 /* we might end up not finding anything, wrap around? */
118 if (spot == __NULL__) {
119 spot = find(spot, ::classname, className);
120 }
121
122 /* we should have returned something valid now */
123 return spot;
124}
entupdate_t
Entity update identifiers.
Definition: entities.h:19
@ ENT_SPRITE
of type env_sprite
Definition: entities.h:47
@ ENT_GLOW
of type env_glow
Definition: entities.h:48
@ ENT_MONITOR
of type func_monitor
Definition: entities.h:52
@ ENT_PARTSYSTEM
of type info_particle_system
Definition: entities.h:46
@ ENT_ENTITY
of type NSEntity
Definition: entities.h:21
@ ENT_CASCADELIGHT
Definition: entities.h:44
@ ENT_NONE
invalid, but reserved.
Definition: entities.h:20
@ ENT_SPECTATOR
of type NSClientSpectator
Definition: entities.h:32
@ ENT_TALKMONSTER
of type NSTalkMonster
Definition: entities.h:28
@ ENT_SPRAY
of type spray
Definition: entities.h:49
@ ENT_VEH_TANKMORTAR
of type func_tankmortar
Definition: entities.h:56
@ ENT_WEAPON
of type NSWeapon
Definition: entities.h:31
@ ENT_PORTAL
of type NSPortal
Definition: entities.h:33
@ ENT_SURFPROP
of type NSSurfacePropEntity
Definition: entities.h:25
@ ENT_PROJECTEDTEXTURE
of type env_projectedtexture
Definition: entities.h:39
@ ENT_SPEAKER
of type speaker
Definition: entities.h:29
@ ENT_OLDCAMERA
of type trigger_camera
Definition: entities.h:51
@ ENT_FOG
Definition: entities.h:41
@ ENT_FOGCONTROLLER
of type env_fog_controller
Definition: entities.h:43
@ ENT_STEAM
Definition: entities.h:42
@ ENT_SEPARATOR
This is a separator.
Definition: entities.h:65
@ ENT_LASER
of type env_laser
Definition: entities.h:45
@ ENT_FUNNEL
of type env_funnel
Definition: entities.h:36
@ ENT_VEHICLE
Reserved.
Definition: entities.h:53
@ ENT_PUSH
of type trigger_push
Definition: entities.h:64
@ ENT_SMOKER
of type env_smoker
Definition: entities.h:37
@ ENT_TRACKTRAIN
of type func_tracktrain
Definition: entities.h:54
@ ENT_DLIGHT
of type light_dynamic
Definition: entities.h:38
@ ENT_AMBIENTSOUND
of type ambient_generic
Definition: entities.h:34
@ ENT_VEH_BRUSH
of type func_vehicle
Definition: entities.h:55
@ ENT_WAYPOINT
of type info_waypoint
Definition: entities.h:62
@ ENT_PROPROPE
of type prop_rope
Definition: entities.h:58
@ ENT_PHYSICS
of type NSPhysicsEntity
Definition: entities.h:26
@ ENT_BEAM
of type env_beam
Definition: entities.h:35
@ ENT_ENTITYPROJECTILE
of type NSProjectile
Definition: entities.h:24
@ ENT_INSTRUCTOR
of type env_instructor_hint
Definition: entities.h:63
@ ENT_SPOTLIGHT
of type point_spotlight
Definition: entities.h:40
@ ENT_PLAYER
of type NSClientPlayer
Definition: entities.h:30
@ ENT_PHYSROPE
of type phys_rope
Definition: entities.h:59
@ ENT_ENTITYRENDERABLE
of type NSPMoveVars
Definition: entities.h:23
@ ENT_PMOVEVARS
Definition: entities.h:22
@ ENT_MONSTER
of type NSMonster
Definition: entities.h:27
@ ENT_CONVEYOR
of type func_conveyor
Definition: entities.h:61
@ ENT_DECAL
of type infodecal
Definition: entities.h:50
@ ENT_BUBBLES
of type env_bubbles
Definition: entities.h:60
@ ENT_VEH_4WHEEL
of type prop_vehicle_driveable
Definition: entities.h:57
entity Entity_FindClosest(entity startTarget, string className)
Returns the closest point entity of a given classname.
Definition: entities.h:72
entity Entity_SelectRandom(string className)
Returns a random entity of a given classname.
Definition: entities.h:96
entity() spawn
get __int i
Definition: fteextensions.qc:3826
#define NSError(...)
Logs an error message, with timestamp.
Definition: global.h:75
string classname
Definition: ui.qc:342