Make it compile on UNIX-like systems

This commit is contained in:
Marco Cawthorne 2020-02-10 13:27:07 +01:00
parent 51e076c7ac
commit eb147b0e01
15 changed files with 991 additions and 987 deletions

View file

@ -1,17 +1,13 @@
#
# Action makefile
# Intended for gcc/Linux, may need modifying for other platforms
# ACTION QUAKE II MAKEFILE FOR LINUX
# Including the ACE BOT!
# Written by eukara
#
CC=gcc
BASE_CFLAGS=-Dstricmp=strcasecmp
#use these cflags to optimize it
#CFLAGS=$(BASE_CFLAGS) -m486 -O6 -ffast-math -funroll-loops \
# -fomit-frame-pointer -fexpensive-optimizations -malign-loops=2 \
# -malign-jumps=2 -malign-functions=2
#use these when debugging
CFLAGS=$(BASE_CFLAGS) -I../src/
CFLAGS=$(BASE_CFLAGS)
LDFLAGS=-ldl -lm
SHLIBEXT=so
@ -20,11 +16,6 @@ SHLIBLDFLAGS=-shared
DO_CC=$(CC) $(CFLAGS) $(SHLIBCFLAGS) -o $@ -c $<
#############################################################################
# SETUP AND BUILD
# GAME
#############################################################################
.c.o:
$(DO_CC)
@ -33,17 +24,15 @@ GAME_OBJS = \
g_monster.o g_phys.o g_save.o g_spawn.o g_svcmds.o \
g_target.o g_trigger.o g_turret.o g_utils.o g_weapon.o g_chase.o \
p_client.o p_hud.o p_trail.o p_view.o p_weapon.o q_shared.o \
m_move.o a_team.o a_game.o a_items.o a_cmds.o a_radio.o a_menu.o \
m_move.o a_team.o \
acesrc/acebot_ai.o acesrc/acebot_cmds.o acesrc/acebot_compress.o acesrc/acebot_items.o acesrc/acebot_movement.o \
acesrc/acebot_nodes.o acesrc/acebot_spawn.o acesrc/botchat.o acesrc/botnav.o acesrc/botscan.o acesrc/cgf_sfx_fog.o \
a_game.o a_items.o a_cmds.o a_radio.o a_menu.o \
cgf_sfx_glass.o a_doorkick.o
game$(ARCH).$(SHLIBEXT) : $(GAME_OBJS)
$(CC) $(CFLAGS) $(SHLIBLDFLAGS) -o $@ $(GAME_OBJS)
#############################################################################
# MISC
#############################################################################
clean:
-rm -f $(GAME_OBJS)
@ -54,10 +43,6 @@ depend:
install:
cp gamei386.so ../quake2/action
#
# From "make depend"
#
g_ai.o: g_ai.c g_local.h q_shared.h game.h a_team.h a_game.h a_menu.h \
a_radio.h
g_cmds.o: g_cmds.c g_local.h q_shared.h game.h a_team.h a_game.h \
@ -109,6 +94,28 @@ m_move.o: m_move.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h
a_team.o: a_team.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h
acesrc/acebot_ai.o: acesrc/acebot_ai.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/acebot_cmds.o: acesrc/acebot_cmds.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/acebot_compress.o: acesrc/acebot_compress.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/acebot_items.o: acesrc/acebot_items.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/acebot_movement.o: acesrc/acebot_movement.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/acebot_nodes.o: acesrc/acebot_nodes.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/acebot_spawn.o: acesrc/acebot_spawn.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/botchat.o: acesrc/botchat.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/botnav.o: acesrc/botnav.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/botscan.o: acesrc/botscan.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
acesrc/cgf_sfx_fog.o: acesrc/cgf_sfx_fog.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h acesrc/acebot.h acesrc/botchat.h acesrc/botnav.h acesrc/botscan.h acesrc/cgf_sfx_fog.h
a_game.o: a_game.c g_local.h q_shared.h game.h a_team.h a_game.h \
a_menu.h a_radio.h cgf_sfx_glass.h
a_items.o: a_items.c g_local.h q_shared.h game.h a_team.h a_game.h \

View file

@ -101,13 +101,16 @@
// to provide a "higher" level of AI.
////////////////////////////////////////////////////////////////////////
#include "..\g_local.h"
#include "..\m_player.h"
#include "../g_local.h"
#include "../m_player.h"
#include "acebot.h"
#if 0
// CGF_FOG ADD
#include "cgf_sfx_fog.h"
// CGF_FOG END
#endif
void ACEAI_Cmd_Choose( edict_t *ent, char *s);
///////////////////////////////////////////////////////////////////////
@ -325,6 +328,7 @@ void ACEAI_PickLongRangeGoal(edict_t *self)
{
if( players[i]->light_level < 30)
continue;
#if 0
// CGF_FOG ADD
// Check for FOG!
if( CGF_SFX_IsFogEnabled() )
@ -340,6 +344,7 @@ void ACEAI_PickLongRangeGoal(edict_t *self)
continue;
}
// CGF_FOG END
#endif
}
node = ACEND_FindClosestReachableNode(players[i],NODE_DENSITY,NODE_ALL);
@ -500,6 +505,7 @@ qboolean ACEAI_FindEnemy(edict_t *self)
{
if( players[i]->light_level < 30)
continue;
#if 0
// CGF_FOG ADD
// Check for FOG!
if( CGF_SFX_IsFogEnabled() )
@ -515,6 +521,7 @@ qboolean ACEAI_FindEnemy(edict_t *self)
continue;
}
// CGF_FOG END
#endif
}
/* if(ctf->value &&

View file

@ -34,7 +34,7 @@
//
///////////////////////////////////////////////////////////////////////
#include "..\g_local.h"
#include "../g_local.h"
#include "acebot.h"
qboolean debug_mode=false;

View file

@ -71,7 +71,7 @@
//
///////////////////////////////////////////////////////////////////////
#include "..\g_local.h"
#include "../g_local.h"
#include "acebot.h"
int num_players = 0;

View file

@ -113,7 +113,7 @@
//
///////////////////////////////////////////////////////////////////////
#include "..\g_local.h"
#include "../g_local.h"
#include "acebot.h"
qboolean ACEAI_CheckShot(edict_t *self);

View file

@ -124,7 +124,7 @@
//
///////////////////////////////////////////////////////////////////////
#include "..\g_local.h"
#include "../g_local.h"
#include "acebot.h"
#define LTK_NODEVERSION 3

View file

@ -118,8 +118,8 @@
//
///////////////////////////////////////////////////////////////////////
#include "..\g_local.h"
#include "..\m_player.h"
#include "../g_local.h"
#include "../m_player.h"
#include "acebot.h"
#include "botchat.h"
#include "botscan.h"

View file

@ -38,7 +38,7 @@
*
*/
#include "..\g_local.h"
#include "../g_local.h"
#include "botnav.h"
//== GLOBAL SEMAPHORE ==

