2019-08-31 19:18:15 -07:00
|
|
|
/*
|
2022-07-07 09:10:14 -07:00
|
|
|
* Copyright (c) 2016-2022 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
|
|
|
|
2020-10-24 04:11:02 -07:00
|
|
|
/* entity update identifiers */
|
2020-04-12 06:50:42 -07:00
|
|
|
enum
|
|
|
|
{
|
2021-01-20 16:29:26 -08:00
|
|
|
ENT_NONE,
|
|
|
|
ENT_ENTITY,
|
2021-10-19 16:18:36 -07:00
|
|
|
ENT_ENTITYRENDERABLE,
|
2022-04-20 14:29:37 -07:00
|
|
|
ENT_SURFPROP,
|
2022-04-20 10:44:59 -07:00
|
|
|
ENT_PHYSICS,
|
2021-09-11 15:13:24 -07:00
|
|
|
ENT_MONSTER,
|
2021-10-19 16:18:36 -07:00
|
|
|
ENT_TALKMONSTER,
|
2020-01-15 20:43:12 -08:00
|
|
|
ENT_PLAYER,
|
2021-03-23 23:50:30 -07:00
|
|
|
ENT_SPECTATOR,
|
2019-01-18 20:50:25 -08:00
|
|
|
ENT_AMBIENTSOUND,
|
2020-10-21 17:23:05 -07:00
|
|
|
ENT_DLIGHT,
|
2020-11-27 10:23:21 -08:00
|
|
|
ENT_PROJECTEDTEXTURE,
|
2022-03-23 11:05:35 -07:00
|
|
|
ENT_FOGCONTROLLER,
|
2020-03-25 05:58:19 -07:00
|
|
|
ENT_ENVLASER,
|
2020-11-26 18:05:21 -08:00
|
|
|
ENT_PARTSYSTEM,
|
2019-01-18 20:50:25 -08:00
|
|
|
ENT_SPRITE,
|
|
|
|
ENT_SPRAY,
|
2020-10-24 04:11:02 -07:00
|
|
|
ENT_DECAL,
|
2020-11-28 13:52:56 -08:00
|
|
|
ENT_OLDCAMERA,
|
2020-12-01 11:43:25 -08:00
|
|
|
ENT_MONITOR,
|
2021-08-28 12:25:38 -07:00
|
|
|
ENT_VEHICLE,
|
2022-08-28 09:20:34 -07:00
|
|
|
ENT_VEH_BRUSH,
|
2021-09-08 11:17:13 -07:00
|
|
|
ENT_VEH_TANKMORTAR,
|
2021-09-11 13:43:14 -07:00
|
|
|
ENT_VEH_4WHEEL,
|
2022-03-22 16:38:31 -07:00
|
|
|
ENT_PROPROPE,
|
2022-04-30 20:18:56 -07:00
|
|
|
ENT_BUBBLES,
|
2021-08-28 12:25:38 -07:00
|
|
|
ENT_SEPARATOR,
|
2019-01-18 20:50:25 -08:00
|
|
|
};
|
2022-05-26 13:25:02 -07:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Entity_FindClosest
|
|
|
|
|
|
|
|
Returns the closest point entity of a given classname.
|
|
|
|
world means it failed. most likely.
|
|
|
|
=================
|
|
|
|
*/
|
2022-10-26 12:50:08 -07:00
|
|
|
entity
|
|
|
|
Entity_FindClosest(entity target, string cname)
|
|
|
|
{
|
2022-05-26 13:25:02 -07:00
|
|
|
entity best = world;
|
|
|
|
float bestdist;
|
|
|
|
float dist;
|
|
|
|
|
|
|
|
bestdist = 9999999;
|
|
|
|
|
|
|
|
for (entity e = world; (e = find(e, classname, cname));) {
|
|
|
|
dist = vlen(target.origin - e.origin);
|
|
|
|
|
|
|
|
if (dist < bestdist) {
|
|
|
|
bestdist = dist;
|
|
|
|
best = e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return best;
|
|
|
|
}
|
|
|
|
|
2022-10-26 12:50:08 -07:00
|
|
|
|
2022-05-26 13:25:02 -07:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Entity_SelectRandom
|
|
|
|
|
|
|
|
Returns a random entity of a given classname.
|
|
|
|
Check for world at all times. If world is returned then the given classname
|
|
|
|
will most likely never return anything valid.
|
|
|
|
=================
|
|
|
|
*/
|
2022-10-26 12:50:08 -07:00
|
|
|
entity
|
|
|
|
Entity_SelectRandom(string cname)
|
2022-05-26 13:25:02 -07:00
|
|
|
{
|
|
|
|
entity spot = world;
|
|
|
|
float max = 0;
|
|
|
|
|
|
|
|
/* count our max count */
|
2022-10-26 12:50:08 -07:00
|
|
|
for (entity e = world; (e = find(e,::classname, cname));) {
|
2022-05-26 13:25:02 -07:00
|
|
|
max++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* immediately exit out */
|
|
|
|
if (max == 0) {
|
|
|
|
print(sprintf("^1Error: %s is not present on this map.\n", cname));
|
|
|
|
return __NULL__;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* select a random point */
|
|
|
|
for (int i = random(1, max); i > 0; i--) {
|
|
|
|
spot = find(spot, classname, cname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we might end up not finding anything, wrap around? */
|
|
|
|
if (spot == __NULL__) {
|
|
|
|
spot = find(spot, classname, cname);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we should have returned something valid now */
|
|
|
|
return spot;
|
2022-06-08 17:35:56 -07:00
|
|
|
}
|