2019-08-31 19:18:15 -07:00
/*
2024-03-02 00:40:08 -08:00
* Copyright ( c ) 2016 - 2024 Vera Visions LLC .
2019-08-31 19:18:15 -07:00
*
* Permission to use , copy , modify , and distribute this software for any
* purpose with or without fee is hereby granted , provided that the above
* copyright notice and this permission notice appear in all copies .
*
* THE SOFTWARE IS PROVIDED " AS IS " AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS . IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL , DIRECT , INDIRECT , OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND , USE , DATA OR PROFITS , WHETHER
* IN AN ACTION OF CONTRACT , NEGLIGENCE OR OTHER TORTIOUS ACTION , ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE .
2022-07-07 09:10:14 -07:00
*/
2019-01-18 20:50:25 -08:00
2022-12-21 17:09:35 -08:00
/** Entity update identifiers */
typedef enum
2020-04-12 06:50:42 -07:00
{
2022-12-21 17:09:35 -08:00
ENT_NONE = 0 , /**< invalid, but reserved. */
ENT_ENTITY , /**< of type NSEntity */
ENT_ENTITYRENDERABLE , /**< of type NSRenderableEntity */
2023-05-27 11:58:34 -07:00
ENT_ENTITYPROJECTILE , /**< of type NSProjectile */
2022-12-21 17:09:35 -08:00
ENT_SURFPROP , /**< of type NSSurfacePropEntity */
ENT_PHYSICS , /**< of type NSPhysicsEntity */
ENT_MONSTER , /**< of type NSMonster */
ENT_TALKMONSTER , /**< of type NSTalkMonster */
2023-11-15 09:52:11 -08:00
ENT_SPEAKER , /**< of type speaker */
2022-12-21 17:09:35 -08:00
ENT_PLAYER , /**< of type NSClientPlayer */
2023-02-06 16:41:19 -08:00
ENT_WEAPON , /**< of type NSWeapon */
2022-12-21 17:09:35 -08:00
ENT_SPECTATOR , /**< of type NSClientSpectator */
2023-05-27 11:58:34 -07:00
ENT_PORTAL , /**< of type NSPortal */
2022-12-21 17:09:35 -08:00
ENT_AMBIENTSOUND , /**< of type ambient_generic */
ENT_BEAM , /**< of type env_beam */
2023-10-24 09:50:59 -07:00
ENT_FUNNEL , /**< of type env_funnel */
ENT_SMOKER , /**< of type env_smoker */
2022-12-21 17:09:35 -08:00
ENT_DLIGHT , /**< of type light_dynamic */
ENT_PROJECTEDTEXTURE , /**< of type env_projectedtexture */
2023-09-12 15:00:56 -07:00
ENT_SPOTLIGHT , /**< of type point_spotlight */
2023-04-14 10:21:07 -07:00
ENT_FOG , /*<< of type env_fog */
2023-11-15 09:52:11 -08:00
ENT_STEAM , /*<< of type env_steam */
2022-12-21 17:09:35 -08:00
ENT_FOGCONTROLLER , /**< of type env_fog_controller */
2023-11-15 09:52:11 -08:00
ENT_CASCADELIGHT , /*<< of type env_cascade_light */
2022-12-21 17:09:35 -08:00
ENT_LASER , /**< of type env_laser */
ENT_PARTSYSTEM , /**< of type info_particle_system */
ENT_SPRITE , /**< of type env_sprite */
2023-09-19 22:01:36 -07:00
ENT_GLOW , /**< of type env_glow */
2022-12-21 17:09:35 -08:00
ENT_SPRAY , /**< of type spray */
ENT_DECAL , /**< of type infodecal */
ENT_OLDCAMERA , /**< of type trigger_camera */
ENT_MONITOR , /**< of type func_monitor */
ENT_VEHICLE , /**< Reserved. */
2024-02-13 22:51:36 -08:00
ENT_TRACKTRAIN , /**< of type func_tracktrain */
2022-12-21 17:09:35 -08:00
ENT_VEH_BRUSH , /**< of type func_vehicle */
ENT_VEH_TANKMORTAR , /**< of type func_tankmortar */
ENT_VEH_4WHEEL , /**< of type prop_vehicle_driveable */
ENT_PROPROPE , /**< of type prop_rope */
2023-10-17 16:48:03 -07:00
ENT_PHYSROPE , /**< of type phys_rope */
2022-12-21 17:09:35 -08:00
ENT_BUBBLES , /**< of type env_bubbles */
2023-03-21 22:03:27 -07:00
ENT_CONVEYOR , /**< of type func_conveyor */
ENT_WAYPOINT , /**< of type info_waypoint */
2023-11-15 09:52:11 -08:00
ENT_INSTRUCTOR , /**< of type env_instructor_hint */
2023-03-21 22:03:27 -07:00
ENT_PUSH , /**< of type trigger_push */
2022-12-21 17:09:35 -08:00
ENT_SEPARATOR , /**< This is a separator. This separator is used by you to add game-specific networked entities. When declaring your own entity-update types, you want the first value to equal ENT_SEPARATOR at all times to ensure you'll not be overriding existing slots. */
} entupdate_t ;
/** Returns the closest point entity of a given classname.
Returns ' world ' or ' __NULL__ ' if it fails to find anything . */
2022-10-26 12:50:08 -07:00
entity
2022-12-21 17:09:35 -08:00
Entity_FindClosest ( entity startTarget , string className )
2022-10-26 12:50:08 -07:00
{
2022-05-26 13:25:02 -07:00
entity best = world ;
float bestdist ;
float dist ;
bestdist = 9999999 ;
2022-12-21 17:09:35 -08:00
for ( entity e = world ; ( e = find ( e , classname , className ) ) ; ) {
dist = vlen ( startTarget . origin - e . origin ) ;
2022-05-26 13:25:02 -07:00
if ( dist < bestdist ) {
bestdist = dist ;
best = e ;
}
}
return best ;
}
2022-10-26 12:50:08 -07:00
2022-12-21 17:09:35 -08:00
/** Returns a random entity of a given classname.
If world or ' __NULL__ ' is returned , then the given classname is not present in the map . */
2022-10-26 12:50:08 -07:00
entity
2022-12-21 17:09:35 -08:00
Entity_SelectRandom ( string className )
2022-05-26 13:25:02 -07:00
{
entity spot = world ;
2022-12-21 17:09:35 -08:00
int max = 0 i ;
2022-05-26 13:25:02 -07:00
2022-12-21 17:09:35 -08:00
/* count the total number of entities of the desired class */
for ( entity e = world ; ( e = find ( e , : : classname , className ) ) ; ) {
2022-05-26 13:25:02 -07:00
max + + ;
}
2022-12-21 17:09:35 -08:00
/* immediately exit out if we've got none */
if ( max < 1 i ) {
2024-03-02 00:40:08 -08:00
NSError ( " %S is not present on this map. " , className ) ;
2022-05-26 13:25:02 -07:00
return __NULL__ ;
}
/* select a random point */
for ( int i = random ( 1 , max ) ; i > 0 ; i - - ) {
2022-12-21 17:09:35 -08:00
spot = find ( spot , : : classname , className ) ;
2022-05-26 13:25:02 -07:00
}
/* we might end up not finding anything, wrap around? */
if ( spot = = __NULL__ ) {
2022-12-21 17:09:35 -08:00
spot = find ( spot , : : classname , className ) ;
2022-05-26 13:25:02 -07:00
}
/* we should have returned something valid now */
return spot ;
2022-06-08 17:35:56 -07:00
}