View file

@ -1,472 +1,473 @@
/****************************************************************************/
/* */
/* project : CGF (c) 1999 William van der Sterren */
/* */
/* file : cgf_sfx_fog.h "fog openGL stuff" */
/* author(s): William van der Sterren */
/* version : 0.5 */
/* */
/* date (last revision): Aug 31, 99 */
/* date (creation) : Aug 31, 99 */
/* */
/* */
/* revision history */
/* -- date ---- | -- revision ---------------------- | -- revisor -- */
/* | | */
/* */
/****************************************************************************/
//#ifdef FOG
#include <cmath> // prevent problems between C and STL
/****************************************************************************/
/* */
/* project : CGF (c) 1999 William van der Sterren */
/* */
/* file : cgf_sfx_fog.h "fog openGL stuff" */
/* author(s): William van der Sterren */
/* version : 0.5 */
/* */
/* date (last revision): Aug 31, 99 */
/* date (creation) : Aug 31, 99 */
/* */
/* */
/* revision history */
/* -- date ---- | -- revision ---------------------- | -- revisor -- */
/* | | */
/* */
/****************************************************************************/
extern "C"
{
#include "cgf_sfx_fog.h"
#include "../g_local.h"
//#include "sabin_debug.h"
#include <windows.h>
#include <GL/gl.h>
#undef FOG
#ifdef FOG
/*
#ifdef CGF
// AI update related to fog
#include "cgf_tactics_visibility.h"
#include <cmath> // prevent problems between C and STL
extern "C"
{
#include "cgf_sfx_fog.h"
#include "../g_local.h"
//#include "sabin_debug.h"
#include <windows.h>
#include <GL/gl.h>
/*
#ifdef CGF
// AI update related to fog
#include "cgf_tactics_visibility.h"
#endif
*/
}
#include <vector>
#include <fstream>
#include <strstream>
using namespace std;
// defaults
static vec_t m_FogDensity = 0.1000;
static int m_FogEnabled = false;
static int m_FogType = 2; // linear
static int m_FogStart = 200;
static int m_FogEnd = 1600;
static vec_t m_FogColor[4] = {0.5, 0.5, 0.5, 1};
static char m_Settings[64];
const int kMaxViewingDistance = 8192;
const int kViewingDistanceStep = 64;
*/
}
#include <vector>
#include <fstream>
#include <strstream>
using namespace std;
// defaults
static vec_t m_FogDensity = 0.1000;
static int m_FogEnabled = false;
static int m_FogType = 2; // linear
static int m_FogStart = 200;
static int m_FogEnd = 1600;
static vec_t m_FogColor[4] = {0.5, 0.5, 0.5, 1};
static char m_Settings[64];
const int kMaxViewingDistance = 8192;
const int kViewingDistanceStep = 64;
//static vec_t m_FogViewReduction[kMaxViewingDistance / kViewingDistanceStep];
static vec_t m_FogViewReduction[128];
// cvar for fog and video mode
static cvar_t* fog = 0;
static cvar_t* vid_ref = 0;
// forward decls
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
);
void CGF_SFX_DeactivateFog();
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
);
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd);
void CGF_SFX_InstallFogSupport()
{
// reset settings
m_Settings[0] = 0;//char(0);
// if fog > 0, then enabled
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
// prevent issueing gl calls if no opengl present
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
// if not fog enabled, act upon it
if (!m_FogEnabled)
{
if (fog->value == 0)
{
strcpy(m_Settings, "cvar fog is 0");
// CGF_Debug_LogMessage("fog disabled: cvar fog is 0");
}
else
{
strcpy(m_Settings, "using software rendering");
// CGF_Debug_LogMessage("fog disabled: using software rendering");
}
gi.cvar_set("fog", "0");
}
}
void CGF_SFX_AdjustFogForMap(const char* aMapName)
{
// verify fog if m_FogEnabled, and reset if required
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
if (m_FogEnabled)
{
if (!(m_FogEnabled = (fog->value != 0)))
{
#ifdef CGF
CGF_Debug_LogMessage("fog disabled: fog set to 0 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
else
{
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
if (m_FogEnabled)
{
#ifdef CGF
CGF_Debug_LogMessage("fog enabled : fog set to 1 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
// process fog setting
if (m_FogEnabled)
{
vec_t d;
int t;
vec_t s;
vec_t e;
vec3_t rgb;
if ( (!aMapName)
|| (!CGF_SFX_FindFogPreferences(aMapName, &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
)
{
if (!CGF_SFX_FindFogPreferences("default", &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
{
d = m_FogDensity;
t = m_FogType;
VectorCopy(m_FogColor, rgb);
s = m_FogStart;
e = m_FogEnd;
}
}
// convert d to value usable for gl lib
d /= 100;
// convert fog type
// 0 == GL_EXP, 1 == GL_EXP2, 2 == GL_LINEAR
if ((t < 0) || (t > 2))
t = m_FogType;
if (t < 2)
t = t + 0x800;
else
t = GL_LINEAR;
if (d > 0)
CGF_SFX_ActivateFog(d, t, rgb, s, e);
else
CGF_SFX_DeactivateFog();
}
else
{
CGF_SFX_DeactivateFog();
}
}
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
)
{
*aDensity = 0;
// try to read preferences from file action\cgf\fog\<mapname>.fog
// format for file is:
// // format: mapname density fogtype red green blue
char buf_filename[256];
ostrstream filename(buf_filename, 255);
cvar_t* gamedir;
cvar_t* basedir;
gamedir = gi.cvar ("game", "", 0);
basedir = gi.cvar("basedir", ".", 0);
// obtain file location
filename << basedir->string << '\\' << gamedir->string
<< '\\' << "cgf\\fog\\" << aMapName << ".fog" << char(0);
// open file, append mode
ifstream preferences(buf_filename, ios_base::in);
if (preferences.good())
{
char name[128];
memset(name,0, sizeof(name));
preferences >> name;
// skip comment lines if any
while ( (strlen(name) >= 2)
&& (name[0] == '/')
&& ( (name[1] == '/')
|| (name[1] == '*')
)
)
{
preferences.getline(name, 128);
memset(name,0, sizeof(name));
preferences >> name;
}
/* test for name similarity removed
if ( (strlen(name))
&& ( 0 == stricmp(name, aMapName))
)
*/
{
preferences >> *aDensity;
if (*aDensity > 0)
{
preferences >> *aType;
preferences >> *aRed;
preferences >> *aGreen;
preferences >> *aBlue;
preferences >> *aBegin;
preferences >> *aEnd;
}
// adjust settings info
ostrstream settings(buf_filename, 63);
settings << "cgf\\fog\\" << aMapName << ".fog" << char(0);
strcpy(m_Settings, buf_filename);
return true;
}
}
return false;
}
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
)
{
#ifdef CGF
if (CGF_Debug_IsLogging())
{
char message[256];
if (aDensity)
sprintf(message,
"fog settings: mode %d, density %.2f, rgb=[%.2f, %.2f, %.2f], begin %d, end %d",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity, aColor[0], aColor[1], aColor[2], (int) aBegin, (int) anEnd
);
else
sprintf(message,
"fog settings: mode %d, density %.2f == disabled",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity
);
CGF_Debug_LogMessage(message);
}
#endif
CGF_SFX_InitFogForDistance(aType, aDensity, aBegin, anEnd);
glEnable (GL_FOG); // turn on fog, otherwise you won't see any
glFogi (GL_FOG_MODE, aType);
if (aType == GL_LINEAR)
{
glFogf (GL_FOG_START, aBegin);
glFogf (GL_FOG_END, anEnd);
}
glFogfv (GL_FOG_COLOR, aColor);
glFogf (GL_FOG_DENSITY, aDensity);
glHint (GL_FOG_HINT, GL_NICEST);
}
void CGF_SFX_DeactivateFog()
{
CGF_SFX_InitFogForDistance(0, 0, 0, 0);
// prevent opengl calls when no opengl
if ( (vid_ref)
&& (0 == stricmp(vid_ref->string, "soft"))
)
return;
glDisable (GL_FOG); // turn off fog
}
int CGF_SFX_IsFogEnabled()
{
return m_FogEnabled;
}
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd)
{
// determine how many cells
int cells;
cells = kMaxViewingDistance / kViewingDistanceStep;
vec_t dist;
vec_t maxdist;
vec_t mindist;
if (aFogDensity == 0.0)
aFogMode = 0;
// adjust fog density value to our values
aFogDensity *= 100;
switch (aFogMode)
{
case GL_LINEAR:
maxdist = aFogEnd;
mindist = aFogBegin;
break;
case GL_EXP:
maxdist = 400.0 / sqrt(aFogDensity);
break;
case GL_EXP2:
maxdist = 130.0 / aFogDensity;
break;
default :
maxdist = kMaxViewingDistance;
}
dist = 0;
for (int cell = 0; cell < cells; cell++)
{
vec_t reduction;
switch (aFogMode)
{
case GL_LINEAR:
if (dist < mindist)
reduction = 1;
else
if (dist > maxdist)
reduction = 0;
else
reduction = 1 - (dist - mindist) / (maxdist - mindist);
break;
case GL_EXP:
reduction = 1 - dist / maxdist;
break;
case GL_EXP2:
reduction = 1 - (dist / maxdist) * (dist / maxdist);
break;
default :
reduction = 1.0;
}
if (reduction < 0)
reduction = 0;
m_FogViewReduction[cell] = reduction;
dist += kViewingDistanceStep;
}
}
const char* CGF_SFX_FogSettingsInfo()
{
return (const char*) m_Settings;
}
vec_t CGF_SFX_GetFogForDistance(vec_t dist)
{
int index;
index = ((int) dist) / (int) kViewingDistanceStep;
assert( (index < (kMaxViewingDistance / kViewingDistanceStep))
);
return m_FogViewReduction[index];
}
vec_t CGF_SFX_GetViewingDistanceUpToReduction(vec_t aReduction)
{
int index;
index = (kMaxViewingDistance / kViewingDistanceStep) - 1;
while ( (index >= 0)
&& (m_FogViewReduction[index] < aReduction)
)
index--;
return (vec_t) (index * kViewingDistanceStep);
}
/*
#ifdef _DEBUG
extern "C" void CGF_SFX_Fog_DisplayRods(edict_t* aClient);
void CGF_SFX_Fog_DisplayRods(edict_t* aClient)
{
vec3_t forward;
vec3_t v1;
vec3_t v2;
bool half;
bool ten;
half = false;
ten = false;
AngleVectors(aClient->s.angles, forward, 0, 0);
forward[2] = 0;
VectorNormalize(forward);
for (int rod = 0; rod < 20; rod ++)
{
VectorMA(aClient->s.origin, 100 * ((float) rod), forward, v1);
VectorCopy(v1, v2);
v2[2] -= 1000;
SABIN_Debug_DisplayLine(v1, v2, 60);
if ( (!half)
&& (half = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.5))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
if ( (!ten)
&& (ten = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.1))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
}
}
#endif
*/
//#endif
static vec_t m_FogViewReduction[128];
// cvar for fog and video mode
static cvar_t* fog = 0;
static cvar_t* vid_ref = 0;
// forward decls
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
);
void CGF_SFX_DeactivateFog();
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
);
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd);
void CGF_SFX_InstallFogSupport()
{
// reset settings
m_Settings[0] = 0;//char(0);
// if fog > 0, then enabled
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
// prevent issueing gl calls if no opengl present
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
// if not fog enabled, act upon it
if (!m_FogEnabled)
{
if (fog->value == 0)
{
strcpy(m_Settings, "cvar fog is 0");
// CGF_Debug_LogMessage("fog disabled: cvar fog is 0");
}
else
{
strcpy(m_Settings, "using software rendering");
// CGF_Debug_LogMessage("fog disabled: using software rendering");
}
gi.cvar_set("fog", "0");
}
}
void CGF_SFX_AdjustFogForMap(const char* aMapName)
{
// verify fog if m_FogEnabled, and reset if required
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
if (m_FogEnabled)
{
if (!(m_FogEnabled = (fog->value != 0)))
{
#ifdef CGF
CGF_Debug_LogMessage("fog disabled: fog set to 0 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
else
{
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
if (m_FogEnabled)
{
#ifdef CGF
CGF_Debug_LogMessage("fog enabled : fog set to 1 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
// process fog setting
if (m_FogEnabled)
{
vec_t d;
int t;
vec_t s;
vec_t e;
vec3_t rgb;
if ( (!aMapName)
|| (!CGF_SFX_FindFogPreferences(aMapName, &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
)
{
if (!CGF_SFX_FindFogPreferences("default", &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
{
d = m_FogDensity;
t = m_FogType;
VectorCopy(m_FogColor, rgb);
s = m_FogStart;
e = m_FogEnd;
}
}
// convert d to value usable for gl lib
d /= 100;
// convert fog type
// 0 == GL_EXP, 1 == GL_EXP2, 2 == GL_LINEAR
if ((t < 0) || (t > 2))
t = m_FogType;
if (t < 2)
t = t + 0x800;
else
t = GL_LINEAR;
if (d > 0)
CGF_SFX_ActivateFog(d, t, rgb, s, e);
else
CGF_SFX_DeactivateFog();
}
else
{
CGF_SFX_DeactivateFog();
}
}
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
)
{
*aDensity = 0;
// try to read preferences from file action\cgf\fog\<mapname>.fog
// format for file is:
// // format: mapname density fogtype red green blue
char buf_filename[256];
ostrstream filename(buf_filename, 255);
cvar_t* gamedir;
cvar_t* basedir;
gamedir = gi.cvar ("game", "", 0);
basedir = gi.cvar("basedir", ".", 0);
// obtain file location
filename << basedir->string << '\\' << gamedir->string
<< '\\' << "cgf\\fog\\" << aMapName << ".fog" << char(0);
// open file, append mode
ifstream preferences(buf_filename, ios_base::in);
if (preferences.good())
{
char name[128];
memset(name,0, sizeof(name));
preferences >> name;
// skip comment lines if any
while ( (strlen(name) >= 2)
&& (name[0] == '/')
&& ( (name[1] == '/')
|| (name[1] == '*')
)
)
{
preferences.getline(name, 128);
memset(name,0, sizeof(name));
preferences >> name;
}
/* test for name similarity removed
if ( (strlen(name))
&& ( 0 == stricmp(name, aMapName))
)
*/
{
preferences >> *aDensity;
if (*aDensity > 0)
{
preferences >> *aType;
preferences >> *aRed;
preferences >> *aGreen;
preferences >> *aBlue;
preferences >> *aBegin;
preferences >> *aEnd;
}
// adjust settings info
ostrstream settings(buf_filename, 63);
settings << "cgf\\fog\\" << aMapName << ".fog" << char(0);
strcpy(m_Settings, buf_filename);
return true;
}
}
return false;
}
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
)
{
#ifdef CGF
if (CGF_Debug_IsLogging())
{
char message[256];
if (aDensity)
sprintf(message,
"fog settings: mode %d, density %.2f, rgb=[%.2f, %.2f, %.2f], begin %d, end %d",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity, aColor[0], aColor[1], aColor[2], (int) aBegin, (int) anEnd
);
else
sprintf(message,
"fog settings: mode %d, density %.2f == disabled",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity
);
CGF_Debug_LogMessage(message);
}
#endif
CGF_SFX_InitFogForDistance(aType, aDensity, aBegin, anEnd);
glEnable (GL_FOG); // turn on fog, otherwise you won't see any
glFogi (GL_FOG_MODE, aType);
if (aType == GL_LINEAR)
{
glFogf (GL_FOG_START, aBegin);
glFogf (GL_FOG_END, anEnd);
}
glFogfv (GL_FOG_COLOR, aColor);
glFogf (GL_FOG_DENSITY, aDensity);
glHint (GL_FOG_HINT, GL_NICEST);
}
void CGF_SFX_DeactivateFog()
{
CGF_SFX_InitFogForDistance(0, 0, 0, 0);
// prevent opengl calls when no opengl
if ( (vid_ref)
&& (0 == stricmp(vid_ref->string, "soft"))
)
return;
glDisable (GL_FOG); // turn off fog
}
int CGF_SFX_IsFogEnabled()
{
return m_FogEnabled;
}
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd)
{
// determine how many cells
int cells;
cells = kMaxViewingDistance / kViewingDistanceStep;
vec_t dist;
vec_t maxdist;
vec_t mindist;
if (aFogDensity == 0.0)
aFogMode = 0;
// adjust fog density value to our values
aFogDensity *= 100;
switch (aFogMode)
{
case GL_LINEAR:
maxdist = aFogEnd;
mindist = aFogBegin;
break;
case GL_EXP:
maxdist = 400.0 / sqrt(aFogDensity);
break;
case GL_EXP2:
maxdist = 130.0 / aFogDensity;
break;
default :
maxdist = kMaxViewingDistance;
}
dist = 0;
for (int cell = 0; cell < cells; cell++)
{
vec_t reduction;
switch (aFogMode)
{
case GL_LINEAR:
if (dist < mindist)
reduction = 1;
else
if (dist > maxdist)
reduction = 0;
else
reduction = 1 - (dist - mindist) / (maxdist - mindist);
break;
case GL_EXP:
reduction = 1 - dist / maxdist;
break;
case GL_EXP2:
reduction = 1 - (dist / maxdist) * (dist / maxdist);
break;
default :
reduction = 1.0;
}
if (reduction < 0)
reduction = 0;
m_FogViewReduction[cell] = reduction;
dist += kViewingDistanceStep;
}
}
const char* CGF_SFX_FogSettingsInfo()
{
return (const char*) m_Settings;
}
vec_t CGF_SFX_GetFogForDistance(vec_t dist)
{
int index;
index = ((int) dist) / (int) kViewingDistanceStep;
assert( (index < (kMaxViewingDistance / kViewingDistanceStep))
);
return m_FogViewReduction[index];
}
vec_t CGF_SFX_GetViewingDistanceUpToReduction(vec_t aReduction)
{
int index;
index = (kMaxViewingDistance / kViewingDistanceStep) - 1;
while ( (index >= 0)
&& (m_FogViewReduction[index] < aReduction)
)
index--;
return (vec_t) (index * kViewingDistanceStep);
}
/*
#ifdef _DEBUG
extern "C" void CGF_SFX_Fog_DisplayRods(edict_t* aClient);
void CGF_SFX_Fog_DisplayRods(edict_t* aClient)
{
vec3_t forward;
vec3_t v1;
vec3_t v2;
bool half;
bool ten;
half = false;
ten = false;
AngleVectors(aClient->s.angles, forward, 0, 0);
forward[2] = 0;
VectorNormalize(forward);
for (int rod = 0; rod < 20; rod ++)
{
VectorMA(aClient->s.origin, 100 * ((float) rod), forward, v1);
VectorCopy(v1, v2);
v2[2] -= 1000;
SABIN_Debug_DisplayLine(v1, v2, 60);
if ( (!half)
&& (half = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.5))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
if ( (!ten)
&& (ten = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.1))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
}
}
#endif
*/
#endif

View file

@ -1,472 +1,473 @@
/****************************************************************************/
/* */
/* project : CGF (c) 1999 William van der Sterren */
/* */
/* file : cgf_sfx_fog.h "fog openGL stuff" */
/* author(s): William van der Sterren */
/* version : 0.5 */
/* */
/* date (last revision): Aug 31, 99 */
/* date (creation) : Aug 31, 99 */
/* */
/* */
/* revision history */
/* -- date ---- | -- revision ---------------------- | -- revisor -- */
/* | | */
/* */
/****************************************************************************/
//#ifdef FOG
#include <cmath> // prevent problems between C and STL
/****************************************************************************/
/* */
/* project : CGF (c) 1999 William van der Sterren */
/* */
/* file : cgf_sfx_fog.h "fog openGL stuff" */
/* author(s): William van der Sterren */
/* version : 0.5 */
/* */
/* date (last revision): Aug 31, 99 */
/* date (creation) : Aug 31, 99 */
/* */
/* */
/* revision history */
/* -- date ---- | -- revision ---------------------- | -- revisor -- */
/* | | */
/* */
/****************************************************************************/
extern "C"
{
#include "cgf_sfx_fog.h"
#include "../g_local.h"
//#include "sabin_debug.h"
#include <windows.h>
#include <GL/gl.h>
#undef FOG
/*
#ifdef CGF
// AI update related to fog
#include "cgf_tactics_visibility.h"
#ifdef FOG
#include <cmath> // prevent problems between C and STL
extern "C"
{
#include "cgf_sfx_fog.h"
#include "../g_local.h"
//#include "sabin_debug.h"
#include <windows.h>
#include <GL/gl.h>
/*
#ifdef CGF
// AI update related to fog
#include "cgf_tactics_visibility.h"
#endif
*/
}
#include <vector>
#include <fstream>
#include <strstream>
using namespace std;
// defaults
static vec_t m_FogDensity = 0.1000;
static int m_FogEnabled = false;
static int m_FogType = 2; // linear
static int m_FogStart = 200;
static int m_FogEnd = 1600;
static vec_t m_FogColor[4] = {0.5, 0.5, 0.5, 1};
static char m_Settings[64];
const int kMaxViewingDistance = 8192;
const int kViewingDistanceStep = 64;
*/
}
#include <vector>
#include <fstream>
#include <strstream>
using namespace std;
// defaults
static vec_t m_FogDensity = 0.1000;
static int m_FogEnabled = false;
static int m_FogType = 2; // linear
static int m_FogStart = 200;
static int m_FogEnd = 1600;
static vec_t m_FogColor[4] = {0.5, 0.5, 0.5, 1};
static char m_Settings[64];
const int kMaxViewingDistance = 8192;
const int kViewingDistanceStep = 64;
static vec_t m_FogViewReduction[kMaxViewingDistance / kViewingDistanceStep];
//static vec_t m_FogViewReduction[128];
// cvar for fog and video mode
static cvar_t* fog = 0;
static cvar_t* vid_ref = 0;
// forward decls
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
);
void CGF_SFX_DeactivateFog();
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
);
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd);
void CGF_SFX_InstallFogSupport()
{
// reset settings
m_Settings[0] = 0;//char(0);
// if fog > 0, then enabled
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
// prevent issueing gl calls if no opengl present
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
// if not fog enabled, act upon it
if (!m_FogEnabled)
{
if (fog->value == 0)
{
strcpy(m_Settings, "cvar fog is 0");
// CGF_Debug_LogMessage("fog disabled: cvar fog is 0");
}
else
{
strcpy(m_Settings, "using software rendering");
// CGF_Debug_LogMessage("fog disabled: using software rendering");
}
gi.cvar_set("fog", "0");
}
}
void CGF_SFX_AdjustFogForMap(const char* aMapName)
{
// verify fog if m_FogEnabled, and reset if required
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
if (m_FogEnabled)
{
if (!(m_FogEnabled = (fog->value != 0)))
{
#ifdef CGF
CGF_Debug_LogMessage("fog disabled: fog set to 0 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
else
{
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
if (m_FogEnabled)
{
#ifdef CGF
CGF_Debug_LogMessage("fog enabled : fog set to 1 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
// process fog setting
if (m_FogEnabled)
{
vec_t d;
int t;
vec_t s;
vec_t e;
vec3_t rgb;
if ( (!aMapName)
|| (!CGF_SFX_FindFogPreferences(aMapName, &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
)
{
if (!CGF_SFX_FindFogPreferences("default", &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
{
d = m_FogDensity;
t = m_FogType;
VectorCopy(m_FogColor, rgb);
s = m_FogStart;
e = m_FogEnd;
}
}
// convert d to value usable for gl lib
d /= 100;
// convert fog type
// 0 == GL_EXP, 1 == GL_EXP2, 2 == GL_LINEAR
if ((t < 0) || (t > 2))
t = m_FogType;
if (t < 2)
t = t + 0x800;
else
t = GL_LINEAR;
if (d > 0)
CGF_SFX_ActivateFog(d, t, rgb, s, e);
else
CGF_SFX_DeactivateFog();
}
else
{
CGF_SFX_DeactivateFog();
}
}
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
)
{
*aDensity = 0;
// try to read preferences from file action\cgf\fog\<mapname>.fog
// format for file is:
// // format: mapname density fogtype red green blue
char buf_filename[256];
ostrstream filename(buf_filename, 255);
cvar_t* gamedir;
cvar_t* basedir;
gamedir = gi.cvar ("game", "", 0);
basedir = gi.cvar("basedir", ".", 0);
// obtain file location
filename << basedir->string << '\\' << gamedir->string
<< '\\' << "cgf\\fog\\" << aMapName << ".fog" << char(0);
// open file, append mode
ifstream preferences(buf_filename, ios_base::in);
if (preferences.good())
{
char name[128];
memset(name,0, sizeof(name));
preferences >> name;
// skip comment lines if any
while ( (strlen(name) >= 2)
&& (name[0] == '/')
&& ( (name[1] == '/')
|| (name[1] == '*')
)
)
{
preferences.getline(name, 128);
memset(name,0, sizeof(name));
preferences >> name;
}
/* test for name similarity removed
if ( (strlen(name))
&& ( 0 == stricmp(name, aMapName))
)
*/
{
preferences >> *aDensity;
if (*aDensity > 0)
{
preferences >> *aType;
preferences >> *aRed;
preferences >> *aGreen;
preferences >> *aBlue;
preferences >> *aBegin;
preferences >> *aEnd;
}
// adjust settings info
ostrstream settings(buf_filename, 63);
settings << "cgf\\fog\\" << aMapName << ".fog" << char(0);
strcpy(m_Settings, buf_filename);
return true;
}
}
return false;
}
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
)
{
#ifdef CGF
if (CGF_Debug_IsLogging())
{
char message[256];
if (aDensity)
sprintf(message,
"fog settings: mode %d, density %.2f, rgb=[%.2f, %.2f, %.2f], begin %d, end %d",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity, aColor[0], aColor[1], aColor[2], (int) aBegin, (int) anEnd
);
else
sprintf(message,
"fog settings: mode %d, density %.2f == disabled",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity
);
CGF_Debug_LogMessage(message);
}
#endif
CGF_SFX_InitFogForDistance(aType, aDensity, aBegin, anEnd);
glEnable (GL_FOG); // turn on fog, otherwise you won't see any
glFogi (GL_FOG_MODE, aType);
if (aType == GL_LINEAR)
{
glFogf (GL_FOG_START, aBegin);
glFogf (GL_FOG_END, anEnd);
}
glFogfv (GL_FOG_COLOR, aColor);
glFogf (GL_FOG_DENSITY, aDensity);
glHint (GL_FOG_HINT, GL_NICEST);
}
void CGF_SFX_DeactivateFog()
{
CGF_SFX_InitFogForDistance(0, 0, 0, 0);
// prevent opengl calls when no opengl
if ( (vid_ref)
&& (0 == stricmp(vid_ref->string, "soft"))
)
return;
glDisable (GL_FOG); // turn off fog
}
int CGF_SFX_IsFogEnabled()
{
return m_FogEnabled;
}
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd)
{
// determine how many cells
int cells;
cells = kMaxViewingDistance / kViewingDistanceStep;
vec_t dist;
vec_t maxdist;
vec_t mindist;
if (aFogDensity == 0.0)
aFogMode = 0;
// adjust fog density value to our values
aFogDensity *= 100;
switch (aFogMode)
{
case GL_LINEAR:
maxdist = aFogEnd;
mindist = aFogBegin;
break;
case GL_EXP:
maxdist = 400.0 / sqrt(aFogDensity);
break;
case GL_EXP2:
maxdist = 130.0 / aFogDensity;
break;
default :
maxdist = kMaxViewingDistance;
}
dist = 0;
for (int cell = 0; cell < cells; cell++)
{
vec_t reduction;
switch (aFogMode)
{
case GL_LINEAR:
if (dist < mindist)
reduction = 1;
else
if (dist > maxdist)
reduction = 0;
else
reduction = 1 - (dist - mindist) / (maxdist - mindist);
break;
case GL_EXP:
reduction = 1 - dist / maxdist;
break;
case GL_EXP2:
reduction = 1 - (dist / maxdist) * (dist / maxdist);
break;
default :
reduction = 1.0;
}
if (reduction < 0)
reduction = 0;
m_FogViewReduction[cell] = reduction;
dist += kViewingDistanceStep;
}
}
const char* CGF_SFX_FogSettingsInfo()
{
return (const char*) m_Settings;
}
vec_t CGF_SFX_GetFogForDistance(vec_t dist)
{
int index;
index = ((int) dist) / (int) kViewingDistanceStep;
assert( (index < (kMaxViewingDistance / kViewingDistanceStep))
);
return m_FogViewReduction[index];
}
vec_t CGF_SFX_GetViewingDistanceUpToReduction(vec_t aReduction)
{
int index;
index = (kMaxViewingDistance / kViewingDistanceStep) - 1;
while ( (index >= 0)
&& (m_FogViewReduction[index] < aReduction)
)
index--;
return (vec_t) (index * kViewingDistanceStep);
}
/*
#ifdef _DEBUG
extern "C" void CGF_SFX_Fog_DisplayRods(edict_t* aClient);
void CGF_SFX_Fog_DisplayRods(edict_t* aClient)
{
vec3_t forward;
vec3_t v1;
vec3_t v2;
bool half;
bool ten;
half = false;
ten = false;
AngleVectors(aClient->s.angles, forward, 0, 0);
forward[2] = 0;
VectorNormalize(forward);
for (int rod = 0; rod < 20; rod ++)
{
VectorMA(aClient->s.origin, 100 * ((float) rod), forward, v1);
VectorCopy(v1, v2);
v2[2] -= 1000;
SABIN_Debug_DisplayLine(v1, v2, 60);
if ( (!half)
&& (half = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.5))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
if ( (!ten)
&& (ten = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.1))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
}
}
#endif
*/
//#endif
//static vec_t m_FogViewReduction[128];
// cvar for fog and video mode
static cvar_t* fog = 0;
static cvar_t* vid_ref = 0;
// forward decls
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
);
void CGF_SFX_DeactivateFog();
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
);
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd);
void CGF_SFX_InstallFogSupport()
{
// reset settings
m_Settings[0] = 0;//char(0);
// if fog > 0, then enabled
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
// prevent issueing gl calls if no opengl present
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
// if not fog enabled, act upon it
if (!m_FogEnabled)
{
if (fog->value == 0)
{
strcpy(m_Settings, "cvar fog is 0");
// CGF_Debug_LogMessage("fog disabled: cvar fog is 0");
}
else
{
strcpy(m_Settings, "using software rendering");
// CGF_Debug_LogMessage("fog disabled: using software rendering");
}
gi.cvar_set("fog", "0");
}
}
void CGF_SFX_AdjustFogForMap(const char* aMapName)
{
// verify fog if m_FogEnabled, and reset if required
fog = gi.cvar("fog", "0", 0);
vid_ref = gi.cvar("vid_ref", "", 0);
if (m_FogEnabled)
{
if (!(m_FogEnabled = (fog->value != 0)))
{
#ifdef CGF
CGF_Debug_LogMessage("fog disabled: fog set to 0 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
else
{
m_FogEnabled = ( (fog->value > 0)
&& (0 != stricmp(vid_ref->string, "soft"))
);
if (m_FogEnabled)
{
#ifdef CGF
CGF_Debug_LogMessage("fog enabled : fog set to 1 or video mode changed");
// change visibility info for AI
CGF_Tactics_IncorporateChangedFogSettings();
#endif
}
}
// process fog setting
if (m_FogEnabled)
{
vec_t d;
int t;
vec_t s;
vec_t e;
vec3_t rgb;
if ( (!aMapName)
|| (!CGF_SFX_FindFogPreferences(aMapName, &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
)
{
if (!CGF_SFX_FindFogPreferences("default", &d, &t, &rgb[0], &rgb[1], &rgb[2], &s, &e))
{
d = m_FogDensity;
t = m_FogType;
VectorCopy(m_FogColor, rgb);
s = m_FogStart;
e = m_FogEnd;
}
}
// convert d to value usable for gl lib
d /= 100;
// convert fog type
// 0 == GL_EXP, 1 == GL_EXP2, 2 == GL_LINEAR
if ((t < 0) || (t > 2))
t = m_FogType;
if (t < 2)
t = t + 0x800;
else
t = GL_LINEAR;
if (d > 0)
CGF_SFX_ActivateFog(d, t, rgb, s, e);
else
CGF_SFX_DeactivateFog();
}
else
{
CGF_SFX_DeactivateFog();
}
}
qboolean CGF_SFX_FindFogPreferences(const char* aMapName,
vec_t* aDensity,
int* aType,
vec_t* aRed,
vec_t* aGreen,
vec_t* aBlue,
vec_t* aBegin,
vec_t* aEnd
)
{
*aDensity = 0;
// try to read preferences from file action\cgf\fog\<mapname>.fog
// format for file is:
// // format: mapname density fogtype red green blue
char buf_filename[256];
ostrstream filename(buf_filename, 255);
cvar_t* gamedir;
cvar_t* basedir;
gamedir = gi.cvar ("game", "", 0);
basedir = gi.cvar("basedir", ".", 0);
// obtain file location
filename << basedir->string << '\\' << gamedir->string
<< '\\' << "cgf\\fog\\" << aMapName << ".fog" << char(0);
// open file, append mode
ifstream preferences(buf_filename, ios_base::in);
if (preferences.good())
{
char name[128];
memset(name,0, sizeof(name));
preferences >> name;
// skip comment lines if any
while ( (strlen(name) >= 2)
&& (name[0] == '/')
&& ( (name[1] == '/')
|| (name[1] == '*')
)
)
{
preferences.getline(name, 128);
memset(name,0, sizeof(name));
preferences >> name;
}
/* test for name similarity removed
if ( (strlen(name))
&& ( 0 == stricmp(name, aMapName))
)
*/
{
preferences >> *aDensity;
if (*aDensity > 0)
{
preferences >> *aType;
preferences >> *aRed;
preferences >> *aGreen;
preferences >> *aBlue;
preferences >> *aBegin;
preferences >> *aEnd;
}
// adjust settings info
ostrstream settings(buf_filename, 63);
settings << "cgf\\fog\\" << aMapName << ".fog" << char(0);
strcpy(m_Settings, buf_filename);
return true;
}
}
return false;
}
void CGF_SFX_ActivateFog(vec_t aDensity,
int aType,
vec3_t aColor,
vec_t aBegin,
vec_t anEnd
)
{
#ifdef CGF
if (CGF_Debug_IsLogging())
{
char message[256];
if (aDensity)
sprintf(message,
"fog settings: mode %d, density %.2f, rgb=[%.2f, %.2f, %.2f], begin %d, end %d",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity, aColor[0], aColor[1], aColor[2], (int) aBegin, (int) anEnd
);
else
sprintf(message,
"fog settings: mode %d, density %.2f == disabled",
(aType == GL_LINEAR ? 2 : aType - GL_FOG_START),
aDensity
);
CGF_Debug_LogMessage(message);
}
#endif
CGF_SFX_InitFogForDistance(aType, aDensity, aBegin, anEnd);
glEnable (GL_FOG); // turn on fog, otherwise you won't see any
glFogi (GL_FOG_MODE, aType);
if (aType == GL_LINEAR)
{
glFogf (GL_FOG_START, aBegin);
glFogf (GL_FOG_END, anEnd);
}
glFogfv (GL_FOG_COLOR, aColor);
glFogf (GL_FOG_DENSITY, aDensity);
glHint (GL_FOG_HINT, GL_NICEST);
}
void CGF_SFX_DeactivateFog()
{
CGF_SFX_InitFogForDistance(0, 0, 0, 0);
// prevent opengl calls when no opengl
if ( (vid_ref)
&& (0 == stricmp(vid_ref->string, "soft"))
)
return;
glDisable (GL_FOG); // turn off fog
}
int CGF_SFX_IsFogEnabled()
{
return m_FogEnabled;
}
void CGF_SFX_InitFogForDistance(int aFogMode, vec_t aFogDensity, vec_t aFogBegin, vec_t aFogEnd)
{
// determine how many cells
int cells;
cells = kMaxViewingDistance / kViewingDistanceStep;
vec_t dist;
vec_t maxdist;
vec_t mindist;
if (aFogDensity == 0.0)
aFogMode = 0;
// adjust fog density value to our values
aFogDensity *= 100;
switch (aFogMode)
{
case GL_LINEAR:
maxdist = aFogEnd;
mindist = aFogBegin;
break;
case GL_EXP:
maxdist = 400.0 / sqrt(aFogDensity);
break;
case GL_EXP2:
maxdist = 130.0 / aFogDensity;
break;
default :
maxdist = kMaxViewingDistance;
}
dist = 0;
for (int cell = 0; cell < cells; cell++)
{
vec_t reduction;
switch (aFogMode)
{
case GL_LINEAR:
if (dist < mindist)
reduction = 1;
else
if (dist > maxdist)
reduction = 0;
else
reduction = 1 - (dist - mindist) / (maxdist - mindist);
break;
case GL_EXP:
reduction = 1 - dist / maxdist;
break;
case GL_EXP2:
reduction = 1 - (dist / maxdist) * (dist / maxdist);
break;
default :
reduction = 1.0;
}
if (reduction < 0)
reduction = 0;
m_FogViewReduction[cell] = reduction;
dist += kViewingDistanceStep;
}
}
const char* CGF_SFX_FogSettingsInfo()
{
return (const char*) m_Settings;
}
vec_t CGF_SFX_GetFogForDistance(vec_t dist)
{
int index;
index = ((int) dist) / (int) kViewingDistanceStep;
assert( (index < (kMaxViewingDistance / kViewingDistanceStep))
);
return m_FogViewReduction[index];
}
vec_t CGF_SFX_GetViewingDistanceUpToReduction(vec_t aReduction)
{
int index;
index = (kMaxViewingDistance / kViewingDistanceStep) - 1;
while ( (index >= 0)
&& (m_FogViewReduction[index] < aReduction)
)
index--;
return (vec_t) (index * kViewingDistanceStep);
}
/*
#ifdef _DEBUG
extern "C" void CGF_SFX_Fog_DisplayRods(edict_t* aClient);
void CGF_SFX_Fog_DisplayRods(edict_t* aClient)
{
vec3_t forward;
vec3_t v1;
vec3_t v2;
bool half;
bool ten;
half = false;
ten = false;
AngleVectors(aClient->s.angles, forward, 0, 0);
forward[2] = 0;
VectorNormalize(forward);
for (int rod = 0; rod < 20; rod ++)
{
VectorMA(aClient->s.origin, 100 * ((float) rod), forward, v1);
VectorCopy(v1, v2);
v2[2] -= 1000;
SABIN_Debug_DisplayLine(v1, v2, 60);
if ( (!half)
&& (half = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.5))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
if ( (!ten)
&& (ten = (CGF_SFX_GetFogForDistance(100 * ((float) rod)) < 0.1))
)
{
SABIN_Debug_DisplayPoint(v1, RF_SHELL_RED, 60);
}
}
}
#endif
*/
#endif

Binary file not shown.

View file

@ -32,11 +32,11 @@ gitem_armor_t jacketarmor_info = { 25, 50, .30, .00, ARMOR_JACKET};
gitem_armor_t combatarmor_info = { 50, 100, .60, .30, ARMOR_COMBAT};
gitem_armor_t bodyarmor_info = {100, 200, .80, .60, ARMOR_BODY};
static int jacket_armor_index;
static int combat_armor_index;
static int body_armor_index;
static int power_screen_index;
static int power_shield_index;
int jacket_armor_index;
int combat_armor_index;
int body_armor_index;
int power_screen_index;
int power_shield_index;
#define HEALTH_IGNORE_MAX 1
#define HEALTH_TIMED 2

View file

@ -1458,7 +1458,7 @@ bind 6 "use Sniper Rifle"
#define GRENADE_DAMRAD 170
// ACEBOT_ADD
#include "acesrc\acebot.h"
#include "acesrc/acebot.h"
// ACEBOT_END
#endif
#endif

View file

@ -25,9 +25,6 @@
*/
#include "g_local.h"
#include "cgf_sfx_glass.h"
// CGF_FOG ADD
#include "acesrc/cgf_sfx_fog.h"
// CGF_FOG END
field_t fields[] = {
{"classname", FOFS(classname), F_LSTRING},
@ -282,9 +279,6 @@ void InitGame (void)
globals.edicts = g_edicts;
globals.max_edicts = game.maxentities;
// CGF_FOG ADD
CGF_SFX_InstallFogSupport();
// CGF_FOG END
// initialize all clients for this game
game.maxclients = maxclients->value;
game.clients = gi.TagMalloc (game.maxclients * sizeof(game.clients[0]), TAG_GAME);

View file

@ -10,9 +10,6 @@
*/
#include "g_local.h"
// CGF_FOG ADD
#include "acesrc/cgf_sfx_fog.h"
// CGF_FOG END
typedef struct
{
@ -686,9 +683,6 @@ void SpawnEntities (char *mapname, char *entities, char *spawnpoint)
//zucc for special items
SetupSpecSpawn();
}
// CGF_FOG ADD
CGF_SFX_AdjustFogForMap(level.mapname);
// CGF_FOG END
}