2019-03-13 19:20:07 +00:00
|
|
|
/*
|
2020-06-04 21:01:28 +00:00
|
|
|
===========================================================================
|
2019-03-13 19:20:07 +00:00
|
|
|
Copyright (C) 1997-2001 Id Software, Inc.
|
|
|
|
Copyright (C) 2000-2002 Mr. Hyde and Mad Dog
|
|
|
|
|
2020-06-04 21:01:28 +00:00
|
|
|
This file is part of Lazarus Quake 2 Mod source code.
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-06-04 21:01:28 +00:00
|
|
|
Lazarus Quake 2 Mod source code is free software; you can redistribute it
|
|
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
|
|
or (at your option) any later version.
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-06-04 21:01:28 +00:00
|
|
|
Lazarus Quake 2 Mod source code is distributed in the hope that it will be
|
|
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2019-03-13 19:20:07 +00:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2020-06-04 21:01:28 +00:00
|
|
|
along with Lazarus Quake 2 Mod source code; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
===========================================================================
|
2019-03-13 19:20:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "g_local.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
//#ifdef KMQUAKE2_ENGINE_MOD
|
|
|
|
//#define NEW_FOGSYS
|
|
|
|
//#endif
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Fog is sent to engine like this:
|
|
|
|
// gi.WriteByte (svc_fog); // svc_fog = 21
|
|
|
|
// gi.WriteByte (fog_enable); // 1 = on, 0 = off
|
|
|
|
// gi.WriteByte (fog_model); // 0, 1, or 2
|
|
|
|
// gi.WriteByte (fog_density); // 1-100
|
2020-04-07 06:02:54 +00:00
|
|
|
// gi.WriteShort (fog_near); // >0, < fog_far
|
|
|
|
// gi.WriteShort (fog_far); // >fog_near-64, < 10000
|
2019-03-13 19:20:07 +00:00
|
|
|
// gi.WriteByte (fog_red); // 0-255
|
|
|
|
// gi.WriteByte (fog_green); // 0-255
|
|
|
|
// gi.WriteByte (fog_blue); // 0-255
|
|
|
|
// gi.unicast (player_ent, true);
|
|
|
|
|
|
|
|
#ifdef DISABLE_FOG
|
|
|
|
|
2019-03-13 23:54:41 +00:00
|
|
|
void Fog_Init (void) {}
|
2019-03-13 19:20:07 +00:00
|
|
|
void Fog (edict_t *ent) {}
|
2020-04-07 06:02:54 +00:00
|
|
|
void Fog_Off (edict_t *ent) {}
|
|
|
|
void Fog_Off_Global (void) {}
|
2019-03-13 23:54:41 +00:00
|
|
|
void Fog_ConsoleFog (void) {}
|
|
|
|
void GLFog (void) {}
|
2019-03-13 19:20:07 +00:00
|
|
|
void trig_fog_fade (edict_t *self) {}
|
|
|
|
void init_trigger_fog_delay (edict_t *self) {}
|
|
|
|
void fog_fade (edict_t *self) {}
|
|
|
|
void target_fog_use (edict_t *self, edict_t *other, edict_t *activator) {}
|
|
|
|
void trigger_fog_use (edict_t *self, edict_t *other, edict_t *activator) {}
|
|
|
|
void SP_trigger_fog (edict_t *self)
|
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
}
|
|
|
|
void SP_trigger_fog_bbox (edict_t *self)
|
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
}
|
|
|
|
void SP_target_fog (edict_t *self)
|
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
}
|
|
|
|
void Cmd_Fog_f (edict_t *ent) {}
|
|
|
|
|
|
|
|
#else // DISABLE_FOG
|
|
|
|
|
|
|
|
#ifdef NEW_FOGSYS // new multi-client fog code here
|
|
|
|
/*
|
|
|
|
=================================================
|
|
|
|
NEW FOG SYSTEM
|
|
|
|
=================================================
|
|
|
|
*/
|
|
|
|
|
2019-03-13 23:54:41 +00:00
|
|
|
void Client_Fog_Off (edict_t *player_ent)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!player_ent || !player_ent->client || player_ent->is_bot)
|
2019-03-13 19:20:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
gi.WriteByte (svc_fog); // svc_fog = 21
|
|
|
|
gi.WriteByte (0); // disable message, remaining paramaters are ignored
|
|
|
|
gi.WriteByte (0); // 0, 1, or 2
|
|
|
|
gi.WriteByte (0); // 1-100
|
|
|
|
gi.WriteShort (0); // >0, <fog_far
|
2020-04-07 06:02:54 +00:00
|
|
|
gi.WriteShort (0); // >fog_near-64, < 10000
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.WriteByte (0); // 0-255
|
|
|
|
gi.WriteByte (0); // 0-255
|
|
|
|
gi.WriteByte (0); // 0-255
|
|
|
|
gi.unicast (player_ent, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#else // NEW_FOGSYS
|
|
|
|
/*
|
|
|
|
=================================================
|
|
|
|
OLD FOG SYSTEM
|
|
|
|
=================================================
|
|
|
|
*/
|
|
|
|
#ifdef KMQUAKE2_ENGINE_MOD // engine fog
|
|
|
|
|
|
|
|
#define GL_LINEAR 0x2601
|
|
|
|
#define GL_EXP 0x0800
|
|
|
|
#define GL_EXP2 0x0801
|
|
|
|
|
|
|
|
#else // old sever-side fog
|
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#define __MSC__
|
|
|
|
#include <gl/gl.h>
|
|
|
|
|
|
|
|
#endif // KMQUAKE2_ENGINE_MOD
|
|
|
|
|
|
|
|
fog_t gfogs[MAX_FOGS];
|
|
|
|
|
|
|
|
fog_t trig_fade_fog;
|
|
|
|
fog_t fade_fog;
|
|
|
|
fog_t *pfog;
|
|
|
|
|
|
|
|
qboolean InTriggerFog;
|
|
|
|
float last_software_frame;
|
|
|
|
float last_opengl_frame;
|
|
|
|
|
|
|
|
int GLModels[3] = {GL_LINEAR, GL_EXP, GL_EXP2};
|
|
|
|
|
|
|
|
#ifdef KMQUAKE2_ENGINE_MOD // engine fog
|
|
|
|
int last_fog_model, last_fog_density, last_fog_near, last_fog_far, last_fog_color[3];
|
|
|
|
|
|
|
|
#else // old sever-side fog
|
|
|
|
|
|
|
|
HMODULE hOpenGL;
|
|
|
|
typedef void (WINAPI *GLCLEARCOLOR) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
|
|
|
|
typedef void (WINAPI *GLDISABLE) (GLenum cap);
|
|
|
|
typedef void (WINAPI *GLENABLE) (GLenum cap);
|
|
|
|
typedef void (WINAPI *GLFOGF) (GLenum pname, GLfloat param);
|
|
|
|
typedef void (WINAPI *GLFOGFV) (GLenum pname, const GLfloat *params);
|
|
|
|
typedef void (WINAPI *GLFOGI) (GLenum pname, GLint param);
|
|
|
|
typedef void (WINAPI *GLHINT) (GLenum target, GLenum mode);
|
|
|
|
GLCLEARCOLOR GL_glClearColor;
|
|
|
|
GLDISABLE GL_glDisable;
|
|
|
|
GLENABLE GL_glEnable;
|
|
|
|
GLFOGF GL_glFogf;
|
|
|
|
GLFOGFV GL_glFogfv;
|
|
|
|
GLFOGI GL_glFogi;
|
|
|
|
GLHINT GL_glHint;
|
|
|
|
#endif // KMQUAKE2_ENGINE_MOD
|
|
|
|
|
|
|
|
#define FOG_ON 1
|
|
|
|
#define FOG_TOGGLE 2
|
|
|
|
#define FOG_TURNOFF 4
|
|
|
|
#define FOG_STARTOFF 8
|
|
|
|
|
|
|
|
#define COLOR(r,g,b) ((((BYTE)(b)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(r))<<16)))
|
|
|
|
|
|
|
|
void fog_fade (edict_t *self);
|
|
|
|
|
|
|
|
void Fog_ConsoleFog (void)
|
|
|
|
{
|
|
|
|
// This routine is ONLY called for console fog commands
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (deathmatch->value || coop->value)
|
2019-03-13 19:20:07 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!level.active_fog) return;
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&level.current_fog, &gfogs[0], sizeof(fog_t));
|
|
|
|
pfog = &level.current_fog;
|
2019-03-13 19:20:07 +00:00
|
|
|
|
|
|
|
// Force sensible values for linear:
|
2020-04-07 06:02:54 +00:00
|
|
|
if ( (pfog->Model == 0) && (pfog->Near == 0.0f) && (pfog->Far == 0.0f) )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
pfog->Near=64;
|
|
|
|
pfog->Far=1024;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Cmd_Say_f (edict_t *ent, qboolean team, qboolean arg0);
|
|
|
|
void Cmd_Fog_f (edict_t *ent)
|
|
|
|
{
|
|
|
|
char *cmd;
|
|
|
|
char *parm;
|
|
|
|
fog_t *fog;
|
|
|
|
|
|
|
|
fog = &gfogs[0];
|
|
|
|
cmd = gi.argv(0);
|
2020-04-07 06:02:54 +00:00
|
|
|
if (gi.argc() < 2)
|
2019-03-13 19:20:07 +00:00
|
|
|
parm = NULL;
|
|
|
|
else
|
|
|
|
parm = gi.argv(1);
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!ent || !ent->client || ent->is_bot)
|
|
|
|
return;
|
|
|
|
|
2019-03-13 19:20:07 +00:00
|
|
|
if (Q_stricmp (cmd, "fog_help") == 0 )
|
|
|
|
{
|
|
|
|
gi.dprintf("Fog parameters for console only.\n"
|
|
|
|
"Use fog_active to see parameters for currently active fog.\n");
|
|
|
|
|
|
|
|
gi.dprintf("\nUse \"fog [0/1]\" to turn fog off/on (currently %s)\n"
|
|
|
|
"Current GL driver is %s\n",(level.active_fog > 0 ? "on" : "off"), gl_driver->string);
|
|
|
|
|
|
|
|
gi.dprintf("Fog_Red = red component (0-1)\n"
|
|
|
|
"Fog_Grn = green component (0-1)\n"
|
|
|
|
"Fog_Blu = blue component (0-1)\n"
|
|
|
|
"Fog_Model 0=linear, 1=exponential, 2=exponential squared\n\n"
|
|
|
|
"Linear parameters:\n"
|
|
|
|
"Fog_Near = fog start distance (>0 and < Fog_Far)\n"
|
|
|
|
"Fog_Far = distance where objects are completely obscured\n"
|
2020-04-07 06:02:54 +00:00
|
|
|
" (<10000 and > Fog_Near)\n"
|
2019-03-13 19:20:07 +00:00
|
|
|
"Exponential parameters:\n"
|
|
|
|
"Fog_Density Best results with values < 100\n\n"
|
|
|
|
"Command without a value will show current setting\n");
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "fog_active") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.active_fog)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("Active fog:\n"
|
|
|
|
" Color: %f, %f, %f\n"
|
|
|
|
" Model: %s\n",
|
2020-04-07 06:02:54 +00:00
|
|
|
level.current_fog.Color[0], level.current_fog.Color[1], level.current_fog.Color[2],
|
|
|
|
((level.current_fog.Model == 1) ? "Exp" : ((level.current_fog.Model == 2) ? "Exp2" : "Linear")));
|
|
|
|
if (level.current_fog.Model)
|
|
|
|
gi.dprintf("Density: %f\n", level.current_fog.Density);
|
2019-03-13 19:20:07 +00:00
|
|
|
else
|
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
gi.dprintf(" Near: %f\n", level.current_fog.Near);
|
|
|
|
gi.dprintf(" Far: %f\n", level.current_fog.Far);
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gi.dprintf("No fogs currently active\n");
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "fog_stuff") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("active_fog=%d, last_active_fog=%d\n",level.active_fog,level.last_active_fog);
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "fog") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
int on;
|
|
|
|
on = atoi(parm);
|
|
|
|
level.active_fog = level.active_target_fog = (on ? 1 : 0);
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
gi.dprintf("fog is %s\n",(level.active_fog ? "on" : "off"));
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_Red") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("%s = %f\n",cmd,fog->Color[0]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.active_fog = level.active_target_fog = 1;
|
|
|
|
fog->Color[0] = max(0.0f,min(1.0f,(float)atof(parm)));
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_Grn") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("%s = %f\n",cmd,fog->Color[1]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.active_fog = level.active_target_fog = 1;
|
|
|
|
fog->Color[1] = max(0.0f,min(1.0f,(float)atof(parm)));
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_Blu") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("%s = %f\n",cmd,fog->Color[2]);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.active_fog = level.active_target_fog = 1;
|
|
|
|
fog->Color[2] = max(0.0f,min(1.0f,(float)atof(parm)));
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_Near") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("%s = %f\n",cmd,fog->Near);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.active_fog = level.active_target_fog = 1;
|
|
|
|
fog->Near = (float)atof(parm);
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_Far") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("%s = %f\n",cmd,fog->Far);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.active_fog = level.active_target_fog = 1;
|
|
|
|
fog->Far = (float)atof(parm);
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_Model") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("%s = %d\n0=Linear\n1=Exp\n2=Exp2\n",cmd,fog->Model);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.active_fog = level.active_target_fog = 1;
|
|
|
|
//fog->Model = max(0,min(2,atoi(parm)));
|
|
|
|
fog->Model = max(0,min(3,atoi(parm)));
|
2020-04-07 06:02:54 +00:00
|
|
|
if (fog->Model == 3)
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->GL_Model = GLModels[2];
|
|
|
|
else
|
|
|
|
fog->GL_Model = GLModels[fog->Model];
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_Density") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!parm)
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("%s = %f\n",cmd,fog->Density);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
level.active_fog = level.active_target_fog = 1;
|
|
|
|
fog->Density = fog->Density1 = fog->Density2 = (float)atof(parm);
|
|
|
|
Fog_ConsoleFog();
|
|
|
|
}
|
|
|
|
}
|
2019-06-29 07:33:32 +00:00
|
|
|
else if (Q_stricmp (cmd, "Fog_List") == 0 )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2019-06-29 07:33:32 +00:00
|
|
|
int i;
|
|
|
|
fog_t *cFog;
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
gi.dprintf("level.num_fogs=%d\n", level.num_fogs);
|
|
|
|
gi.dprintf("level.num_trigger_fogs=%d\n", level.num_trigger_fogs);
|
|
|
|
for (i=0; i<level.num_fogs; i++)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2019-06-29 07:33:32 +00:00
|
|
|
cFog = &gfogs[i];
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("Fog #%d\n",i+1);
|
2020-04-07 06:02:54 +00:00
|
|
|
gi.dprintf("Trigger=%s\n", (cFog->Trigger ? "true" : "false"));
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.dprintf("Model=%d, Near=%g, Far=%g, Density=%g\n",
|
2019-06-29 07:33:32 +00:00
|
|
|
cFog->Model, cFog->Near, cFog->Far, cFog->Density);
|
2020-04-07 06:02:54 +00:00
|
|
|
gi.dprintf("Color=%g,%g,%g\n", cFog->Color[0],cFog->Color[1],cFog->Color[2]);
|
|
|
|
gi.dprintf("Targetname=%s\n", (cFog->ent ? cFog->ent->targetname : "no ent"));
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Cmd_Say_f (ent, false, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-04-07 06:02:54 +00:00
|
|
|
void SoftwareFog (edict_t *ent)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!ent || !ent->client) // || ent->is_bot)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ent->client->fadein = level.framenum - 1;
|
|
|
|
ent->client->fadehold = level.framenum + 2;
|
|
|
|
ent->client->fadeout = 0.0f;
|
|
|
|
ent->client->fadecolor[0] = pfog->Color[0];
|
|
|
|
ent->client->fadecolor[1] = pfog->Color[1];
|
|
|
|
ent->client->fadecolor[2] = pfog->Color[2];
|
|
|
|
|
|
|
|
if (pfog->Model == 0)
|
|
|
|
ent->client->fadealpha = pfog->Far / 256.0f;
|
|
|
|
else if (pfog->Model == 1)
|
|
|
|
ent->client->fadealpha = pfog->Density / 30.0f;
|
2019-03-13 19:20:07 +00:00
|
|
|
else
|
2020-04-07 06:02:54 +00:00
|
|
|
ent->client->fadealpha = pfog->Density / 15.0f;
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (ent->client->fadealpha > 0.9f)
|
|
|
|
ent->client->fadealpha = 0.9f;
|
2019-03-13 19:20:07 +00:00
|
|
|
|
|
|
|
last_software_frame = level.framenum;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
void GLFog (edict_t *ent)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
#ifdef KMQUAKE2_ENGINE_MOD // engine fog
|
2020-04-07 06:02:54 +00:00
|
|
|
// edict_t *player_ent = &g_edicts[1];
|
2019-03-13 19:20:07 +00:00
|
|
|
int fog_model, fog_density, fog_near, fog_far, fog_color[3];
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!ent || !ent->client || ent->is_bot)
|
2019-03-13 19:20:07 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (pfog->GL_Model == GL_EXP)
|
|
|
|
fog_model = 1;
|
|
|
|
else if (pfog->GL_Model == GL_EXP2)
|
|
|
|
fog_model = 2;
|
|
|
|
else // GL_LINEAR
|
|
|
|
fog_model = 0;
|
|
|
|
|
|
|
|
fog_density = (int)(pfog->Density);
|
|
|
|
fog_near = (int)(pfog->Near);
|
|
|
|
fog_far = (int)(pfog->Far);
|
|
|
|
fog_color[0] = (int)(pfog->Color[0]*255);
|
|
|
|
fog_color[1] = (int)(pfog->Color[1]*255);
|
|
|
|
fog_color[2] = (int)(pfog->Color[2]*255);
|
|
|
|
|
|
|
|
// check for change in fog state before updating
|
|
|
|
if ( fog_model == last_fog_model &&
|
|
|
|
fog_density == last_fog_density &&
|
|
|
|
fog_near == last_fog_near &&
|
|
|
|
fog_far == last_fog_far &&
|
|
|
|
fog_color[0] == last_fog_color[0] &&
|
|
|
|
fog_color[1] == last_fog_color[1] &&
|
|
|
|
fog_color[2] == last_fog_color[2] )
|
|
|
|
return;
|
|
|
|
|
|
|
|
gi.WriteByte (svc_fog); // svc_fog = 21
|
|
|
|
gi.WriteByte (1); // enable message
|
|
|
|
gi.WriteByte (fog_model); // model 0, 1, or 2
|
|
|
|
gi.WriteByte (fog_density); // density 1-100
|
2020-04-07 06:02:54 +00:00
|
|
|
gi.WriteShort (fog_near); // near >0, < fog_far
|
|
|
|
gi.WriteShort (fog_far); // far >fog_near-64, < 10000
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.WriteByte (fog_color[0]); // red 0-255
|
|
|
|
gi.WriteByte (fog_color[1]); // green 0-255
|
|
|
|
gi.WriteByte (fog_color[2]); // blue 0-255
|
2020-04-07 06:02:54 +00:00
|
|
|
gi.unicast (ent, true);
|
2019-03-13 19:20:07 +00:00
|
|
|
|
|
|
|
// write to last fog state
|
|
|
|
last_fog_model = fog_model;
|
|
|
|
last_fog_density = fog_density;
|
|
|
|
last_fog_near = fog_near;
|
|
|
|
last_fog_far = fog_far;
|
|
|
|
VectorCopy (fog_color, last_fog_color);
|
|
|
|
|
|
|
|
#else // old sever-side fog
|
|
|
|
|
|
|
|
GLfloat fogColor[4];
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!hOpenGL) return;
|
2019-03-13 19:20:07 +00:00
|
|
|
fogColor[0] = pfog->Color[0];
|
|
|
|
fogColor[1] = pfog->Color[1];
|
|
|
|
fogColor[2] = pfog->Color[2];
|
|
|
|
fogColor[3] = 1.0;
|
|
|
|
GL_glEnable (GL_FOG); // turn on fog, otherwise you won't see any
|
|
|
|
GL_glClearColor ( fogColor[0], fogColor[1], fogColor[2], fogColor[3]); // Clear the background color to the fog color
|
|
|
|
GL_glFogi (GL_FOG_MODE, pfog->GL_Model);
|
|
|
|
GL_glFogfv (GL_FOG_COLOR, fogColor);
|
2020-04-07 06:02:54 +00:00
|
|
|
if (pfog->GL_Model == GL_LINEAR)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
GL_glFogf (GL_FOG_START, pfog->Near);
|
|
|
|
GL_glFogf (GL_FOG_END, pfog->Far);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
GL_glFogf (GL_FOG_DENSITY, pfog->Density/10000.f);
|
|
|
|
GL_glHint (GL_FOG_HINT, GL_NICEST);
|
|
|
|
#endif // KMQUAKE2_ENGINE_MOD
|
|
|
|
|
|
|
|
last_opengl_frame = level.framenum;
|
|
|
|
}
|
|
|
|
|
|
|
|
void trig_fog_fade (edict_t *self)
|
|
|
|
{
|
|
|
|
float frames;
|
|
|
|
int index;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!InTriggerFog)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
self->nextthink = 0;
|
|
|
|
return;
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.framenum <= self->goal_frame)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
index = self->fog_index-1;
|
|
|
|
frames = self->goal_frame - level.framenum + 1;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (trig_fade_fog.Model == 0)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
trig_fade_fog.Near += (gfogs[index].Near - trig_fade_fog.Near)/frames;
|
|
|
|
trig_fade_fog.Far += (gfogs[index].Far - trig_fade_fog.Far )/frames;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
trig_fade_fog.Density += (gfogs[index].Density - trig_fade_fog.Density) /frames;
|
|
|
|
trig_fade_fog.Density1 += (gfogs[index].Density1 - trig_fade_fog.Density1)/frames;
|
|
|
|
trig_fade_fog.Density2 += (gfogs[index].Density2 - trig_fade_fog.Density2)/frames;
|
|
|
|
}
|
|
|
|
trig_fade_fog.Color[0] += (gfogs[index].Color[0] - trig_fade_fog.Color[0])/frames;
|
|
|
|
trig_fade_fog.Color[1] += (gfogs[index].Color[1] - trig_fade_fog.Color[1])/frames;
|
|
|
|
trig_fade_fog.Color[2] += (gfogs[index].Color[2] - trig_fade_fog.Color[2])/frames;
|
|
|
|
trig_fade_fog.GL_Model = GLModels[trig_fade_fog.Model];
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
|
|
|
gi.linkentity(self);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void init_trigger_fog_delay (edict_t *self)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int index;
|
|
|
|
edict_t *e;
|
|
|
|
|
|
|
|
index = self->fog_index-1;
|
|
|
|
|
|
|
|
// scan for other trigger_fog's that are currently "thinking", iow
|
|
|
|
// the trigger_fog has a delay and is ramping. If found, stop the ramp for those fogs
|
2020-04-07 06:02:54 +00:00
|
|
|
for (i=1, e=g_edicts+i; i<globals.num_edicts; i++, e++)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!e->inuse) continue;
|
|
|
|
if (e == self) continue;
|
|
|
|
if (e->think == trig_fog_fade || e->think == fog_fade)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
e->think = NULL;
|
|
|
|
e->nextthink = 0;
|
|
|
|
gi.linkentity(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self->spawnflags |= FOG_ON;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!level.active_fog)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
// Fog isn't currently on
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&level.current_fog, &gfogs[index], sizeof(fog_t));
|
|
|
|
level.current_fog.Near = 4999.0f;
|
|
|
|
level.current_fog.Far = 5000.0f;
|
|
|
|
level.current_fog.Density = 0.0f;
|
|
|
|
level.current_fog.Density1 = 0.0f;
|
|
|
|
level.current_fog.Density2 = 0.0f;
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
VectorCopy(self->fog_color,gfogs[index].Color);
|
|
|
|
gfogs[index].Near = self->fog_near;
|
|
|
|
gfogs[index].Far = self->fog_far;
|
|
|
|
gfogs[index].Density = self->fog_density;
|
|
|
|
gfogs[index].Density1 = self->fog_density;
|
|
|
|
gfogs[index].Density2 = self->density;
|
|
|
|
self->goal_frame = level.framenum + self->delay*10 + 1;
|
|
|
|
self->think = trig_fog_fade;
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&trig_fade_fog, &level.current_fog, sizeof(fog_t));
|
2019-03-13 19:20:07 +00:00
|
|
|
level.active_fog = self->fog_index;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
void Fog (edict_t *ent)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
edict_t *triggerfog;
|
2020-04-07 06:02:54 +00:00
|
|
|
// edict_t *player = ent; //&g_edicts[1];
|
2019-03-13 19:20:07 +00:00
|
|
|
vec3_t viewpoint;
|
|
|
|
|
|
|
|
if (!gl_driver || !vid_ref)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (deathmatch->value || coop->value)
|
|
|
|
return;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!ent || !ent->client || ent->is_bot)
|
2019-03-13 19:20:07 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
VectorCopy(ent->s.origin, viewpoint);
|
2019-03-13 19:20:07 +00:00
|
|
|
viewpoint[2] += ent->viewheight;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (Q_stricmp(vid_ref->string,"gl"))
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
last_software_frame = level.framenum;
|
|
|
|
level.active_fog = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
InTriggerFog = false;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.num_trigger_fogs)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int trigger;
|
2020-04-07 06:02:54 +00:00
|
|
|
trigger = 0;
|
|
|
|
for (i=1; i<level.num_fogs; i++)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!gfogs[i].Trigger) continue;
|
|
|
|
if (!gfogs[i].ent->inuse) continue;
|
|
|
|
if (!(gfogs[i].ent->spawnflags & FOG_ON)) continue;
|
|
|
|
if (viewpoint[0] < gfogs[i].ent->absmin[0]) continue;
|
|
|
|
if (viewpoint[0] > gfogs[i].ent->absmax[0]) continue;
|
|
|
|
if (viewpoint[1] < gfogs[i].ent->absmin[1]) continue;
|
|
|
|
if (viewpoint[1] > gfogs[i].ent->absmax[1]) continue;
|
|
|
|
if (viewpoint[2] < gfogs[i].ent->absmin[2]) continue;
|
|
|
|
if (viewpoint[2] > gfogs[i].ent->absmax[2]) continue;
|
2019-03-13 19:20:07 +00:00
|
|
|
trigger = i;
|
|
|
|
break;
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
if (trigger)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
InTriggerFog = true;
|
|
|
|
triggerfog = gfogs[trigger].ent;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.last_active_fog != trigger+1)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (triggerfog->delay)
|
2019-03-13 19:20:07 +00:00
|
|
|
init_trigger_fog_delay(triggerfog);
|
|
|
|
else
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&level.current_fog, &gfogs[trigger], sizeof(fog_t));
|
2019-03-13 19:20:07 +00:00
|
|
|
level.active_fog = trigger+1;
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (triggerfog->delay)
|
|
|
|
memcpy(&level.current_fog, &trig_fade_fog, sizeof(fog_t));
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
InTriggerFog = false;
|
|
|
|
level.active_fog = level.active_target_fog;
|
|
|
|
// if we are just coming out of a trigger_fog, force
|
2020-04-07 06:02:54 +00:00
|
|
|
// level.current_fog to last active target_fog values
|
|
|
|
if (level.active_fog && level.last_active_fog && gfogs[level.last_active_fog-1].Trigger)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
edict_t *ent = gfogs[level.active_fog-1].ent;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (ent && (ent->think == fog_fade))
|
2019-03-13 19:20:07 +00:00
|
|
|
ent->think(ent);
|
|
|
|
else
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&level.current_fog, &gfogs[level.active_fog-1], sizeof(fog_t));
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!level.active_fog)
|
|
|
|
{
|
|
|
|
if (level.last_active_fog)
|
2020-04-07 06:02:54 +00:00
|
|
|
Fog_Off (ent);
|
2019-03-13 19:20:07 +00:00
|
|
|
level.last_active_fog = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
pfog = &level.current_fog;
|
|
|
|
if ((pfog->Density1 != pfog->Density2) && (game.maxclients == 1) && (pfog->Model))
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
float density;
|
|
|
|
float dp;
|
|
|
|
vec3_t vp;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
AngleVectors(ent->client->ps.viewangles,vp,0,0);
|
2019-03-13 19:20:07 +00:00
|
|
|
dp = DotProduct(pfog->Dir,vp) + 1.0;
|
|
|
|
density = ((pfog->Density1*dp) + (pfog->Density2*(2.0-dp)))/2.;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (pfog->Density != density)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
pfog->Density = density;
|
|
|
|
}
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
GLFog (ent);
|
2019-03-13 19:20:07 +00:00
|
|
|
level.last_active_fog = level.active_fog;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
void Fog_Off (edict_t *ent)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
if (deathmatch->value || coop->value)
|
|
|
|
return;
|
|
|
|
|
2019-03-14 00:30:02 +00:00
|
|
|
// If game is shutting down, g_edicts will likely be invalid
|
|
|
|
// and the client will clear the fog automatically
|
2020-04-07 06:02:54 +00:00
|
|
|
// if (gameShutdown)
|
|
|
|
// return;
|
|
|
|
|
|
|
|
if (!ent || !ent->client || ent->is_bot)
|
2019-03-14 00:30:02 +00:00
|
|
|
return;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
#ifdef KMQUAKE2_ENGINE_MOD // engine fog
|
|
|
|
|
|
|
|
gi.WriteByte (svc_fog); // svc_fog = 21
|
|
|
|
gi.WriteByte (0); // disable message, remaining paramaters are ignored
|
|
|
|
gi.WriteByte (0); // 0, 1, or 2
|
|
|
|
gi.WriteByte (0); // 1-100
|
|
|
|
gi.WriteShort (0); // >0, < fog_far
|
|
|
|
gi.WriteShort (0); // >fog_near-64, < 10000
|
|
|
|
gi.WriteByte (0); // 0-255
|
|
|
|
gi.WriteByte (0); // 0-255
|
|
|
|
gi.WriteByte (0); // 0-255
|
|
|
|
gi.unicast (ent, true);
|
|
|
|
|
|
|
|
// write to last fog state
|
|
|
|
last_fog_model = last_fog_density = last_fog_near = last_fog_far = 0;
|
|
|
|
VectorSet (last_fog_color, 255, 255, 255);
|
2019-03-13 19:20:07 +00:00
|
|
|
|
|
|
|
#else // old sever-side fog
|
|
|
|
|
|
|
|
if (gl_driver && vid_ref)
|
|
|
|
{
|
|
|
|
if (!strcmp(vid_ref->string,"gl"))
|
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (hOpenGL)
|
|
|
|
GL_glDisable (GL_FOG);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ent->client->fadein = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // KMQUAKE2_ENGINE_MOD
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fog_Off_Global (void)
|
|
|
|
{
|
|
|
|
#ifndef KMQUAKE2_ENGINE_MOD // old sever-side fog
|
|
|
|
if (gl_driver && vid_ref)
|
|
|
|
{
|
|
|
|
if (!strcmp(vid_ref->string, "gl"))
|
|
|
|
{
|
|
|
|
if (hOpenGL)
|
|
|
|
GL_glDisable (GL_FOG);
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
edict_t *player;
|
|
|
|
|
|
|
|
player = &g_edicts[1];
|
|
|
|
player->client->fadein = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // KMQUAKE2_ENGINE_MOD
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fog_Init (void)
|
|
|
|
{
|
|
|
|
#ifndef KMQUAKE2_ENGINE_MOD
|
|
|
|
char GL_Lib[64];
|
|
|
|
|
|
|
|
if (gl_driver_fog && strlen(gl_driver_fog->string))
|
|
|
|
// strncpy(GL_Lib, gl_driver_fog->string);
|
|
|
|
Q_strncpyz(GL_Lib, gl_driver_fog->string, sizeof(GL_Lib));
|
|
|
|
else
|
|
|
|
// strncpy(GL_Lib, "opengl32");
|
|
|
|
Q_strncpyz(GL_Lib, "opengl32", sizeof(GL_Lib));
|
|
|
|
// strncat(GL_Lib,".dll");
|
|
|
|
Q_strncatz(GL_Lib,".dll", sizeof(GL_Lib));
|
|
|
|
hOpenGL = LoadLibrary(GL_Lib);
|
|
|
|
if (hOpenGL)
|
|
|
|
{
|
|
|
|
GL_glClearColor = (GLCLEARCOLOR)GetProcAddress(hOpenGL,"glClearColor");
|
|
|
|
GL_glDisable = (GLDISABLE)GetProcAddress(hOpenGL,"glDisable");
|
|
|
|
GL_glEnable = (GLENABLE)GetProcAddress(hOpenGL,"glEnable");
|
|
|
|
GL_glFogf = (GLFOGF)GetProcAddress(hOpenGL,"glFogf");
|
|
|
|
GL_glFogfv = (GLFOGFV)GetProcAddress(hOpenGL,"glFogfv");
|
|
|
|
GL_glFogi = (GLFOGI)GetProcAddress(hOpenGL,"glFogi");
|
|
|
|
GL_glHint = (GLHINT)GetProcAddress(hOpenGL,"glHint");
|
|
|
|
}
|
|
|
|
#endif // KMQUAKE2_ENGINE_MOD
|
|
|
|
|
|
|
|
gfogs[0].Color[0] = gfogs[0].Color[1] = gfogs[0].Color[2] = 0.5;
|
|
|
|
gfogs[0].Model = 1;
|
|
|
|
gfogs[0].GL_Model = GLModels[1];
|
|
|
|
gfogs[0].Density = 20.;
|
|
|
|
gfogs[0].Trigger = false;
|
|
|
|
|
|
|
|
#ifdef KMQUAKE2_ENGINE_MOD // engine fog
|
|
|
|
// write to last fog state
|
|
|
|
last_fog_model = last_fog_density = last_fog_near = last_fog_far = 0;
|
|
|
|
VectorSet (last_fog_color, 255, 255, 255);
|
|
|
|
#endif // KMQUAKE2_ENGINE_MOD
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void fog_fade (edict_t *self)
|
|
|
|
{
|
|
|
|
float frames;
|
|
|
|
int index;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.framenum <= self->goal_frame)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
index = self->fog_index-1;
|
|
|
|
frames = self->goal_frame - level.framenum + 1;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (fade_fog.Model == 0)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
fade_fog.Near += (gfogs[index].Near - fade_fog.Near)/frames;
|
|
|
|
fade_fog.Far += (gfogs[index].Far - fade_fog.Far )/frames;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fade_fog.Density += (gfogs[index].Density - fade_fog.Density) /frames;
|
|
|
|
fade_fog.Density1 += (gfogs[index].Density1 - fade_fog.Density1)/frames;
|
|
|
|
fade_fog.Density2 += (gfogs[index].Density2 - fade_fog.Density2)/frames;
|
|
|
|
}
|
|
|
|
fade_fog.Color[0] += (gfogs[index].Color[0] - fade_fog.Color[0])/frames;
|
|
|
|
fade_fog.Color[1] += (gfogs[index].Color[1] - fade_fog.Color[1])/frames;
|
|
|
|
fade_fog.Color[2] += (gfogs[index].Color[2] - fade_fog.Color[2])/frames;
|
|
|
|
fade_fog.GL_Model = GLModels[fade_fog.Model];
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!InTriggerFog)
|
|
|
|
memcpy(&level.current_fog, &fade_fog, sizeof(fog_t));
|
2019-03-13 19:20:07 +00:00
|
|
|
gi.linkentity(self);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
// if (!(self->spawnflags & FOG_ON))
|
|
|
|
if (self->spawnflags & FOG_TURNOFF)
|
2019-03-13 19:20:07 +00:00
|
|
|
level.active_fog = level.active_target_fog = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // NEW_FOGSYS
|
|
|
|
|
|
|
|
// The fog entity code works for both systems
|
|
|
|
|
|
|
|
/*QUAKED target_fog (1 0 0) (-8 -8 -8) (8 8 8) ADDITIVE NEGATIVE
|
|
|
|
Change the fog effects.
|
|
|
|
|
|
|
|
ADDITIVE : adds the target_fog settings to the current settings
|
|
|
|
NEGATIVE : subtracts the target_fog settings from the current settings
|
|
|
|
|
|
|
|
fog_color : The colour of the fog, the colour picker box can (and should IMO) be used.
|
|
|
|
fog_density : The density of the fog, dens*10K (exp&exp2) Default=20
|
|
|
|
fog_model : Choices are:
|
|
|
|
0 :Linear (Default)
|
|
|
|
1 :Exponential
|
|
|
|
2 :Exponential2
|
|
|
|
fog_near : How close the player must get before he sees the fog. Default=64
|
|
|
|
fog_far : How far the player can see into the fog. Default=1024
|
|
|
|
density : Specifies how player see fog. Direction is in degrees. Default=0
|
|
|
|
delay : Ramp time in seconds
|
|
|
|
count : Number of times it can be used
|
|
|
|
*/
|
|
|
|
|
|
|
|
void target_fog_use (edict_t *self, edict_t *other, edict_t *activator)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int index;
|
|
|
|
edict_t *e;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!self)
|
|
|
|
return;
|
|
|
|
// if (!activator || !activator->client)
|
|
|
|
// return;
|
|
|
|
|
2019-03-13 19:20:07 +00:00
|
|
|
self->count--;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->count == 0)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
self->think = G_FreeEdict;
|
|
|
|
self->nextthink = level.time + self->delay + 1;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if ((self->spawnflags & FOG_ON) && (self->spawnflags & FOG_TOGGLE))
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
self->spawnflags &= ~FOG_ON;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
self->spawnflags |= FOG_ON;
|
|
|
|
|
|
|
|
index = self->fog_index-1;
|
|
|
|
|
|
|
|
InTriggerFog = false;
|
|
|
|
|
|
|
|
// scan for other target_fog's that are currently "thinking", iow
|
|
|
|
// the target_fog has a delay and is ramping. If found, stop the ramp for those fogs
|
2020-04-07 06:02:54 +00:00
|
|
|
for (i=1, e=g_edicts+i; i<globals.num_edicts; i++, e++)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!e->inuse) continue;
|
|
|
|
if (e->think == fog_fade)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
e->nextthink = 0;
|
|
|
|
gi.linkentity(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->spawnflags & FOG_TURNOFF)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
// Fog is "turn off" only
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if ( self->delay && level.active_fog )
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
gfogs[index].Far = 5000.0f;
|
|
|
|
gfogs[index].Near = 4999.0f;
|
|
|
|
gfogs[index].Density = 0.0f;
|
|
|
|
gfogs[index].Density1 = 0.0f;
|
|
|
|
gfogs[index].Density2 = 0.0f;
|
|
|
|
VectorCopy(level.current_fog.Color,gfogs[index].Color);
|
2019-03-13 19:20:07 +00:00
|
|
|
self->goal_frame = level.framenum + self->delay*10 + 1;
|
|
|
|
self->think = fog_fade;
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
|
|
|
level.active_fog = level.active_target_fog = self->fog_index;
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&fade_fog, &level.current_fog, sizeof(fog_t));
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
level.active_fog = level.active_target_fog = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->delay)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!level.active_fog)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
// Fog isn't currently on
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&level.current_fog, &gfogs[index], sizeof(fog_t));
|
|
|
|
level.current_fog.Near = 4999.0f;
|
|
|
|
level.current_fog.Far = 5000.0f;
|
|
|
|
level.current_fog.Density = 0.0f;
|
|
|
|
level.current_fog.Density1 = 0.0f;
|
|
|
|
level.current_fog.Density2 = 0.0f;
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
VectorCopy(self->fog_color,gfogs[index].Color);
|
|
|
|
gfogs[index].Near = self->fog_near;
|
|
|
|
gfogs[index].Far = self->fog_far;
|
|
|
|
gfogs[index].Density = self->fog_density;
|
|
|
|
gfogs[index].Density1 = self->fog_density;
|
|
|
|
gfogs[index].Density2 = self->density;
|
|
|
|
self->goal_frame = level.framenum + self->delay*10 + 1;
|
|
|
|
self->think = fog_fade;
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
2020-04-07 06:02:54 +00:00
|
|
|
memcpy(&fade_fog, &level.current_fog, sizeof(fog_t));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
memcpy(&level.current_fog, &gfogs[index], sizeof(fog_t));
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
level.active_fog = level.active_target_fog = self->fog_index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SP_target_fog (edict_t *self)
|
|
|
|
{
|
|
|
|
fog_t *fog;
|
|
|
|
|
|
|
|
if ( !allow_fog->value )
|
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (deathmatch->value || coop->value)
|
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->class_id = ENTITY_TARGET_FOG;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!level.num_fogs)
|
|
|
|
level.num_fogs = 1; // 1st fog reserved for console commands
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.num_fogs >= MAX_FOGS)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("Maximum number of fogs exceeded!\n");
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->delay < 0.0f)
|
|
|
|
self->delay = 0.0f;
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
self->fog_index = level.num_fogs+1;
|
|
|
|
fog = &gfogs[level.num_fogs];
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->Trigger = false;
|
2020-04-07 06:02:54 +00:00
|
|
|
fog->Model = self->fog_model;
|
|
|
|
if (fog->Model < 0 || fog->Model > 2)
|
|
|
|
fog->Model = 0;
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->GL_Model = GLModels[fog->Model];
|
|
|
|
VectorCopy(self->fog_color,fog->Color);
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->spawnflags & FOG_TURNOFF)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
fog->Near = 4999;
|
|
|
|
fog->Far = 5000;
|
|
|
|
fog->Density = 0;
|
|
|
|
fog->Density1 = 0;
|
|
|
|
fog->Density2 = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fog->Near = self->fog_near;
|
|
|
|
fog->Far = self->fog_far;
|
|
|
|
fog->Density = self->fog_density;
|
|
|
|
fog->Density1 = self->fog_density;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->density == 0.0f)
|
2019-03-13 19:20:07 +00:00
|
|
|
self->density = self->fog_density;
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (self->density < 0.0f)
|
|
|
|
self->density = 0.0f;
|
|
|
|
fog->Density2 = self->density;
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
AngleVectors(self->s.angles, fog->Dir, 0, 0);
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->ent = self;
|
2020-04-07 06:02:54 +00:00
|
|
|
level.num_fogs++;
|
2019-03-13 19:20:07 +00:00
|
|
|
self->use = target_fog_use;
|
|
|
|
gi.linkentity(self);
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->spawnflags & FOG_ON)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
self->spawnflags &= ~FOG_ON;
|
2020-04-07 06:02:54 +00:00
|
|
|
target_fog_use(self, NULL, NULL);
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*QUAKED trigger_fog (1 0 0) ? x Toggle x StartOff
|
|
|
|
Fog field
|
|
|
|
|
|
|
|
"fog_color" specify an RGB color: Default = .5 .5 .5
|
|
|
|
"fog_model" default = 1
|
|
|
|
0 :Linear
|
|
|
|
1 :Exp
|
|
|
|
2 :Exp2
|
|
|
|
|
|
|
|
"fog_near" Starting distance from player. Default = 64
|
|
|
|
"fog_far" How far the player can see into the fog. Default = 1024
|
|
|
|
"fog_density" Default = 20
|
|
|
|
"density" at 180 degrees; Default=0
|
|
|
|
"delay" ramp time in seconds
|
|
|
|
"count" number of times it can be used
|
|
|
|
*/
|
|
|
|
|
|
|
|
void trigger_fog_use (edict_t *self, edict_t *other, edict_t *activator)
|
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
if ((self->spawnflags & FOG_ON) && (self->spawnflags & FOG_TOGGLE))
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
self->spawnflags &= ~FOG_ON;
|
|
|
|
self->count--;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->count == 0)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
self->think = G_FreeEdict;
|
|
|
|
self->nextthink = level.time + FRAMETIME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
self->spawnflags |= FOG_ON;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SP_trigger_fog (edict_t *self)
|
|
|
|
{
|
|
|
|
fog_t *fog;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!allow_fog->value)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
if (deathmatch->value || coop->value)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->class_id = ENTITY_TRIGGER_FOG;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!level.num_fogs)
|
|
|
|
level.num_fogs = 1; // 1st fog reserved for console commands
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.num_fogs >= MAX_FOGS)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("Maximum number of fogs exceeded!\n");
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
self->fog_index = level.num_fogs+1;
|
|
|
|
fog = &gfogs[level.num_fogs];
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->Trigger = true;
|
|
|
|
fog->Model = self->fog_model;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (( fog->Model < 0) || (fog->Model > 2) )
|
|
|
|
fog->Model = 0;
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->GL_Model = GLModels[fog->Model];
|
|
|
|
VectorCopy(self->fog_color,fog->Color);
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->spawnflags & FOG_TURNOFF)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
fog->Near = 4999.0f;
|
|
|
|
fog->Far = 5000.0f;
|
|
|
|
fog->Density = 0.0f;
|
|
|
|
fog->Density1 = 0.0f;
|
|
|
|
fog->Density2 = 0.0f;
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fog->Near = self->fog_near;
|
|
|
|
fog->Far = self->fog_far;
|
|
|
|
fog->Density = self->fog_density;
|
|
|
|
fog->Density1 = self->fog_density;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->density == 0.0f)
|
2019-03-13 19:20:07 +00:00
|
|
|
self->density = self->fog_density;
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (self->density < 0.0f)
|
|
|
|
self->density = 0.0f;
|
|
|
|
fog->Density2 = self->density;
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!(self->spawnflags & FOG_STARTOFF))
|
2019-03-13 19:20:07 +00:00
|
|
|
self->spawnflags |= FOG_ON;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
AngleVectors(self->s.angles, fog->Dir, 0, 0);
|
2019-03-13 19:20:07 +00:00
|
|
|
VectorClear(self->s.angles);
|
|
|
|
fog->ent = self;
|
2020-04-07 06:02:54 +00:00
|
|
|
level.num_fogs++;
|
|
|
|
level.num_trigger_fogs++;
|
2019-03-13 19:20:07 +00:00
|
|
|
self->movetype = MOVETYPE_NONE;
|
|
|
|
self->svflags |= SVF_NOCLIENT;
|
|
|
|
self->solid = SOLID_NOT;
|
|
|
|
gi.setmodel (self, self->model);
|
|
|
|
gi.linkentity(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*QUAKED trigger_fog_bbox (.5 .5 .5) (-8 -8 -8) (8 8 8) x Toggle x StartOff
|
|
|
|
Fog field
|
|
|
|
|
|
|
|
"fog_color" specify an RGB color: Default = .5 .5 .5
|
|
|
|
"fog_model" default = 1
|
|
|
|
0 :Linear
|
|
|
|
1 :Exp
|
|
|
|
2 :Exp2
|
|
|
|
|
|
|
|
"fog_near" Starting distance from player. Default = 64
|
|
|
|
"fog_far" How far the player can see into the fog. Default = 1024
|
|
|
|
"fog_density" Default = 20
|
|
|
|
"density" at 180 degrees; Default=0
|
|
|
|
"delay" ramp time in seconds
|
|
|
|
"count" number of times it can be used
|
|
|
|
|
|
|
|
bleft Min b-box coords XYZ. Default = -16 -16 -16
|
|
|
|
tright Max b-box coords XYZ. Default = 16 16 16
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SP_trigger_fog_bbox (edict_t *self)
|
|
|
|
{
|
|
|
|
fog_t *fog;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!allow_fog->value)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
if (deathmatch->value || coop->value)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
self->class_id = ENTITY_TRIGGER_FOG;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!level.num_fogs)
|
|
|
|
level.num_fogs = 1; // 1st fog reserved for console commands
|
2019-03-13 19:20:07 +00:00
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
if (level.num_fogs >= MAX_FOGS)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
|
|
|
gi.dprintf("Maximum number of fogs exceeded!\n");
|
|
|
|
G_FreeEdict(self);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
self->fog_index = level.num_fogs+1;
|
|
|
|
fog = &gfogs[level.num_fogs];
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->Trigger = true;
|
|
|
|
fog->Model = self->fog_model;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (fog->Model < 0 || fog->Model > 2)
|
|
|
|
fog->Model = 0;
|
2019-03-13 19:20:07 +00:00
|
|
|
fog->GL_Model = GLModels[fog->Model];
|
|
|
|
VectorCopy(self->fog_color,fog->Color);
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->spawnflags & FOG_TURNOFF)
|
2019-03-13 19:20:07 +00:00
|
|
|
{
|
2020-04-07 06:02:54 +00:00
|
|
|
fog->Near = 4999.0f;
|
|
|
|
fog->Far = 5000.0f;
|
|
|
|
fog->Density = 0.0f;
|
|
|
|
fog->Density1 = 0.0f;
|
|
|
|
fog->Density2 = 0.0f;
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fog->Near = self->fog_near;
|
|
|
|
fog->Far = self->fog_far;
|
|
|
|
fog->Density = self->fog_density;
|
|
|
|
fog->Density1 = self->fog_density;
|
2020-04-07 06:02:54 +00:00
|
|
|
if (self->density == 0.0f)
|
2019-03-13 19:20:07 +00:00
|
|
|
self->density = self->fog_density;
|
2020-04-07 06:02:54 +00:00
|
|
|
else if (self->density < 0.0f)
|
|
|
|
self->density = 0.0f;
|
|
|
|
fog->Density2 = self->density;
|
2019-03-13 19:20:07 +00:00
|
|
|
}
|
2020-04-07 06:02:54 +00:00
|
|
|
if (!(self->spawnflags & FOG_STARTOFF))
|
2019-03-13 19:20:07 +00:00
|
|
|
self->spawnflags |= FOG_ON;
|
|
|
|
|
2020-04-07 06:02:54 +00:00
|
|
|
AngleVectors(self->s.angles, fog->Dir, 0, 0);
|
2019-03-13 19:20:07 +00:00
|
|
|
VectorClear(self->s.angles);
|
2020-04-07 06:02:54 +00:00
|
|
|
fog->ent = self;
|
|
|
|
level.num_fogs++;
|
|
|
|
level.num_trigger_fogs++;
|
2019-03-13 19:20:07 +00:00
|
|
|
self->movetype = MOVETYPE_NONE;
|
|
|
|
self->svflags |= SVF_NOCLIENT;
|
|
|
|
self->solid = SOLID_NOT;
|
|
|
|
if ( (!VectorLength(self->bleft)) && (!VectorLength(self->tright)) )
|
|
|
|
{
|
|
|
|
VectorSet(self->bleft, -16, -16, -16);
|
|
|
|
VectorSet(self->tright, 16, 16, 16);
|
|
|
|
}
|
|
|
|
VectorCopy (self->bleft, self->mins);
|
|
|
|
VectorCopy (self->tright, self->maxs);
|
|
|
|
gi.linkentity(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DISABLE_FOG
|