reaction/code/game/bg_misc.c

1824 lines
37 KiB
C
Raw Normal View History

//-----------------------------------------------------------------------------
//
// $Id$
//
//-----------------------------------------------------------------------------
//
2001-12-31 16:28:42 +00:00
// $Log$
2006-04-14 18:16:31 +00:00
// Revision 1.58 2006/04/14 18:15:45 makro
// no message
//
2005-09-07 20:27:42 +00:00
// Revision 1.57 2005/09/07 20:27:41 makro
// Entity attachment trees
//
// Revision 1.56 2005/02/15 16:33:39 makro
// Tons of updates (entity tree attachment system, UI vectors)
//
2003-07-30 16:05:47 +00:00
// Revision 1.55 2003/07/30 16:05:46 makro
// no message
//
// Revision 1.54 2003/04/02 22:23:51 jbravo
// More replacements tweaks. Added zcam_stfu
//
2003-03-31 21:04:24 +00:00
// Revision 1.53 2003/03/31 21:04:24 makro
// no message
//
2003-03-29 23:04:56 +00:00
// Revision 1.52 2003/03/29 23:04:56 jbravo
// More post _skin cvar fixes
//
// Revision 1.51 2003/03/29 16:01:36 jbravo
// _skin cvars now fully removed. dlight code from Makro added. cvar
// defaults fixed.
//
2003-03-28 22:26:24 +00:00
// Revision 1.50 2003/03/28 22:26:24 makro
// no message
//
// Revision 1.49 2003/02/05 20:21:38 jbravo
// Fixed the model replacement system. Its no longer an ugly hack.
//
2003-02-01 02:15:31 +00:00
// Revision 1.48 2003/02/01 02:15:31 jbravo
// Replacement models and items
//
// Revision 1.47 2003/01/08 04:46:26 jbravo
// Wrote a new hackish model replacement system
//
2002-10-30 20:04:34 +00:00
// Revision 1.46 2002/10/30 20:04:34 jbravo
// Adding helmet
//
// Revision 1.45 2002/10/26 00:37:18 jbravo
// New multiple item code and added PB support to the UI
//
2002-07-22 06:35:03 +00:00
// Revision 1.44 2002/07/22 06:34:13 niceass
// cleaned up the powerup code
//
// Revision 1.43 2002/07/01 02:18:42 jbravo
// Small fixes to CTB and possible fix for subs and limchasecam
//
// Revision 1.42 2002/06/29 04:15:15 jbravo
// CTF is now CTB. no weapons while the case is in hand other than pistol or knife
//
// Revision 1.41 2002/06/16 20:06:14 jbravo
// Reindented all the source files with "indent -kr -ut -i8 -l120 -lc120 -sob -bad -bap"
//
// Revision 1.40 2002/06/16 17:37:59 jbravo
// Removed the MISSIONPACK ifdefs and missionpack only code.
//
2002-05-29 13:49:26 +00:00
// Revision 1.39 2002/05/29 13:49:25 makro
// Elevators/doors
//
2002-05-12 22:14:13 +00:00
// Revision 1.38 2002/05/12 22:14:13 makro
// Impact sounds
//
2002-05-11 19:18:20 +00:00
// Revision 1.37 2002/05/11 19:18:20 makro
// Sand surfaceparm
//
// Revision 1.36 2002/05/11 14:22:06 makro
// Func_statics now reset at the beginning of each round
//
// Revision 1.35 2002/04/30 11:54:37 makro
// Bots rule ! Also, added clips to give all. Maybe some other things
//
2002-04-23 06:09:18 +00:00
// Revision 1.34 2002/04/23 06:03:39 niceass
// pressure stuff
//
// Revision 1.33 2002/04/20 15:03:47 makro
// More footstep sounds, a few other things
//
// Revision 1.32 2002/04/03 03:13:16 blaze
// NEW BREAKABLE CODE - will break all old breakables(wont appear in maps)
//
2002-03-31 03:31:24 +00:00
// Revision 1.31 2002/03/31 03:31:24 jbravo
// Compiler warning cleanups
//
2002-03-02 12:24:30 +00:00
// Revision 1.30 2002/03/02 12:24:30 jbravo
// Removed some debugging messages
//
// Revision 1.29 2002/02/23 16:55:09 jbravo
// Added debugging to help find what was going with can't find item for weapon
// error that crash the server.
//
// Revision 1.28 2002/01/24 14:20:53 jbravo
// Adding func_explosive and a few new surfaceparms
//
// Revision 1.27 2002/01/14 07:31:33 jbravo
// Added a small workaround for the HoldableItem not found crash during
// mapchanges.
//
// Revision 1.26 2002/01/11 19:48:29 jbravo
// Formatted the source in non DOS format.
//
2001-12-31 16:28:42 +00:00
// Revision 1.25 2001/12/31 16:28:42 jbravo
// I made a Booboo with the Log tag.
//
//
//-----------------------------------------------------------------------------
2001-05-06 20:50:27 +00:00
// Copyright (C) 1999-2000 Id Software, Inc.
//
// bg_misc.c -- both games misc functions, all completely stateless
#include "../qcommon/q_shared.h"
2001-05-06 20:50:27 +00:00
#include "bg_public.h"
/*QUAKED item_***** ( 0 0 0 ) (-16 -16 -16) (16 16 16) suspended
DO NOT USE THIS CLASS, IT JUST HOLDS GENERAL INFORMATION.
The suspended flag will allow items to hang in the air, otherwise they are dropped to the next surface.
If an item is the target of another entity, it will not spawn in until fired.
An item fires all of its targets when it is picked up. If the toucher can't carry it, the targets won't be fired.
"notfree" if set to 1, don't spawn in free for all games
"notteam" if set to 1, don't spawn in team games
"notsingle" if set to 1, don't spawn in single player games
"wait" override the default wait before respawning. -1 = never respawn automatically, which can be used with targeted spawning.
"random" random number of plus or minus seconds varied from the respawn time
"count" override quantity or duration on most items.
*/
gitem_t bg_itemlist[] = {
2001-05-06 20:50:27 +00:00
{
NULL,
NULL,
{NULL,
NULL,
NULL, NULL}
,
/* icon */ NULL,
/* pickup */ NULL,
0,
0,
0,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
, // leave index 0 alone
2001-05-06 20:50:27 +00:00
//
// ARMOR
//
//
2001-12-17 15:08:34 +00:00
// WEAPONS
2001-05-06 20:50:27 +00:00
//
//Blaze: Reaction weapons
//Knife
{
"weapon_knife",
"sound/misc/am_pkup.wav",
{"models/weapons2/knife/knife.md3",
0, 0, 0}
,
"icons/iconw_knife",
RQ3_KNIFE_NAME,
1,
IT_WEAPON,
WP_KNIFE,
"",
""}
,
2001-05-06 20:50:27 +00:00
//Pistol
{
"weapon_pistol",
"sound/weapons/mk23/mk23slide.wav",
{"models/weapons2/mk23/mk23.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_mk23",
/* pickup */ RQ3_PISTOL_NAME,
12,
IT_WEAPON,
WP_PISTOL,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//M4
{
"weapon_m4",
"sound/weapons/m4/m4slide.wav",
{"models/weapons2/m4/m4.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_m4",
/* pickup */ RQ3_M4_NAME,
24,
IT_WEAPON,
WP_M4,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//SSG3000
{
"weapon_ssg3000",
"sound/weapons/ssg3000/ssgin.wav",
{"models/weapons2/ssg3000/ssg3000.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_ssg",
/* pickup */ RQ3_SSG3000_NAME,
6,
IT_WEAPON,
WP_SSG3000,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//MP5
{
"weapon_mp5",
"sound/weapons/mp5/mp5slide.wav",
{"models/weapons2/mp5/mp5.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_mp5",
/* pickup */ RQ3_MP5_NAME,
30,
IT_WEAPON,
WP_MP5,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//Handcannon
{
"weapon_handcannon",
"sound/weapons/handcannon/hcopen.wav",
{"models/weapons2/handcannon/handcannon.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_handcannon",
/* pickup */ RQ3_HANDCANNON_NAME,
2,
IT_WEAPON,
WP_HANDCANNON,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//Shotgun
{
"weapon_m3",
"sound/weapons/m3/m3in.wav",
{"models/weapons2/m3/m3.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_m3",
/* pickup */ RQ3_M3_NAME,
7,
IT_WEAPON,
WP_M3,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//Akimbo Placeholder
{
"weapon_akimbo",
"sound/weapons/mk23/mk23slide.wav",
{"models/weapons2/akimbo/akimbo.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_akimbo",
/* pickup */ RQ3_AKIMBO_NAME,
24,
IT_WEAPON,
WP_AKIMBO,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//Grenade
{
"weapon_grenade",
//"sound/grenade/tink2.wav",
"sound/misc/am_pkup.wav",
{"models/weapons2/grenade/grenade.md3",
0, 0, 0}
,
/* icon */ "icons/iconw_grenade",
/* pickup */ RQ3_GRENADE_NAME,
1,
IT_WEAPON,
WP_GRENADE,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//Blaze: 3rd Person Models
//Elder: 07/06/2001: Now known as 1st-person models!
2001-05-06 20:50:27 +00:00
//Knife
{
"knife_1st",
NULL,
{"models/weapons2/knife/knife_1st.md3", 0, 0, 0}
,
"icons/iconw_knife",
RQ3_KNIFE_NAME,
1,
IT_WEAPON,
WP_KNIFE,
"",
""}
,
2001-05-06 20:50:27 +00:00
//Pistol
{
"pistol_1st",
NULL,
{"models/weapons2/mk23/mk23_1st.md3",
0, 0, 0}
,
"icons/iconw_mk23",
RQ3_PISTOL_NAME,
12,
IT_WEAPON,
WP_PISTOL,
"",
""}
,
2001-05-06 20:50:27 +00:00
//M4
{
"m4_1st",
NULL,
{"models/weapons2/m4/m4_1st.md3",
0, 0, 0}
,
"icons/iconw_m4",
RQ3_M4_NAME,
24,
IT_WEAPON,
WP_M4,
"",
""}
,
2001-05-06 20:50:27 +00:00
//SSG3000
{
"ssg3000_1st",
NULL,
{"models/weapons2/ssg3000/ssg3000_1st.md3",
0, 0, 0}
,
"icons/iconw_ssg",
RQ3_SSG3000_NAME,
6,
IT_WEAPON,
WP_SSG3000,
"",
""}
,
2001-05-06 20:50:27 +00:00
//MP5
{
"mp5_1st",
NULL,
{"models/weapons2/mp5/mp5_1st.md3",
0, 0, 0}
,
"icons/iconw_mp5",
RQ3_MP5_NAME,
30,
IT_WEAPON,
WP_MP5,
"",
""}
,
2001-05-06 20:50:27 +00:00
//Handcannon
{
"handcannon_1st",
NULL,
{"models/weapons2/handcannon/handcannon_1st.md3",
0, 0, 0}
,
"icons/iconw_sawedoff",
RQ3_HANDCANNON_NAME,
2,
IT_WEAPON,
WP_HANDCANNON,
"",
""}
,
2001-05-06 20:50:27 +00:00
//Shotgun
{
"m3_1st",
NULL,
{"models/weapons2/m3/m3_1st.md3",
0, 0, 0}
,
"icons/iconw_m3",
RQ3_M3_NAME,
7,
IT_WEAPON,
WP_M3,
"",
""}
,
2001-05-06 20:50:27 +00:00
//Akimbo Placeholder
{
"akimbo_1st",
NULL,
{"models/weapons2/akimbo/akimbo_1st.md3",
0, 0, 0}
,
"icons/iconw_akimbo",
RQ3_AKIMBO_NAME,
24,
IT_WEAPON,
WP_AKIMBO,
"",
""}
,
2001-05-06 20:50:27 +00:00
//Grenade
{
"grenade_1st",
NULL,
{"models/weapons2/grenade/grenade_1st.md3",
0, 0, 0}
,
"icons/iconw_gren",
RQ3_GRENADE_NAME,
1,
IT_WEAPON,
WP_GRENADE,
"",
""}
,
2001-05-06 20:50:27 +00:00
//
// AMMO ITEMS
//
/*QUAKED ammo_mk23 (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
2001-05-06 20:50:27 +00:00
*/
{
"ammo_mk23",
"sound/misc/am_pkup.wav",
{"models/ammo/mk23.md3",
0, 0, 0}
,
/* icon */ "icons/icona_mk23",
/* pickup */ "MK23 Clip",
1,
IT_AMMO,
//Blaze: Changed from WP_MACHINEGUN to WP_PISTOL
WP_PISTOL,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
/*QUAKED ammo_shells (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
{
"ammo_shells",
"sound/misc/am_pkup.wav",
{"models/ammo/m3.md3",
0, 0, 0}
,
/* icon */ "icons/icona_m3",
/* pickup */ "Shotgun Shells",
7,
IT_AMMO,
//Blaze: Changed from WP_ROCKET_LAUNCHER to WP_SHOTGUN
WP_M3,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
/*QUAKED ammo_ssg3000 (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
2001-05-06 20:50:27 +00:00
*/
{
"ammo_ssg3000",
"sound/misc/am_pkup.wav",
{"models/ammo/ssg3000.md3",
0, 0, 0}
,
/* icon */ "icons/icona_ssg3000",
/* pickup */ "AP Sniper Ammo",
10,
IT_AMMO,
//Blaze: Changed from WP_RAILGUN to WP_GRENADE
WP_SSG3000,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
/*QUAKED ammo_mp5 (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
2001-05-06 20:50:27 +00:00
*/
{
"ammo_mp5",
"sound/misc/am_pkup.wav",
{"models/ammo/mp5.md3",
0, 0, 0}
,
/* icon */ "icons/icona_mp5",
/* pickup */ "MP5 Clip",
1,
IT_AMMO,
//Blaze: Changed from WP_PLASMAGUN to WP_MP5
WP_MP5,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
/*QUAKED ammo_lightning (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
//Blaze: HC and M3 use same ammo
// {
// "ammo_lightning",
// "sound/misc/am_pkup.wav",
2001-12-17 15:08:34 +00:00
// { "models/powerups/ammo/lightningam.md3",
// 0, 0, 0},
/* icon */// "icons/icona_lightning",
/* pickup */// "Shotgun Shells",
//7,
//IT_AMMO,
//Blaze: Changed from WP_LIGHTNING to WP_HANDCANNON
//WP_HANDCANNON,
2001-05-06 20:50:27 +00:00
/* precache */// "",
/* sounds *///""
// },
2001-05-06 20:50:27 +00:00
/*QUAKED ammo_m4 (.3 .3 1) (-16 -16 -16) (16 16 16) suspended
*/
{
"ammo_m4",
"sound/misc/am_pkup.wav",
{"models/ammo/m4.md3",
0, 0, 0}
,
/* icon */ "icons/icona_m4",
/* pickup */ "M4 Clip",
1,
IT_AMMO,
//Blaze: changed from WP_SHOTGUN to WP_M4
WP_M4,
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
/*QUAKED team_CTF_redflag (1 0 0) (-16 -16 -16) (16 16 16)
Only in CTF games
*/
{
"team_CTF_redflag",
NULL,
// {"models/flags/r_flag.md3",
{"models/cases/s_case.md3",
0, 0, 0}
,
/* icon */ "icons/iconc_silver",
/* pickup */ "Silver Case",
0,
IT_TEAM,
PW_REDFLAG,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
/*QUAKED team_CTF_blueflag (0 0 1) (-16 -16 -16) (16 16 16)
Only in CTF games
*/
{
"team_CTF_blueflag",
NULL,
// {"models/flags/b_flag.md3",
{"models/cases/b_case.md3",
0, 0, 0}
,
/* icon */ "icons/iconc_black",
/* pickup */ "Black Case",
0,
IT_TEAM,
PW_BLUEFLAG,
2001-05-06 20:50:27 +00:00
/* precache */ "",
/* sounds */ ""
}
,
2001-05-06 20:50:27 +00:00
//Elder: RQ3 Items
2001-06-28 00:13:45 +00:00
{
"item_kevlar",
"sound/items/kevlar.wav",
{"models/items/kevlar.md3",
0, 0, 0}
,
"icons/iconi_kevlar",
RQ3_KEVLAR_NAME,
0,
IT_HOLDABLE,
HI_KEVLAR,
"",
""}
,
2001-06-28 00:13:45 +00:00
{
"item_silencer",
"sound/items/silencer.wav",
{"models/items/silencer.md3",
0, 0, 0}
,
"icons/iconi_silencer",
RQ3_SILENCER_NAME,
0,
IT_HOLDABLE,
HI_SILENCER,
"",
""}
,
{
"item_laser",
"sound/items/laser.wav",
{"models/items/laser.md3",
0, 0, 0}
,
"icons/iconi_laser",
RQ3_LASER_NAME,
0,
IT_HOLDABLE,
HI_LASER,
"",
""}
,
{
"item_bandolier",
"sound/items/bandolier.wav",
{"models/items/bandolier.md3",
0, 0, 0}
,
"icons/iconi_bandolier",
RQ3_BANDOLIER_NAME,
0,
IT_HOLDABLE,
HI_BANDOLIER,
"",
""}
,
{
"item_slippers",
"sound/items/slippers.wav",
{"models/items/slippers.md3",
0, 0, 0}
,
"icons/iconi_slippers",
RQ3_SLIPPERS_NAME,
0,
IT_HOLDABLE,
HI_SLIPPERS,
"",
""}
,
2002-10-30 20:04:34 +00:00
// JBravo: adding Helmet
{
"item_helmet",
"sound/items/slippers.wav",
{"models/items/helmet.md3",
2002-10-30 20:04:34 +00:00
0, 0, 0}
,
"icons/iconi_helmet",
2002-10-30 20:04:34 +00:00
RQ3_HELMET_NAME,
0,
IT_HOLDABLE,
HI_HELMET,
"",
""}
,
2001-05-06 20:50:27 +00:00
// end of list marker
{NULL}
};
int bg_numItems = ARRAY_LEN( bg_itemlist ) - 1;
2001-05-06 20:50:27 +00:00
/*
==============
BG_FindItemForPowerup
==============
*/
gitem_t *BG_FindItemForPowerup(powerup_t pw)
{
int i;
for (i = 0; i < bg_numItems; i++) {
if ((bg_itemlist[i].giType == IT_POWERUP ||
bg_itemlist[i].giType == IT_TEAM ||
bg_itemlist[i].giType == IT_PERSISTANT_POWERUP) && bg_itemlist[i].giTag == pw) {
2001-05-06 20:50:27 +00:00
return &bg_itemlist[i];
}
}
return NULL;
}
/*
==============
BG_FindItemForHoldable
==============
*/
gitem_t *BG_FindItemForHoldable(holdable_t pw)
{
int i;
2001-05-06 20:50:27 +00:00
// JBravo: fix for HoldableItem not found error during mapchanges.
// I dont understand why this gets called with pw == 0 during map changes.
if (pw == 0)
2002-03-31 03:31:24 +00:00
return NULL;
for (i = 0; i < bg_numItems; i++) {
if (bg_itemlist[i].giType == IT_HOLDABLE && bg_itemlist[i].giTag == pw) {
2001-05-06 20:50:27 +00:00
return &bg_itemlist[i];
}
}
Com_Error(ERR_DROP, "HoldableItem not found");
2001-05-06 20:50:27 +00:00
return NULL;
}
/*
===============
BG_FindItemForWeapon
===============
*/
gitem_t *BG_FindItemForWeapon(weapon_t weapon)
{
gitem_t *it;
2001-12-17 15:08:34 +00:00
for (it = bg_itemlist + 1; it->classname; it++) {
if (it->giType == IT_WEAPON && it->giTag == weapon) {
2001-05-06 20:50:27 +00:00
return it;
}
}
Com_Error(ERR_DROP, "Couldn't find item for weapon %i", weapon);
2001-05-06 20:50:27 +00:00
return NULL;
}
/*
===============
BG_FindItem
===============
*/
gitem_t *BG_FindItem(const char *pickupName)
{
gitem_t *it;
2001-12-17 15:08:34 +00:00
for (it = bg_itemlist + 1; it->classname; it++) {
if (!Q_stricmp(it->pickup_name, pickupName))
2001-05-06 20:50:27 +00:00
return it;
}
return NULL;
}
/*
============
BG_PlayerTouchesItem
Items can be picked up without actually touching their physical bounds to make
grabbing them easier
============
*/
qboolean BG_PlayerTouchesItem(playerState_t * ps, entityState_t * item, int atTime)
{
vec3_t origin;
2001-05-06 20:50:27 +00:00
BG_EvaluateTrajectory(&item->pos, atTime, origin);
2001-05-06 20:50:27 +00:00
// we are ignoring ducked differences here
if (ps->origin[0] - origin[0] > 44
|| ps->origin[0] - origin[0] < -50
|| ps->origin[1] - origin[1] > 36
|| ps->origin[1] - origin[1] < -36 || ps->origin[2] - origin[2] > 36 || ps->origin[2] - origin[2] < -36) {
2001-05-06 20:50:27 +00:00
return qfalse;
}
return qtrue;
}
/*
==================
Elder: changed from ClipAmountForWeapon - which was an ambiguous name
ClipAmountForReload for Cmd_Reload
2001-05-06 20:50:27 +00:00
Added by Duffman
Returns the amount of ammo a weapon reloads by
==================
2001-05-06 20:50:27 +00:00
*/
int ClipAmountForReload(int w)
{
2001-05-06 20:50:27 +00:00
//How much each clip holds
//Elder: this function is very misleading.
//It returns the amount to add when reloading,
//Not the actual amount in a weapon clip!!
//For that, you should check ClipAmountForAmmo below
//Changed to use constants defined in bg_public.h
switch (w) {
case WP_PISTOL:
return RQ3_PISTOL_RELOAD;
case WP_KNIFE:
return RQ3_KNIFE_RELOAD;
case WP_M4:
return RQ3_M4_RELOAD;
case WP_SSG3000:
return RQ3_SSG3000_RELOAD;
case WP_MP5:
return RQ3_MP5_RELOAD;
case WP_HANDCANNON:
return RQ3_HANDCANNON_RELOAD;
case WP_M3:
return RQ3_M3_RELOAD;
case WP_AKIMBO:
return RQ3_AKIMBO_RELOAD;
case WP_GRENADE:
return RQ3_GRENADE_RELOAD;
default:
return RQ3_PISTOL_RELOAD;
}
2001-05-06 20:50:27 +00:00
// return 12; //this wont happen unless you copy-and-paste too much
}
/*
==================
ClipAmountForAmmo
Added by Elder
Returns the amount of ammo a weapon can hold
==================
*/
int ClipAmountForAmmo(int w)
{
//How much each GUN holds!
//Elder: don't confuse with the reload one
switch (w) {
case WP_PISTOL:
return RQ3_PISTOL_AMMO;
case WP_KNIFE:
return RQ3_KNIFE_AMMO;
case WP_M4:
return RQ3_M4_AMMO;
case WP_SSG3000:
return RQ3_SSG3000_AMMO;
case WP_MP5:
return RQ3_MP5_AMMO;
case WP_HANDCANNON:
return RQ3_HANDCANNON_AMMO;
case WP_M3:
return RQ3_M3_AMMO;
case WP_AKIMBO:
return RQ3_AKIMBO_AMMO;
case WP_GRENADE:
return RQ3_GRENADE_AMMO;
default:
return RQ3_PISTOL_AMMO;
}
}
2001-05-06 20:50:27 +00:00
/*
================
BG_CanItemBeGrabbed
Returns false if the item should not be picked up.
This needs to be the same for client side prediction and server use.
================
*/
qboolean BG_CanItemBeGrabbed(int gametype, const entityState_t * ent, const playerState_t * ps)
{
gitem_t *item;
2001-05-06 20:50:27 +00:00
if (ent->modelindex < 1 || ent->modelindex >= bg_numItems) {
Com_Error(ERR_DROP, "BG_CanItemBeGrabbed: index out of range");
2001-05-06 20:50:27 +00:00
}
item = &bg_itemlist[ent->modelindex];
switch (item->giType) {
2001-05-06 20:50:27 +00:00
case IT_WEAPON:
//Elder: gotta check before we can pick it up
//if (item->giTag == WP_KNIFE && ps->ammo[WP_KNIFE] >= RQ3_KNIFE_MAXCLIP)
//return qfalse;
//else
//if (item->giTag != WP_KNIFE && ent->pos.trDelta && ent->pos.trDelta[2] != 0)
//return qfalse;
//else
return qtrue; // weapons are always picked up
2001-12-17 15:08:34 +00:00
2001-05-06 20:50:27 +00:00
case IT_AMMO:
//Blaze: pick up all ammo
//Blaze: make sure you dont go over max amount of clips
//if ( ps->stats[STAT_CLIPS] >= 2)
//if ( ps->ammo[ item->giTag ] >= ClipAmountForWeapon(item->giTag )) {
//{
// return qfalse; // can't hold any more
2001-05-06 20:50:27 +00:00
//}
return qtrue;
case IT_ARMOR:
if (ps->stats[STAT_ARMOR] >= 200) { //2 times max healthps->stats[STAT_MAX_HEALTH] * 2 ) {
2001-05-06 20:50:27 +00:00
return qfalse;
}
return qtrue;
case IT_HEALTH:
// small and mega healths will go over the max, otherwise
// don't pick up if already at max
if (item->quantity == 5 || item->quantity == 100) {
if (ps->stats[STAT_HEALTH] >= 200) { //200 is max health x 2 ps->stats[STAT_MAX_HEALTH] * 2 ) {
2001-05-06 20:50:27 +00:00
return qfalse;
}
return qtrue;
}
if (ps->stats[STAT_HEALTH] >= 100) { //100 is the max health ps->stats[STAT_MAX_HEALTH] ) {
2001-05-06 20:50:27 +00:00
return qfalse;
}
return qtrue;
case IT_POWERUP:
return qtrue; // powerups are always picked up
case IT_TEAM: // team items, such as flags
if (gametype == GT_CTF) {
// ent->modelindex2 is non-zero on items if they are dropped
// we need to know this because we can pick up our dropped flag (and return it)
// but we can't pick up our flag at base
if (ps->persistant[PERS_TEAM] == TEAM_RED) {
if (item->giTag == PW_BLUEFLAG ||
(item->giTag == PW_REDFLAG && ent->modelindex2) ||
(item->giTag == PW_REDFLAG && ps->powerups[PW_BLUEFLAG]))
return qtrue;
} else if (ps->persistant[PERS_TEAM] == TEAM_BLUE) {
if (item->giTag == PW_REDFLAG ||
(item->giTag == PW_BLUEFLAG && ent->modelindex2) ||
(item->giTag == PW_BLUEFLAG && ps->powerups[PW_REDFLAG]))
return qtrue;
}
2001-05-06 20:50:27 +00:00
}
return qfalse;
case IT_HOLDABLE:
// can only hold one item at a time
// JBravo: I beg to differ
/* if (ps->stats[STAT_HOLDABLE_ITEM]) {
2001-05-06 20:50:27 +00:00
return qfalse;
} */
2001-05-06 20:50:27 +00:00
return qtrue;
case IT_BAD:
Com_Error(ERR_DROP, "BG_CanItemBeGrabbed: IT_BAD");
default:
2001-08-01 19:52:17 +00:00
#ifndef Q3_VM
#ifndef NDEBUG // bk0001204
Com_Printf("BG_CanItemBeGrabbed: unknown enum %d\n", item->giType);
2001-08-01 19:52:17 +00:00
#endif
#endif
break;
2001-05-06 20:50:27 +00:00
}
return qfalse;
}
//======================================================================
/*
================
BG_EvaluateTrajectory
================
*/
void BG_EvaluateTrajectory(const trajectory_t * tr, int atTime, vec3_t result)
{
float deltaTime;
float phase;
2001-05-06 20:50:27 +00:00
switch (tr->trType) {
2001-05-06 20:50:27 +00:00
case TR_STATIONARY:
case TR_INTERPOLATE:
VectorCopy(tr->trBase, result);
2001-05-06 20:50:27 +00:00
break;
case TR_LINEAR:
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
VectorMA(tr->trBase, deltaTime, tr->trDelta, result);
2001-05-06 20:50:27 +00:00
break;
case TR_SINE:
deltaTime = (atTime - tr->trTime) / (float) tr->trDuration;
phase = sin(deltaTime * M_PI * 2);
VectorMA(tr->trBase, phase, tr->trDelta, result);
2001-05-06 20:50:27 +00:00
break;
case TR_LINEAR_STOP:
if (atTime > tr->trTime + tr->trDuration) {
2001-05-06 20:50:27 +00:00
atTime = tr->trTime + tr->trDuration;
}
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
if (deltaTime < 0) {
2001-05-06 20:50:27 +00:00
deltaTime = 0;
}
VectorMA(tr->trBase, deltaTime, tr->trDelta, result);
2001-05-06 20:50:27 +00:00
break;
case TR_GRAVITY:
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
VectorMA(tr->trBase, deltaTime, tr->trDelta, result);
result[2] -= 0.5 * DEFAULT_GRAVITY * deltaTime * deltaTime; // FIXME: local gravity...
2001-05-06 20:50:27 +00:00
break;
default:
2013-07-21 23:15:13 +00:00
Com_Error(ERR_DROP, "BG_EvaluateTrajectory: unknown trType: %i", tr->trType);
2001-05-06 20:50:27 +00:00
break;
}
}
/*
================
BG_EvaluateTrajectoryDelta
For determining velocity at a given time
================
*/
void BG_EvaluateTrajectoryDelta(const trajectory_t * tr, int atTime, vec3_t result)
{
float deltaTime;
float phase;
2001-05-06 20:50:27 +00:00
switch (tr->trType) {
2001-05-06 20:50:27 +00:00
case TR_STATIONARY:
case TR_INTERPOLATE:
VectorClear(result);
2001-05-06 20:50:27 +00:00
break;
case TR_LINEAR:
VectorCopy(tr->trDelta, result);
2001-05-06 20:50:27 +00:00
break;
case TR_SINE:
deltaTime = (atTime - tr->trTime) / (float) tr->trDuration;
phase = cos(deltaTime * M_PI * 2); // derivative of sin = cos
2001-05-06 20:50:27 +00:00
phase *= 0.5;
VectorScale(tr->trDelta, phase, result);
2001-05-06 20:50:27 +00:00
break;
case TR_LINEAR_STOP:
if (atTime > tr->trTime + tr->trDuration) {
VectorClear(result);
2001-05-06 20:50:27 +00:00
return;
}
VectorCopy(tr->trDelta, result);
2001-05-06 20:50:27 +00:00
break;
case TR_GRAVITY:
deltaTime = (atTime - tr->trTime) * 0.001; // milliseconds to seconds
VectorCopy(tr->trDelta, result);
result[2] -= DEFAULT_GRAVITY * deltaTime; // FIXME: local gravity...
2001-05-06 20:50:27 +00:00
break;
default:
2013-07-21 23:15:13 +00:00
Com_Error(ERR_DROP, "BG_EvaluateTrajectoryDelta: unknown trType: %i", tr->trType);
2001-05-06 20:50:27 +00:00
break;
}
}
char *eventnames[] = {
"EV_NONE",
"EV_FOOTSTEP",
"EV_FOOTSTEP_METAL",
"EV_FOOTSTEP_GRAVEL",
"EV_FOOTSTEP_WOOD",
"EV_FOOTSTEP_CARPET",
"EV_FOOTSTEP_METAL2",
"EV_FOOTSTEP_GLASS",
"EV_FOOTSTEP_GRASS",
"EV_FOOTSTEP_SNOW", // JBravo: adding new sounds
"EV_FOOTSTEP_MUD",
"EV_FOOTSTEP_WOOD2",
"EV_FOOTSTEP_HARDMETAL",
//Makro - new sounds
"EV_FOOTSTEP_LEAVES",
"EV_FOOTSTEP_CEMENT",
"EV_FOOTSTEP_MARBLE",
"EV_FOOTSTEP_SNOW2",
"EV_FOOTSTEP_HARDSTEPS",
2002-05-11 19:18:20 +00:00
"EV_FOOTSTEP_SAND",
2001-05-06 20:50:27 +00:00
"EV_FOOTSPLASH",
"EV_FOOTWADE",
"EV_SWIM",
"EV_STEP_4",
"EV_STEP_8",
"EV_STEP_12",
"EV_STEP_16",
"EV_FALL_SHORT",
2001-07-27 00:21:23 +00:00
"EV_FALL_SHORT_NOSOUND",
2001-05-06 20:50:27 +00:00
"EV_FALL_MEDIUM",
2001-07-27 00:21:23 +00:00
"EV_FALL_MEDIUM_NOSOUND",
2001-05-06 20:50:27 +00:00
"EV_FALL_FAR",
2001-07-27 00:21:23 +00:00
"EV_FALL_FAR_NOSOUND",
2001-05-06 20:50:27 +00:00
"EV_JUMP_PAD", // boing sound at origin", jump sound on player
2001-05-06 20:50:27 +00:00
"EV_JUMP",
"EV_WATER_TOUCH", // foot touches
"EV_WATER_LEAVE", // foot leaves
"EV_WATER_UNDER", // head touches
"EV_WATER_CLEAR", // head leaves
"EV_ITEM_PICKUP", // normal item pickups are predictable
2001-05-06 20:50:27 +00:00
"EV_GLOBAL_ITEM_PICKUP", // powerup / team sounds are broadcast to everyone
"EV_NOAMMO",
"EV_CHANGE_WEAPON",
"EV_FIRE_WEAPON",
"EV_RELOAD_WEAPON0", // Elder: reload weapon sounds
"EV_RELOAD_WEAPON1", // Elder: reload weapon sounds
"EV_RELOAD_WEAPON2", // Elder: reload weapon sounds
2001-05-06 20:50:27 +00:00
"EV_USE_ITEM0",
"EV_USE_ITEM1",
"EV_USE_ITEM2",
"EV_USE_ITEM3",
"EV_USE_ITEM4",
"EV_USE_ITEM5",
"EV_USE_ITEM6",
"EV_USE_ITEM7",
"EV_USE_ITEM8",
"EV_USE_ITEM9",
"EV_USE_ITEM10",
"EV_USE_ITEM11",
"EV_USE_ITEM12",
"EV_USE_ITEM13",
"EV_USE_ITEM14",
"EV_USE_ITEM15",
"EV_ITEM_RESPAWN",
"EV_ITEM_POP",
"EV_PLAYER_TELEPORT_IN",
"EV_PLAYER_TELEPORT_OUT",
"EV_GRENADE_BOUNCE", // eventParm will be the soundindex
2001-05-06 20:50:27 +00:00
"EV_GENERAL_SOUND",
"EV_GLOBAL_SOUND", // no attenuation
2001-05-06 20:50:27 +00:00
"EV_GLOBAL_TEAM_SOUND",
"EV_RQ3_SOUND", // Elder: play local sounds - primarily for kick
2001-05-06 20:50:27 +00:00
"EV_DMREWARD", // Duffman: To display exponential reward messages.
2001-06-25 23:45:02 +00:00
2001-05-06 20:50:27 +00:00
"EV_BULLET_HIT_FLESH",
"EV_BULLET_HIT_WALL",
"EV_BULLET_HIT_METAL", // Elder: sparks
"EV_BULLET_HIT_KEVLAR", // Elder: sparks
"EV_BULLET_HIT_GLASS", // Elder: glass mark
"EV_BULLET_HIT_WOOD", // Makro: new sound
"EV_BULLET_HIT_BRICK", // Makro: new sound
2002-05-12 22:14:13 +00:00
"EV_BULLET_HIT_CERAMIC", // Makro: new sound
2003-07-30 16:05:47 +00:00
"EV_BULLET_HIT_SNOW", // Makro: new fx
"EV_BULLET_HIT_GRASS", // Makro: new fx
"EV_SSG3000_HIT_FLESH", // Elder: SSG3000 blood spray
"EV_JUMPKICK", // Elder: sound + jumpkick message
"EV_EJECTBLOOD", // Elder: when bleeding, every 2s release blood
2001-05-06 20:50:27 +00:00
"EV_MISSILE_HIT",
"EV_MISSILE_MISS",
"EV_MISSILE_MISS_METAL",
"EV_KNIFE_MISS", // Elder: knife slash stuff
2001-05-06 20:50:27 +00:00
"EV_RAILTRAIL",
"EV_SHOTGUN",
"EV_HANDCANNON",
"EV_BULLET", // otherEntity is the shooter
2001-05-06 20:50:27 +00:00
"EV_HEADSHOT", // Elder: spray like SSG shot
2001-05-06 20:50:27 +00:00
"EV_PAIN",
"EV_DEATH1",
"EV_DEATH2",
"EV_DEATH3",
"EV_OBITUARY",
//Elder:
//Location-specific obits- need separate events b/c you can't stuff >8bits in eventParm
"EV_OBITUARY_HEAD",
"EV_OBITUARY_CHEST",
"EV_OBITUARY_STOMACH",
"EV_OBITUARY_LEGS",
2001-05-06 20:50:27 +00:00
"EV_GIB_PLAYER", // gib a previously living player
"EV_BREAK_GLASS1", // Blaze: Breakable glass
"EV_BREAK_GLASS2",
"EV_BREAK_GLASS3",
"EV_CHIP_GLASS", // Blaze: this even just breaks it a little bit.
2002-04-23 06:09:18 +00:00
"EV_PRESSURE_WATER", // NiceAss: Shot an ent under pressure with water
"EV_SCOREPLUM", // score plum
2001-05-06 20:50:27 +00:00
"EV_PROXIMITY_MINE_STICK",
"EV_PROXIMITY_MINE_TRIGGER",
"EV_KAMIKAZE", // kamikaze explodes
"EV_OBELISKEXPLODE", // obelisk explodes
"EV_OBELISKPAIN", // obelisk pain
"EV_INVUL_IMPACT", // invulnerability sphere impact
"EV_JUICED", // invulnerability juiced effect
"EV_LIGHTNINGBOLT", // lightning bolt bounced of invulnerability sphere
2001-05-06 20:50:27 +00:00
"EV_DEBUG_LINE",
"EV_STOPLOOPINGSOUND",
"EV_TAUNT",
"EV_TAUNT_YES",
"EV_TAUNT_NO",
"EV_TAUNT_FOLLOWME",
"EV_TAUNT_GETFLAG",
"EV_TAUNT_GUARDBASE",
"EV_TAUNT_PATROL"
2001-05-06 20:50:27 +00:00
};
/*
===============
BG_AddPredictableEventToPlayerstate
Handles the sequence numbers
===============
*/
void trap_Cvar_VariableStringBuffer(const char *var_name, char *buffer, int bufsize);
2001-05-06 20:50:27 +00:00
void BG_AddPredictableEventToPlayerstate(int newEvent, int eventParm, playerState_t * ps)
{
2001-05-06 20:50:27 +00:00
#ifdef _DEBUG
{
char buf[256];
2001-05-06 20:50:27 +00:00
trap_Cvar_VariableStringBuffer("showevents", buf, sizeof(buf));
if (atof(buf) != 0) {
2001-05-06 20:50:27 +00:00
#ifdef QAGAME
Com_Printf(" game event svt %5d -> %5d: num = %20s parm %d\n",
ps->pmove_framecount /*ps->commandTime */ , ps->eventSequence, eventnames[newEvent],
eventParm);
2001-05-06 20:50:27 +00:00
#else
Com_Printf("Cgame event svt %5d -> %5d: num = %20s parm %d\n",
ps->pmove_framecount /*ps->commandTime */ , ps->eventSequence, eventnames[newEvent],
eventParm);
2001-05-06 20:50:27 +00:00
#endif
}
}
#endif
ps->events[ps->eventSequence & (MAX_PS_EVENTS - 1)] = newEvent;
ps->eventParms[ps->eventSequence & (MAX_PS_EVENTS - 1)] = eventParm;
2001-05-06 20:50:27 +00:00
ps->eventSequence++;
}
/*
========================
BG_TouchJumpPad
========================
*/
void BG_TouchJumpPad(playerState_t * ps, entityState_t * jumppad)
{
2001-05-06 20:50:27 +00:00
int effectNum;
// spectators don't use jump pads
if (ps->pm_type != PM_NORMAL) {
2001-05-06 20:50:27 +00:00
return;
}
2002-07-22 06:35:03 +00:00
2002-05-29 13:49:26 +00:00
//Makro - disable all this for bot only triggers
if (!jumppad->powerups) {
// if we didn't hit this same jumppad the previous frame
// then don't play the event sound again if we are in a fat trigger
if (ps->jumppad_ent != jumppad->number) {
2002-05-29 13:49:26 +00:00
/*
vectoangles( jumppad->origin2, angles);
p = fabs( AngleNormalize180( angles[PITCH] ) );
if( p < 45 ) {
effectNum = 0;
} else {
effectNum = 1;
}
*/
2002-05-29 13:49:26 +00:00
// NiceAss: For cutsom sounds...
effectNum = jumppad->generic1;
BG_AddPredictableEventToPlayerstate(EV_JUMP_PAD, effectNum, ps);
2001-05-06 20:50:27 +00:00
}
}
// remember hitting this jumppad this frame
ps->jumppad_ent = jumppad->number;
ps->jumppad_frame = ps->pmove_framecount;
// give the player the velocity from the jumppad
VectorCopy(jumppad->origin2, ps->velocity);
2001-05-06 20:50:27 +00:00
}
/*
========================
BG_PlayerStateToEntityState
This is done after each set of usercmd_t on the server,
and after local prediction on the client
========================
*/
void BG_PlayerStateToEntityState(playerState_t * ps, entityState_t * s, qboolean snap)
{
int i;
2001-05-06 20:50:27 +00:00
if (ps->pm_type == PM_INTERMISSION || ps->pm_type == PM_SPECTATOR) {
2001-05-06 20:50:27 +00:00
s->eType = ET_INVISIBLE;
} else if (ps->stats[STAT_HEALTH] <= GIB_HEALTH) {
2001-05-06 20:50:27 +00:00
s->eType = ET_INVISIBLE;
} else {
s->eType = ET_PLAYER;
}
s->number = ps->clientNum;
s->pos.trType = TR_INTERPOLATE;
VectorCopy(ps->origin, s->pos.trBase);
if (snap) {
SnapVector(s->pos.trBase);
2001-05-06 20:50:27 +00:00
}
// set the trDelta for flag direction
VectorCopy(ps->velocity, s->pos.trDelta);
2001-05-06 20:50:27 +00:00
s->apos.trType = TR_INTERPOLATE;
VectorCopy(ps->viewangles, s->apos.trBase);
if (snap) {
SnapVector(s->apos.trBase);
2001-05-06 20:50:27 +00:00
}
s->angles2[YAW] = ps->movementDir;
s->legsAnim = ps->legsAnim;
s->torsoAnim = ps->torsoAnim;
s->clientNum = ps->clientNum; // ET_PLAYER looks here instead of at number
// so corpses can also reference the proper config
2001-05-06 20:50:27 +00:00
s->eFlags = ps->eFlags;
if (ps->stats[STAT_HEALTH] <= 0) {
2001-05-06 20:50:27 +00:00
s->eFlags |= EF_DEAD;
} else {
s->eFlags &= ~EF_DEAD;
}
if (ps->externalEvent) {
2001-05-06 20:50:27 +00:00
s->event = ps->externalEvent;
s->eventParm = ps->externalEventParm;
} else if (ps->entityEventSequence < ps->eventSequence) {
int seq;
2001-05-06 20:50:27 +00:00
if (ps->entityEventSequence < ps->eventSequence - MAX_PS_EVENTS) {
2001-05-06 20:50:27 +00:00
ps->entityEventSequence = ps->eventSequence - MAX_PS_EVENTS;
}
seq = ps->entityEventSequence & (MAX_PS_EVENTS - 1);
s->event = ps->events[seq] | ((ps->entityEventSequence & 3) << 8);
s->eventParm = ps->eventParms[seq];
2001-08-01 19:52:17 +00:00
ps->entityEventSequence++;
2001-05-06 20:50:27 +00:00
}
s->weapon = ps->weapon;
s->groundEntityNum = ps->groundEntityNum;
s->powerups = 0;
for (i = 0; i < MAX_POWERUPS; i++) {
if (ps->powerups[i]) {
2001-05-06 20:50:27 +00:00
s->powerups |= 1 << i;
}
}
s->loopSound = ps->loopSound;
s->generic1 = ps->generic1;
}
/*
========================
BG_PlayerStateToEntityStateExtraPolate
This is done after each set of usercmd_t on the server,
and after local prediction on the client
========================
*/
void BG_PlayerStateToEntityStateExtraPolate(playerState_t * ps, entityState_t * s, int time, qboolean snap)
{
int i;
2001-05-06 20:50:27 +00:00
if (ps->pm_type == PM_INTERMISSION || ps->pm_type == PM_SPECTATOR) {
2001-05-06 20:50:27 +00:00
s->eType = ET_INVISIBLE;
} else if (ps->stats[STAT_HEALTH] <= GIB_HEALTH) {
2001-05-06 20:50:27 +00:00
s->eType = ET_INVISIBLE;
} else {
s->eType = ET_PLAYER;
}
s->number = ps->clientNum;
s->pos.trType = TR_LINEAR_STOP;
VectorCopy(ps->origin, s->pos.trBase);
if (snap) {
SnapVector(s->pos.trBase);
2001-05-06 20:50:27 +00:00
}
// set the trDelta for flag direction and linear prediction
VectorCopy(ps->velocity, s->pos.trDelta);
2001-05-06 20:50:27 +00:00
// set the time for linear prediction
s->pos.trTime = time;
// set maximum extra polation time
s->pos.trDuration = 50; // 1000 / sv_fps (default = 20)
2001-05-06 20:50:27 +00:00
s->apos.trType = TR_INTERPOLATE;
VectorCopy(ps->viewangles, s->apos.trBase);
if (snap) {
SnapVector(s->apos.trBase);
2001-05-06 20:50:27 +00:00
}
s->angles2[YAW] = ps->movementDir;
s->legsAnim = ps->legsAnim;
s->torsoAnim = ps->torsoAnim;
s->clientNum = ps->clientNum; // ET_PLAYER looks here instead of at number
// so corpses can also reference the proper config
2001-05-06 20:50:27 +00:00
s->eFlags = ps->eFlags;
if (ps->stats[STAT_HEALTH] <= 0) {
2001-05-06 20:50:27 +00:00
s->eFlags |= EF_DEAD;
} else {
s->eFlags &= ~EF_DEAD;
}
if (ps->externalEvent) {
2001-05-06 20:50:27 +00:00
s->event = ps->externalEvent;
s->eventParm = ps->externalEventParm;
} else if (ps->entityEventSequence < ps->eventSequence) {
int seq;
2001-05-06 20:50:27 +00:00
if (ps->entityEventSequence < ps->eventSequence - MAX_PS_EVENTS) {
2001-05-06 20:50:27 +00:00
ps->entityEventSequence = ps->eventSequence - MAX_PS_EVENTS;
}
seq = ps->entityEventSequence & (MAX_PS_EVENTS - 1);
s->event = ps->events[seq] | ((ps->entityEventSequence & 3) << 8);
s->eventParm = ps->eventParms[seq];
2001-08-01 19:52:17 +00:00
ps->entityEventSequence++;
2001-05-06 20:50:27 +00:00
}
s->weapon = ps->weapon;
s->groundEntityNum = ps->groundEntityNum;
s->powerups = 0;
for (i = 0; i < MAX_POWERUPS; i++) {
if (ps->powerups[i]) {
2001-05-06 20:50:27 +00:00
s->powerups |= 1 << i;
}
}
s->loopSound = ps->loopSound;
s->generic1 = ps->generic1;
}
//Makro - weapon string aliases
typedef struct {
const char *name;
weapon_t weapon;
} weaponAlias_t;
weaponAlias_t weaponAliases[] = {
{RQ3_PISTOL_NAME, WP_PISTOL},
{"pistol", WP_PISTOL},
{"mk23", WP_PISTOL},
{RQ3_M3_NAME, WP_M3},
{"m3", WP_M3},
{"shotgun", WP_M3},
{RQ3_HANDCANNON_NAME, WP_HANDCANNON},
{"hc", WP_HANDCANNON},
{RQ3_M4_NAME, WP_M4},
{"m4", WP_M4},
{RQ3_MP5_NAME, WP_MP5},
{"mp5", WP_MP5},
{"mp5/10", WP_MP5},
{RQ3_SSG3000_NAME, WP_SSG3000},
{"sniper", WP_SSG3000},
{"ssg3000", WP_SSG3000},
{"ssg 3000", WP_SSG3000},
{"ssg", WP_SSG3000},
{RQ3_AKIMBO_NAME, WP_AKIMBO},
{"akimbo", WP_AKIMBO},
{RQ3_KNIFE_NAME, WP_KNIFE},
{"knife", WP_KNIFE},
{"knives", WP_KNIFE},
{RQ3_GRENADE_NAME, WP_GRENADE},
{"grenade", WP_GRENADE},
{"grenades", WP_GRENADE},
{NULL, WP_PISTOL}
};
#define num_weapon_aliases 25
weapon_t CharToWeapon(char *name, weapon_t defweapon)
{
int i;
if (!name)
return defweapon;
for (i = 0; weaponAliases[i].name != NULL; i++) {
if (!Q_stricmp(name, weaponAliases[i].name))
return weaponAliases[i].weapon;
}
return defweapon;
}
//Makro - item string aliases
typedef struct {
const char *name;
holdable_t item;
} itemAlias_t;
itemAlias_t itemAliases[] = {
{RQ3_SLIPPERS_NAME, HI_SLIPPERS},
{"slippers", HI_SLIPPERS},
{RQ3_KEVLAR_NAME, HI_KEVLAR},
{"vest", HI_KEVLAR},
{"kevlar", HI_KEVLAR},
{RQ3_BANDOLIER_NAME, HI_BANDOLIER},
{RQ3_LASER_NAME, HI_LASER},
{"laser", HI_LASER},
{RQ3_SILENCER_NAME, HI_SILENCER},
2002-10-30 20:04:34 +00:00
{RQ3_HELMET_NAME, HI_HELMET},
{"helmet", HI_HELMET},
{NULL, HI_KEVLAR}
};
#define num_item_aliases 9
holdable_t CharToItem(char *name, holdable_t defitem)
{
int i;
if (!name)
return defitem;
for (i = 0; itemAliases[i].name != NULL; i++) {
if (!Q_stricmp(name, itemAliases[i].name))
return itemAliases[i].item;
}
return defitem;
}
2002-05-11 19:18:20 +00:00
/*
=====================
Surfaceparm stuff
=====================
*/
int MatFlags[] = {
2002-05-11 19:18:20 +00:00
SURF_METALSTEPS,
SURF_GRAVEL,
SURF_WOOD,
SURF_CARPET,
SURF_METAL2,
SURF_GLASS,
SURF_GRASS,
SURF_SNOW,
SURF_MUD,
SURF_WOOD2,
SURF_HARDMETAL
};
#define MAT_FLAG_COUNT 5
2002-05-11 19:18:20 +00:00
int GetMaterialFromFlag(int flag)
{
2002-05-11 19:18:20 +00:00
int Material = 0;
int i = 0;
for (i = 0; i < MAT_FLAG_COUNT; i++) {
if ((flag & MatFlags[i])) {
2002-05-11 19:18:20 +00:00
Material += (1 << i);
}
}
return Material;
}
2003-03-28 22:26:24 +00:00
//Makro - added
2003-03-29 23:04:56 +00:00
/* char *modelFromStr(char *s)
2003-03-28 22:26:24 +00:00
{
char *p, *out = s;
if (!s)
return NULL;
if ((p = strrchr(s, '/')) != NULL)
2003-03-28 22:26:24 +00:00
{
*p=0;
out=va("%s", s);
*p='/';
}
return out;
2003-03-29 23:04:56 +00:00
} */
2003-03-28 22:26:24 +00:00
2003-03-29 23:04:56 +00:00
/*char *skinFromStr(char *s)
2003-03-28 22:26:24 +00:00
{
char *p;
if (!s)
return NULL;
if (!*s)
return va("");
if ((p = strrchr(s, '/')) != NULL)
2003-03-28 22:26:24 +00:00
return p+1;
return va("default");
2003-03-29 23:04:56 +00:00
} */
// NiceAss: rewriting to avoid va() overriting data.
char *modelFromStr(char *s)
{
static char buffer[128];
char *p;
if (!s)
return NULL;
strncpy(buffer, s, sizeof(buffer));
if ((p = strrchr(buffer, '/')) != NULL)
2003-03-29 23:04:56 +00:00
*p = '\0';
return buffer;
}
char *skinFromStr(char *s)
{
static char buffer[128];
char *p;
memset(buffer, 0, sizeof(buffer));
2003-03-29 23:04:56 +00:00
if (!s)
return NULL;
if (!*s)
return buffer;
strncpy(buffer, s, 128);
if ((p = strrchr(buffer, '/')) != NULL)
2003-03-29 23:04:56 +00:00
return p+1;
strcpy(buffer, "default");
return buffer;
2003-03-28 22:26:24 +00:00
}
char *strchrstr(char *s, char *chars)
{
if (!s || !chars)
return NULL;
while (*s)
if (strchr(chars, *s))
return s;
else
s++;
return NULL;
}
2003-03-31 21:04:24 +00:00
char *strins(char *dest, char *s)
{
int i, l1 = strlen(dest), l2 = strlen(s);
for (i=l1; i>=0; i--)
dest[i+l2]=dest[i];
for (i=0; i<l2; i++)
dest[i]=s[i];
return dest;
}
char *Q_strins(char *dest, char *s, int size)
{
int l1, l2, i;
if (!dest || !s)
return NULL;
l1 = strlen(dest);
l2 = strlen(s);
if (l2+1 > size)
l2 = size - 1;
if (l1+l2+1 > size)
{
l1 = size - l2 - 1;
dest[l1]=0;
}
for (i=l1; i>=0; i--)
dest[i+l2]=dest[i];
for (i=0; i<l2; i++)
dest[i]=s[i];
return dest;
}
2005-09-07 20:27:42 +00:00
//Makro - used for saving ints to char buffers
//not doing this as a simple assignment because
//of endianness (darned Mac users)
void SetIntBytes(int i, char *buf, char count)
{
while (count--)
{
*buf++ = i & 255;
i >>= 8;
}
}
int GetIntBytes(char *buf, char count)
{
int rez = 0, shift = 0;
while (count--)
{
rez |= (*buf << shift);
shift += 8;
}
return rez;
}
2006-04-14 18:16:31 +00:00
/*
====================================================
IdMatchesString
Returns 1 if any of the tokens in the first string
matches any of the tokens in the second string
Added by Makro
====================================================
*/
#define IS_DELIM(x) ((x)==',' || (x)==' ' || (x)=='\t')
#define SKIP_DELIM(s) while (IS_DELIM(*(s))) (s)++
qboolean IdMatchesString(const char *id, const char *match)
{
const char *tok1, *tok2;
// iterate through all the tokens in "id"
while (id && *id)
{
int len1;
const char *tomatch = match;
// find the end of the current token
for (tok1=id, len1=0; *tok1 && !IS_DELIM(*tok1); tok1++, len1++) {}
// skip all delimiters
SKIP_DELIM(tok1);
// iterate through all the tokens in "match"
while (match && *match)
{
int len2;
char ok = 1;
// find the end of the current token
for (tok2=match, len2=0; *tok2 && !IS_DELIM(*tok2); tok2++, len2++)
{
if (ok)
if (len2 > len1 || toupper(*tok2) != toupper(id[len2]))
ok = 0;
}
// skip all delimiters
SKIP_DELIM(tok2);
if (len1 == len2 && ok)
return qtrue;
// fetch next token in "match"
match = tok2;
}
// restore "match" string
match = tomatch;
// fetch next token in "id"
id = tok1;
}
return qfalse;
}
float SawTooth(int time, int period)
{
if (period <= 0)
return 0;
else
{
if ((time / period) & 1)
return (time % period) / ((float)period);
else
return 1.0f - (time % period) / ((float)period);
}
}
2011-03-10 18:52:13 +00:00
float SmoothLerp(float x)
{
return x * x * (3.f - 2.f * x);
}