Nuclide
Software Development Kit for id Technology (BETA)
entities.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/* used to keep track of decl across different classnames */
18.string declclass;
19.string spawnclass;
20
36typedef enum
37{
109
110
113entity
114Entity_FindClosest(entity startTarget, string className)
115{
116 entity best = world;
117 float bestdist;
118 float dist;
119
120 bestdist = 9999999;
121
122 for (entity e = world; (e = find(e, classname, className));) {
123 dist = vlen(startTarget.origin - e.origin);
124
125 if (dist < bestdist) {
126 bestdist = dist;
127 best = e;
128 }
129 }
130
131 return best;
132}
133
134
137entity
138Entity_SelectRandom(string className)
139{
140 entity spot = world;
141 int max = 0i;
142
143 /* count the total number of entities of the desired class */
144 for (entity e = world; (e = find(e, ::classname, className));) {
145 max++;
146 }
147
148 /* immediately exit out if we've got none */
149 if (max < 1i) {
150 ncError("%S is not present on this map.", className);
151 return __NULL__;
152 }
153
154 /* select a random point */
155 for (int i = random(1, max); i > 0; i--) {
156 spot = find(spot, ::classname, className);
157 }
158
159 /* we might end up not finding anything, wrap around? */
160 if (spot == __NULL__) {
161 spot = find(spot, ::classname, className);
162 }
163
164 /* we should have returned something valid now */
165 return spot;
166}
167
168 // end of entities
entupdate_t
Entity update identifiers.
Definition: entities.h:37
entity Entity_FindClosest(entity startTarget, string className)
Returns the closest point entity of a given classname.
Definition: entities.h:114
entity Entity_SelectRandom(string className)
Returns a random entity of a given classname.
Definition: entities.h:138
@ ENT_TVCHANNEL
of type ncAVTransmitter
Definition: entities.h:100
@ ENT_SPRITE
of type env_sprite
Definition: entities.h:70
@ ENT_RAGDOLL
of type ncRagdoll
Definition: entities.h:53
@ ENT_SPRAYVIDEO
of type ncSprayVideo
Definition: entities.h:73
@ ENT_GLOW
of type env_glow
Definition: entities.h:71
@ ENT_MONITOR
of type func_monitor
Definition: entities.h:82
@ ENT_PARTSYSTEM
of type info_particle_system
Definition: entities.h:69
@ ENT_XTERMINAL
of type ncXTerminal
Definition: entities.h:104
@ ENT_AVRECEIVER
of type ncAVReceiver
Definition: entities.h:101
@ ENT_ENTITY
of type ncEntity
Definition: entities.h:39
@ ENT_MEDIASOURCE
of type ncMediaSource
Definition: entities.h:79
@ ENT_CASCADELIGHT
of type env_cascade_light
Definition: entities.h:67
@ ENT_NONE
invalid, but reserved.
Definition: entities.h:38
@ ENT_INPUTDEVICE
of type ncInputDevice
Definition: entities.h:105
@ ENT_SPECTATOR
of type ncSpectator
Definition: entities.h:54
@ ENT_TALKMONSTER
of type ncTalkMonster
Definition: entities.h:48
@ ENT_SPRAYIMAGE
of type ncSprayPoster
Definition: entities.h:75
@ ENT_SPRAY
of type ncSpraylogo
Definition: entities.h:72
@ ENT_VEH_TANKMORTAR
of type func_tankmortar
Definition: entities.h:87
@ ENT_SOUNDSCAPE
of type ncSoundScape
Definition: entities.h:97
@ ENT_SPRAYWWW
of type ncSprayWWW
Definition: entities.h:76
@ ENT_RAIN
of type env_rain
Definition: entities.h:65
@ ENT_WEAPON
of type ncWeapon
Definition: entities.h:52
@ ENT_PORTAL
of type ncPortal
Definition: entities.h:55
@ ENT_SURFPROP
of type ncSurfacePropEntity
Definition: entities.h:45
@ ENT_PROJECTEDTEXTURE
of type env_projectedtexture
Definition: entities.h:61
@ ENT_SPEAKER
of type speaker
Definition: entities.h:49
@ ENT_OLDCAMERA
of type trigger_camera
Definition: entities.h:81
@ ENT_ITEM
of type ncItem
Definition: entities.h:51
@ ENT_SECURITYCAMERA
of type ncSecurityCamera
Definition: entities.h:103
@ ENT_FOG
of type env_fog
Definition: entities.h:63
@ ENT_MEDIASURFACE
of type ncMediaSurface
Definition: entities.h:98
@ ENT_FOGCONTROLLER
of type env_fog_controller
Definition: entities.h:66
@ ENT_STEAM
of type env_steam
Definition: entities.h:64
@ ENT_SEPARATOR
This is a separator.
Definition: entities.h:107
@ ENT_LASER
of type env_laser
Definition: entities.h:68
@ ENT_FUNNEL
of type env_funnel
Definition: entities.h:58
@ ENT_VEHICLE
Reserved.
Definition: entities.h:83
@ ENT_PUSH
of type trigger_push
Definition: entities.h:96
@ ENT_ANIMATIONMANAGER
of type ncAnimationManager
Definition: entities.h:42
@ ENT_SMOKER
of type env_smoker
Definition: entities.h:59
@ ENT_TRACKTRAIN
of type func_tracktrain
Definition: entities.h:84
@ ENT_DLIGHT
of type light_dynamic
Definition: entities.h:60
@ ENT_AMBIENTSOUND
of type ambient_generic
Definition: entities.h:56
@ ENT_VEH_BRUSH
of type func_vehicle
Definition: entities.h:86
@ ENT_WAYPOINT
of type info_waypoint
Definition: entities.h:93
@ ENT_PROPROPE
of type prop_rope
Definition: entities.h:89
@ ENT_PHYSICS
of type ncPhysicsEntity
Definition: entities.h:46
@ ENT_BEAM
of type env_beam
Definition: entities.h:57
@ ENT_ENTITYPROJECTILE
of type ncProjectile
Definition: entities.h:44
@ ENT_INSTRUCTOR
of type env_instructor_hint
Definition: entities.h:94
@ ENT_UISURFACE
of type ncInteractiveSurface
Definition: entities.h:99
@ ENT_DESKTOPCOMPUTER
of type ncComputerDesktop
Definition: entities.h:106
@ ENT_SPOTLIGHT
of type point_spotlight
Definition: entities.h:62
@ ENT_SPRAYAUDIO
of type ncSprayAudio
Definition: entities.h:74
@ ENT_PLAYER
of type ncPlayer
Definition: entities.h:50
@ ENT_USEROBJECT
of type ncUserEntity_GameEntity
Definition: entities.h:78
@ ENT_PHYSROPE
of type phys_rope
Definition: entities.h:90
@ ENT_ENTITYRENDERABLE
of type ncRenderableEntity
Definition: entities.h:43
@ ENT_PMOVEVARS
of type ncPMoveVars
Definition: entities.h:41
@ ENT_VEH_SEAT
of type ncVehicleSeat
Definition: entities.h:85
@ ENT_MONSTER
of type ncMonster
Definition: entities.h:47
@ ENT_SOUND
of type ncSound
Definition: entities.h:40
@ ENT_CONVEYOR
of type func_conveyor
Definition: entities.h:92
@ ENT_DECAL
of type ncDecal
Definition: entities.h:80
@ ENT_USERENTITY
of type ncUserEntity_GameEntity
Definition: entities.h:77
@ ENT_HUDCOUNTER
of type env_hudcounter
Definition: entities.h:95
@ ENT_VIDEODISPLAY
of type ncVideoDisplay
Definition: entities.h:102
@ ENT_BUBBLES
of type env_bubbles
Definition: entities.h:91
@ ENT_VEH_4WHEEL
of type prop_vehicle_driveable
Definition: entities.h:88