2016-03-27 11:49:47 +02:00
/*
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Copyright ( C ) 2015 the OpenMoHAA team
This file is part of OpenMoHAA source code .
OpenMoHAA 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 .
OpenMoHAA 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 .
You should have received a copy of the GNU General Public License
along with OpenMoHAA source code ; if not , write to the Free Software
Foundation , Inc . , 51 Franklin St , Fifth Floor , Boston , MA 02110 - 1301 USA
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
// world.cpp : Holds the target list, and general info (fog and such).
2023-04-29 21:56:38 +02:00
# include "g_phys.h"
2016-03-27 11:49:47 +02:00
# include "world.h"
2023-01-29 20:59:31 +01:00
# include "level.h"
2023-04-29 21:56:38 +02:00
# include "scriptmaster.h"
# include "scriptexception.h"
2023-08-17 17:39:54 +02:00
# include "player.h"
2016-03-27 11:49:47 +02:00
# ifdef GAME_DLL
2023-06-15 23:44:02 +02:00
# include "../fgame/soundman.h"
2016-03-27 11:49:47 +02:00
# endif
WorldPtr world ;
2018-07-21 01:39:35 +02:00
Event EV_World_MapTime
(
2023-08-28 20:22:06 +02:00
" map_time " ,
EV_DEFAULT ,
" i " ,
" version " ,
" Internal usage. "
2018-07-21 01:39:35 +02:00
) ;
2016-03-27 11:49:47 +02:00
Event EV_World_SetSoundtrack
(
2023-08-28 20:22:06 +02:00
" soundtrack " ,
EV_DEFAULT ,
" s " ,
" MusicFile " ,
" Set music soundtrack for this level. "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetGravity
(
2023-08-28 20:22:06 +02:00
" gravity " ,
EV_DEFAULT ,
" f " ,
" worldGravity " ,
" Set the gravity for the whole world. "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetNextMap
(
2023-08-28 20:22:06 +02:00
" nextmap " ,
EV_DEFAULT ,
" s " ,
" nextMap " ,
" Set the next map to change to "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetMessage
(
2023-08-28 20:22:06 +02:00
" message " ,
EV_DEFAULT ,
" s " ,
" worldMessage " ,
" Set a message for the world "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetWaterColor
(
2023-08-28 20:22:06 +02:00
" watercolor " ,
EV_DEFAULT ,
" v " ,
" waterColor " ,
" Set the watercolor screen blend "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetWaterAlpha
(
2023-08-28 20:22:06 +02:00
" wateralpha " ,
EV_DEFAULT ,
" f " ,
" waterAlpha " ,
" Set the alpha of the water screen blend "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetLavaColor
(
2023-08-28 20:22:06 +02:00
" lavacolor " ,
EV_DEFAULT ,
" v " ,
" lavaColor " ,
" Set the color of lava screen blend "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetLavaAlpha
(
2023-08-28 20:22:06 +02:00
" lavaalpha " ,
EV_DEFAULT ,
" f " ,
" lavaAlpha " ,
" Set the alpha of lava screen blend "
2016-03-27 11:49:47 +02:00
) ;
2023-08-17 17:39:54 +02:00
Event EV_World_GetFarPlane_Color
(
2023-08-28 20:22:06 +02:00
" farplane_color " ,
EV_DEFAULT ,
NULL ,
NULL ,
" Get the color of the far clipping plane fog " ,
EV_GETTER
2023-08-17 17:39:54 +02:00
) ;
2016-03-27 11:49:47 +02:00
Event EV_World_SetFarPlane_Color
(
2023-08-28 20:22:06 +02:00
" farplane_color " ,
EV_DEFAULT ,
" v " ,
" farplaneColor " ,
" Set the color of the far clipping plane fog " ,
EV_SETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetFarPlane_Color2
(
2023-08-28 20:22:06 +02:00
" farplane_color " ,
EV_DEFAULT ,
" v " ,
" farplaneColor " ,
" Set the color of the far clipping plane fog " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetAnimatedFarPlaneColor
(
2023-08-28 20:22:06 +02:00
" animated_farplane_color " ,
EV_DEFAULT ,
" vvff " ,
" colorStart colorEnd ZStart ZEnd " ,
" Set the color of the far clipping plane based on a color range and a Z range " ,
EV_NORMAL
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetFarPlane_Cull
(
2023-08-28 20:22:06 +02:00
" farplane_cull " ,
EV_DEFAULT ,
" i " ,
" farplaneCull " ,
" Whether or not the far clipping plane should cull things out of the world \n "
" 0 - no cull \n "
" 1 - normal cull \n "
" 2 - cull but no bsp culling "
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_GetFarPlane
(
2023-08-28 20:22:06 +02:00
" farplane " ,
EV_DEFAULT ,
NULL ,
NULL ,
" Get the distance of the far clipping plane " ,
EV_GETTER
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetFarPlane
(
2023-08-28 20:22:06 +02:00
" farplane " ,
EV_DEFAULT ,
" f " ,
" farplaneDistance " ,
" Set the distance of the far clipping plane " ,
EV_SETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetFarClipOverride
(
2023-08-28 20:22:06 +02:00
" farclipoverride " ,
EV_DEFAULT ,
" f " ,
" farclipoverride " ,
" Override the min config default for the far clip distance " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetFarPlaneColorOverride
(
2023-08-28 20:22:06 +02:00
" farplaneclipcolor " ,
EV_DEFAULT ,
" v " ,
" farplaneclipcolor " ,
" Override the fog color for the min config " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetFarPlane2
(
2023-08-28 20:22:06 +02:00
" farplane " ,
EV_DEFAULT ,
" f " ,
" farplaneDistance " ,
" Set the distance of the far clipping plane " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetAnimatedFarPlane
(
2023-08-28 20:22:06 +02:00
" animated_farplane " ,
EV_DEFAULT ,
" ffff " ,
" farplaneStart farplaneEnd ZStart ZEnd " ,
" Set the distance of the far clipping plane based on a farplane range and a Z range " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_GetFarPlaneBias
(
2023-08-28 20:22:06 +02:00
" farplane_bias " ,
EV_DEFAULT ,
NULL ,
NULL ,
" Get the distance bias of the far clipping plane " ,
EV_GETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetFarPlaneBias
(
2023-08-28 20:22:06 +02:00
" farplane_bias " ,
EV_DEFAULT ,
" f " ,
" farplaneDistanceBias " ,
" Set the distance bias of the far clipping plane " ,
EV_SETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetFarPlaneBias2
(
2023-08-28 20:22:06 +02:00
" farplane_bias " ,
EV_DEFAULT ,
" f " ,
" farplaneDistanceBias " ,
" Set the distance bias of the far clipping plane " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetAnimatedFarPlaneBias
(
2023-08-28 20:22:06 +02:00
" animated_farplane_bias " ,
EV_DEFAULT ,
" ffff " ,
" biasStart biasEnd ZStart ZEnd " ,
" Set the bias of the far clipping plane based on a bias range and a Z range " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_UpdateAnimatedFarplane
(
2023-08-28 20:22:06 +02:00
" _update_animated_farplane " ,
EV_DEFAULT ,
NULL ,
NULL ,
" Updates the farplane if it is being animated. " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_GetSkyboxFarPlane
(
2023-08-28 20:22:06 +02:00
" skybox_farplane " ,
EV_DEFAULT ,
NULL ,
NULL ,
" Get the distance of the skybox far clipping plane " ,
EV_GETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetSkyboxFarPlane
(
2023-08-28 20:22:06 +02:00
" skybox_farplane " ,
EV_DEFAULT ,
" f " ,
" farplaneDistance " ,
" Set the distance of the skybox far clipping plane " ,
EV_SETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetSkyboxFarPlane2
(
2023-08-28 20:22:06 +02:00
" skybox_farplane " ,
EV_DEFAULT ,
" f " ,
" farplaneDistance " ,
" Set the distance of the skybox far clipping plane " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_GetSkyboxSpeed
(
2023-08-28 20:22:06 +02:00
" skybox_speed " ,
EV_DEFAULT ,
NULL ,
NULL ,
" Get the speed of the skybox " ,
EV_GETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetSkyboxSpeed
(
2023-08-28 20:22:06 +02:00
" skybox_speed " ,
EV_DEFAULT ,
" f " ,
" speed " ,
" Set the speed of the skybox " ,
EV_SETTER
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetSkyboxSpeed2
(
2023-08-28 20:22:06 +02:00
" skybox_speed " ,
EV_DEFAULT ,
" f " ,
" speed " ,
" Set the speed of the skybox " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetRenderTerrain
(
2023-08-28 20:22:06 +02:00
" render_terrain " ,
EV_DEFAULT ,
" b " ,
" render_terrain " ,
" Set to draw or not draw terrain " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_GetRenderTerrain
(
2023-08-28 20:22:06 +02:00
" get_render_terrain " ,
EV_DEFAULT ,
NULL ,
NULL ,
" Get the render terrain switch " ,
EV_GETTER
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetAmbientLight
(
2023-08-28 20:22:06 +02:00
" ambientlight " ,
EV_DEFAULT ,
" b " ,
" ambientLight " ,
" Set whether or not ambient light should be used "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetAmbientIntensity
(
2023-08-28 20:22:06 +02:00
" ambient " ,
EV_DEFAULT ,
" f " ,
" ambientIntensity " ,
" Set the intensity of the ambient light "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetSunColor
(
2023-08-28 20:22:06 +02:00
" suncolor " ,
EV_DEFAULT ,
" v " ,
" sunColor " ,
" Set the color of the sun "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetSunLight
(
2023-08-28 20:22:06 +02:00
" sunlight " ,
EV_DEFAULT ,
" b " ,
" sunlight " ,
" Set whether or not there should be sunlight "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetSunDirection
(
2023-08-28 20:22:06 +02:00
" sundirection " ,
EV_DEFAULT ,
" v " ,
" sunlightDirection " ,
" Set the direction of the sunlight "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_LightmapDensity
(
2023-08-28 20:22:06 +02:00
" lightmapdensity " ,
EV_DEFAULT ,
" f " ,
" density " ,
" Set the default lightmap density for all world surfaces "
2016-03-27 11:49:47 +02:00
) ;
2023-08-17 17:39:54 +02:00
Event EV_World_SunFlareName
2016-03-27 11:49:47 +02:00
(
2023-08-28 20:22:06 +02:00
" sunflarename " ,
EV_DEFAULT ,
" s " ,
" flarename " ,
" Set the flare to use for the sunflare "
2016-03-27 11:49:47 +02:00
) ;
2023-08-17 17:39:54 +02:00
Event EV_World_SunFlareDirection
2016-03-27 11:49:47 +02:00
(
2023-08-28 20:22:06 +02:00
" sunflaredirection " ,
EV_DEFAULT ,
" v " ,
" angles " ,
" Set the direction of the sunflare "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetSkyAlpha
(
2023-08-28 20:22:06 +02:00
" skyalpha " ,
EV_DEFAULT ,
" f " ,
" newAlphaForPortalSky " ,
" Set the alpha on the sky "
2016-03-27 11:49:47 +02:00
) ;
Event EV_World_SetSkyPortal
(
2023-08-28 20:22:06 +02:00
" skyportal " ,
EV_DEFAULT ,
" b " ,
" newSkyPortalState " ,
" Whether or not to use the sky portal at all "
2016-03-27 11:49:47 +02:00
) ;
2023-08-17 17:39:54 +02:00
Event EV_World_SetNumArenas
(
2023-08-28 20:22:06 +02:00
" numarenas " ,
EV_DEFAULT ,
" i " ,
" numarenas " ,
" Set the number of arenas in the world " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_SetAIVisionDistance
(
2023-08-28 20:22:06 +02:00
" ai_visiondistance " ,
EV_DEFAULT ,
" f " ,
" vision_distance " ,
" Sets the default AI Vision Distance " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
2016-03-27 11:49:47 +02:00
Event EV_World_SetNorthYaw
(
2023-08-28 20:22:06 +02:00
" northyaw " ,
EV_DEFAULT ,
" f " ,
" yaw " ,
" Sets the yaw direction that is considered to be north "
2016-03-27 11:49:47 +02:00
) ;
2018-07-21 01:39:35 +02:00
Event EV_World_SetSunDiffuse
(
2023-08-28 20:22:06 +02:00
" sundiffuse " ,
EV_DEFAULT ,
" f " ,
" factor " ,
" Sets the fraction of the sunlight to use for diffuse sun "
2018-07-21 01:39:35 +02:00
) ;
Event EV_World_SetSunDiffuseColor
(
2023-08-28 20:22:06 +02:00
" sundiffusecolor " ,
EV_DEFAULT ,
" v " ,
" diffusecolor " ,
" Sets an alternate sun color to use for clcing diffuse sun "
2018-07-21 01:39:35 +02:00
) ;
2023-08-17 17:39:54 +02:00
Event EV_World_Overbright
(
2023-08-28 20:22:06 +02:00
" overbright " ,
EV_DEFAULT ,
" i " ,
" use " ,
" When set to non-zero, removes the overbright cutoff of lightmaps " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
Event EV_World_VisDerived
(
2023-08-28 20:22:06 +02:00
" vis_derived " ,
EV_DEFAULT ,
" i " ,
" use " ,
" whether or not the vis compiler derives additional vis info from the manual vis " ,
EV_NORMAL
2023-08-17 17:39:54 +02:00
) ;
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
CLASS_DECLARATION ( Entity , World , " worldspawn " )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
{ & EV_World_SetSoundtrack , & World : : SetSoundtrack } ,
{ & EV_World_SetGravity , & World : : SetGravity } ,
{ & EV_World_SetNextMap , & World : : SetNextMap } ,
{ & EV_World_SetMessage , & World : : SetMessage } ,
{ & EV_World_SetWaterColor , & World : : SetWaterColor } ,
{ & EV_World_SetWaterAlpha , & World : : SetWaterAlpha } ,
{ & EV_World_SetLavaColor , & World : : SetLavaColor } ,
{ & EV_World_SetLavaAlpha , & World : : SetLavaAlpha } ,
{ & EV_World_GetFarPlane_Color , & World : : GetFarPlane_Color } ,
{ & EV_World_SetFarPlane_Color , & World : : SetFarPlane_Color } ,
{ & EV_World_SetFarPlane_Color2 , & World : : SetFarPlane_Color } ,
{ & EV_World_SetFarPlane_Cull , & World : : SetFarPlane_Cull } ,
{ & EV_World_GetFarPlane , & World : : GetFarPlane } ,
{ & EV_World_SetFarPlane , & World : : SetFarPlane } ,
{ & EV_World_SetFarClipOverride , & World : : SetFarClipOverride } ,
{ & EV_World_SetFarPlaneColorOverride , & World : : SetFarPlaneColorOverride } ,
{ & EV_World_SetFarPlane2 , & World : : SetFarPlane } ,
{ & EV_World_GetFarPlaneBias , & World : : GetFarPlaneBias } ,
{ & EV_World_SetFarPlaneBias , & World : : SetFarPlaneBias } ,
{ & EV_World_SetFarPlaneBias2 , & World : : SetFarPlaneBias } ,
{ & EV_World_GetSkyboxFarPlane , & World : : GetSkyboxFarplane } ,
{ & EV_World_SetSkyboxFarPlane , & World : : SetSkyboxFarplane } ,
{ & EV_World_SetSkyboxFarPlane2 , & World : : SetSkyboxFarplane } ,
{ & EV_World_GetSkyboxSpeed , & World : : GetSkyboxSpeed } ,
{ & EV_World_SetSkyboxSpeed , & World : : SetSkyboxSpeed } ,
{ & EV_World_SetSkyboxSpeed2 , & World : : SetSkyboxSpeed } ,
{ & EV_World_GetRenderTerrain , & World : : GetRenderTerrain } ,
{ & EV_World_SetRenderTerrain , & World : : SetRenderTerrain } ,
{ & EV_World_SetSkyAlpha , & World : : SetSkyAlpha } ,
{ & EV_World_SetSkyPortal , & World : : SetSkyPortal } ,
{ & EV_World_SetNorthYaw , & World : : SetNorthYaw } ,
{ & EV_World_SetAmbientLight , NULL } ,
{ & EV_World_SetAmbientIntensity , NULL } ,
{ & EV_World_SetSunColor , NULL } ,
{ & EV_World_SetSunLight , NULL } ,
{ & EV_World_SetSunDirection , NULL } ,
{ & EV_World_LightmapDensity , NULL } ,
{ & EV_World_SunFlareName , NULL } ,
{ & EV_World_SunFlareDirection , NULL } ,
{ & EV_World_SetNumArenas , NULL } ,
{ & EV_World_SetSunDiffuse , NULL } ,
{ & EV_World_SetSunDiffuseColor , NULL } ,
{ & EV_World_Overbright , NULL } ,
{ & EV_World_VisDerived , NULL } ,
{ & EV_World_SetAIVisionDistance , & World : : SetAIVisionDistance } ,
{ & EV_World_SetNorthYaw , & World : : SetNorthYaw } ,
{ & EV_World_SetAnimatedFarPlaneColor , & World : : SetAnimatedFarplaneColor } ,
{ & EV_World_SetAnimatedFarPlane , & World : : SetAnimatedFarplane } ,
{ & EV_World_SetAnimatedFarPlaneBias , & World : : SetAnimatedFarplaneBias } ,
{ & EV_World_UpdateAnimatedFarplane , & World : : UpdateAnimatedFarplane } ,
{ NULL , NULL }
2023-08-17 17:39:54 +02:00
} ;
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
World : : World ( )
{
2023-08-28 20:22:06 +02:00
world = this ;
world_dying = qfalse ;
// Anything that modifies configstrings, or spawns things is ignored when loading savegames
if ( LoadingSavegame )
{
return ;
}
assert ( entnum = = ENTITYNUM_WORLD ) ;
setMoveType ( MOVETYPE_NONE ) ;
setSolidType ( SOLID_BSP ) ;
// world model is always index 1
edict - > s . modelindex = 1 ;
model = " *1 " ;
UpdateConfigStrings ( ) ;
// clear out the soundtrack from the last level
ChangeSoundtrack ( " " ) ;
// set the default gravity
gi . cvar_set ( " sv_gravity " , " 800 " ) ;
// set the default farplane parameters
farplane_distance = 0 ;
farplane_bias = 0.0 ;
farplane_color = vec_zero ;
farplane_cull = qtrue ;
skybox_farplane = 0.0 ;
render_terrain = qtrue ;
skybox_speed = 0.0 ;
farclip_override = 0.f ;
farplane_color_override = Vector ( - 1 , - 1 , - 1 ) ;
animated_farplane_start = 0.0 ;
animated_farplane_end = 0.0 ;
animated_farplane_start_z = 8192.0 ;
animated_farplane_end_z = 0.0 ;
animated_farplane_bias_start = 0.0 ;
animated_farplane_bias_end = 0.0 ;
animated_farplane_bias_start_z = 8192.0 ;
animated_farplane_bias_end_z = 0.0 ;
animated_farplane_color_start = vec_zero ;
animated_farplane_color_end = vec_zero ;
animated_farplane_color_start_z = 8192.0 ;
animated_farplane_color_end_z = 0.0 ;
UpdateFog ( ) ;
sky_alpha = 1.0f ;
sky_portal = qtrue ;
UpdateSky ( ) ;
m_fAIVisionDistance = 2048.0f ;
level . cinematic = spawnflags & WORLD_CINEMATIC ;
if ( level . cinematic )
gi . cvar_set ( " sv_cinematic " , " 1 " ) ;
else
gi . cvar_set ( " sv_cinematic " , " 0 " ) ;
level . nextmap = " " ;
level . level_name = level . mapname ;
SoundMan . Load ( ) ;
// Set the color for the blends.
level . water_color = Vector ( 0 , 0 , 1 ) ;
level . water_alpha = 0.1f ;
level . lava_color = Vector ( 1.0f , 0.3f , 0 ) ;
level . lava_alpha = 0.6f ;
//
// set the targetname of the world
//
SetTargetName ( " world " ) ;
m_fNorth = 0 ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : UpdateConfigStrings ( void )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
//
// make some data visible to connecting client
//
gi . setConfigstring ( CS_GAME_VERSION , GAME_VERSION ) ;
gi . setConfigstring ( CS_LEVEL_START_TIME , va ( " %i " , level . svsStartTime ) ) ;
// make some data visible to the server
gi . setConfigstring ( CS_MESSAGE , level . level_name . c_str ( ) ) ;
2023-08-17 17:39:54 +02:00
} ;
void World : : UpdateFog ( void )
{
2023-08-28 20:22:06 +02:00
const char * fogInfoString ;
gi . SetFarPlane ( farplane_distance ) ;
if ( g_protocol > = protocol_e : : PROTOCOL_MOHTA_MIN ) {
fogInfoString = va (
" %d %.0f %.0f %.0f %.6f %.4f %.4f %.4f %d %.0f %.2f %.2f %.2f " ,
farplane_cull ,
farplane_distance ,
farplane_bias ,
skybox_farplane ,
skybox_speed ,
farplane_color . x ,
farplane_color . y ,
farplane_color . z ,
render_terrain ,
farclip_override ,
farplane_color_override . x ,
farplane_color_override . y ,
farplane_color_override . z
) ;
} else {
fogInfoString = va (
" %d %.0f %.4f %.4f %.4f " ,
farplane_cull ,
farplane_distance ,
farplane_color . x ,
farplane_color . y ,
farplane_color . z
) ;
}
gi . setConfigstring ( CS_FOGINFO , fogInfoString ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetFarClipOverride ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
farclip_override = ev - > GetFloat ( 1 ) ;
UpdateFog ( ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetFarPlaneColorOverride ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
farplane_color_override = ev - > GetVector ( 1 ) ;
UpdateFog ( ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
void World : : UpdateSky ( void )
{
2023-08-28 20:22:06 +02:00
gi . SetSkyPortal ( sky_portal ) ;
gi . setConfigstring ( CS_SKYINFO , va ( " %.4f %d " , sky_alpha , sky_portal ) ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
void World : : SetSoundtrack ( Event * ev )
{
2023-08-28 20:22:06 +02:00
const char * text ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
text = ev - > GetString ( 1 ) ;
ChangeSoundtrack ( text ) ;
2023-08-17 17:39:54 +02:00
}
void World : : SetGravity ( Event * ev )
{
2023-08-28 20:22:06 +02:00
gi . cvar_set ( " sv_gravity " , ev - > GetString ( 1 ) ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : GetFarPlane ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
ev - > AddFloat ( farplane_distance ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
void World : : SetFarPlane ( Event * ev )
{
2023-08-28 20:22:06 +02:00
animated_farplane_start_z = 8192 ;
if ( animated_farplane_start_z = = 8192
& & animated_farplane_bias_start_z = = 8192
& & animated_farplane_color_start_z = = 8192 ) {
CancelEventsOfType ( EV_World_UpdateAnimatedFarplane ) ;
}
farplane_distance = ev - > GetFloat ( 1 ) ;
UpdateFog ( ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : GetFarPlaneBias ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
ev - > AddFloat ( farplane_bias ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetFarPlaneBias ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
animated_farplane_bias_start_z = 8192 ;
if ( animated_farplane_start_z = = 8192
& & animated_farplane_bias_start_z = = 8192
& & animated_farplane_color_start_z = = 8192 ) {
CancelEventsOfType ( EV_World_UpdateAnimatedFarplane ) ;
}
farplane_bias = ev - > GetFloat ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : GetFarPlane_Color ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
ev - > AddVector ( farplane_color ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetFarPlane_Color ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
animated_farplane_color_start_z = 8192 ;
if ( animated_farplane_start_z = = 8192
& & animated_farplane_bias_start_z = = 8192
& & animated_farplane_color_start_z = = 8192 ) {
CancelEventsOfType ( EV_World_UpdateAnimatedFarplane ) ;
}
farplane_color = ev - > GetVector ( 1 ) ;
UpdateFog ( ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetFarPlane_Cull ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
farplane_cull = ev - > GetBoolean ( 1 ) ;
UpdateFog ( ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
void World : : GetSkyboxFarplane ( Event * ev )
{
2023-08-28 20:22:06 +02:00
ev - > AddFloat ( skybox_farplane ) ;
2023-08-17 17:39:54 +02:00
}
void World : : SetSkyboxFarplane ( Event * ev )
{
2023-08-28 20:22:06 +02:00
skybox_farplane = ev - > GetFloat ( 1 ) ;
2023-08-17 17:39:54 +02:00
}
void World : : SetAnimatedFarplaneColor ( Event * ev )
{
2023-08-28 20:22:06 +02:00
animated_farplane_color_start = ev - > GetVector ( 1 ) ;
animated_farplane_color_end = ev - > GetVector ( 2 ) ;
animated_farplane_color_start_z = ev - > GetFloat ( 3 ) ;
animated_farplane_color_end_z = ev - > GetFloat ( 4 ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
if ( animated_farplane_color_start_z > animated_farplane_color_end_z )
{
float end_z = animated_farplane_color_end_z ;
animated_farplane_color_end_z = animated_farplane_color_start_z ;
animated_farplane_color_start_z = end_z ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
Vector end = animated_farplane_color_end ;
animated_farplane_color_end = animated_farplane_color_start ;
animated_farplane_color_start = end ;
}
2016-03-27 11:49:47 +02:00
2023-08-28 20:22:06 +02:00
PostEvent ( EV_World_UpdateAnimatedFarplane , 0 ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
void World : : SetAnimatedFarplane ( Event * ev )
{
2023-08-28 20:22:06 +02:00
animated_farplane_start = ev - > GetFloat ( 1 ) ;
animated_farplane_end = ev - > GetFloat ( 2 ) ;
animated_farplane_start_z = ev - > GetFloat ( 3 ) ;
animated_farplane_end_z = ev - > GetFloat ( 4 ) ;
if ( animated_farplane_start_z > animated_farplane_end_z )
{
float end_z = animated_farplane_end_z ;
animated_farplane_end_z = animated_farplane_start_z ;
animated_farplane_start_z = end_z ;
float end = animated_farplane_end ;
animated_farplane_end = animated_farplane_start ;
animated_farplane_start = end ;
}
PostEvent ( EV_World_UpdateAnimatedFarplane , 0 ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
void World : : SetAnimatedFarplaneBias ( Event * ev )
{
2023-08-28 20:22:06 +02:00
animated_farplane_bias_start = ev - > GetFloat ( 1 ) ;
animated_farplane_bias_end = ev - > GetFloat ( 2 ) ;
animated_farplane_bias_start_z = ev - > GetFloat ( 3 ) ;
animated_farplane_bias_end_z = ev - > GetFloat ( 4 ) ;
if ( animated_farplane_bias_start_z > animated_farplane_bias_end_z )
{
float end_z = animated_farplane_bias_end_z ;
animated_farplane_bias_end_z = animated_farplane_bias_start_z ;
animated_farplane_bias_start_z = end_z ;
float end = animated_farplane_end ;
animated_farplane_bias_end = animated_farplane_bias_start ;
animated_farplane_bias_start = end ;
}
PostEvent ( EV_World_UpdateAnimatedFarplane , 0 ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
2023-08-17 17:39:54 +02:00
void World : : UpdateAnimatedFarplane ( Event * ev )
{
2023-08-28 20:22:06 +02:00
Entity * player ;
CancelEventsOfType ( EV_World_UpdateAnimatedFarplane ) ;
if ( g_gametype - > integer ! = GT_SINGLE_PLAYER ) {
return ;
}
PostEvent ( EV_World_UpdateAnimatedFarplane , level . frametime ) ;
player = g_entities [ 0 ] . entity ;
if ( ! player ) {
return ;
}
if ( animated_farplane_start_z ! = 8192 )
{
float alpha ;
if ( player - > origin . z < animated_farplane_start_z )
{
alpha = 0 ;
} else if ( player - > origin . z > animated_farplane_end_z ) {
alpha = 1 ;
} else {
alpha = ( player - > origin . z - animated_farplane_start_z ) / ( animated_farplane_end_z - animated_farplane_start_z ) ;
}
farplane_distance = alpha * ( animated_farplane_end - animated_farplane_start ) + animated_farplane_start ;
}
if ( animated_farplane_bias_start_z ! = 8192 )
{
float alpha ;
if ( player - > origin . z < animated_farplane_bias_start_z )
{
alpha = 0 ;
} else if ( player - > origin . z > animated_farplane_bias_end_z ) {
alpha = 1 ;
} else {
alpha = ( player - > origin . z - animated_farplane_bias_start_z ) / ( animated_farplane_bias_end_z - animated_farplane_bias_start_z ) ;
}
farplane_bias = alpha * ( animated_farplane_bias_end - animated_farplane_bias_start ) + animated_farplane_bias_start ;
}
if ( animated_farplane_color_start_z ! = 8192 )
{
float alpha , startAlpha , endAlpha ;
Vector start , end ;
float dot ;
if ( player - > origin . z < animated_farplane_color_start_z )
{
alpha = 0 ;
} else if ( player - > origin . z > animated_farplane_color_end_z ) {
alpha = 1 ;
} else {
alpha = ( player - > origin . z - animated_farplane_color_start_z ) / ( animated_farplane_color_end_z - animated_farplane_color_start_z ) ;
}
start = animated_farplane_color_start ;
end = animated_farplane_color_end ;
VectorNormalize ( start ) ;
VectorNormalize ( end ) ;
dot = Vector : : Dot ( start , end ) ;
if ( 1.f - dot > 0.000001 )
{
startAlpha = sin ( ( 1.f - alpha ) * acos ( dot ) ) / sin ( acos ( dot ) ) ;
endAlpha = sin ( acos ( dot ) * alpha ) / sin ( acos ( dot ) ) ;
}
else
{
startAlpha = 1.f - alpha ;
endAlpha = alpha ;
}
farplane_color = end * endAlpha + start * startAlpha ;
}
UpdateFog ( ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : GetRenderTerrain ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
ev - > AddInteger ( render_terrain ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetRenderTerrain ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
render_terrain = ev - > GetInteger ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : GetSkyboxSpeed ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
ev - > AddInteger ( skybox_speed ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetSkyboxSpeed ( Event * ev )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
skybox_speed = ev - > GetInteger ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetSkyAlpha ( Event * ev )
{
2023-08-28 20:22:06 +02:00
sky_alpha = ev - > GetFloat ( 1 ) ;
UpdateSky ( ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetSkyPortal ( Event * ev )
{
2023-08-28 20:22:06 +02:00
sky_portal = ev - > GetBoolean ( 1 ) ;
UpdateSky ( ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetNextMap ( Event * ev )
{
2023-08-28 20:22:06 +02:00
level . nextmap = ev - > GetString ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetMessage ( Event * ev )
{
2023-08-28 20:22:06 +02:00
const char * text ;
2016-03-27 11:49:47 +02:00
2023-08-28 20:22:06 +02:00
text = ev - > GetString ( 1 ) ;
level . level_name = text ;
gi . setConfigstring ( CS_MESSAGE , text ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetWaterColor ( Event * ev )
{
2023-08-28 20:22:06 +02:00
level . water_color = ev - > GetVector ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetWaterAlpha ( Event * ev )
{
2023-08-28 20:22:06 +02:00
level . water_alpha = ev - > GetFloat ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetLavaColor ( Event * ev )
{
2023-08-28 20:22:06 +02:00
level . lava_color = ev - > GetVector ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
void World : : SetLavaAlpha ( Event * ev )
{
2023-08-28 20:22:06 +02:00
level . lava_alpha = ev - > GetFloat ( 1 ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
void World : : SetNumArenas ( Event * ev )
{
2023-08-28 20:22:06 +02:00
level . m_numArenas = ev - > GetInteger ( 1 ) ;
2023-08-17 17:39:54 +02:00
}
void World : : SetAIVisionDistance ( Event * ev )
{
2023-08-28 20:22:06 +02:00
m_fAIVisionDistance = ev - > GetFloat ( 1 ) ;
2023-08-17 17:39:54 +02:00
}
2016-03-27 11:49:47 +02:00
void World : : SetNorthYaw ( Event * ev )
{
2023-08-28 20:22:06 +02:00
m_fNorth = anglemod ( ev - > GetFloat ( 1 ) ) ;
2016-03-27 11:49:47 +02:00
}
2023-08-17 17:39:54 +02:00
SimpleEntity * World : : GetTarget ( str targetname , bool quiet )
2023-05-22 23:27:40 +02:00
{
2023-08-28 20:22:06 +02:00
return GetTarget ( Director . AddString ( targetname ) , quiet ) ;
2023-08-17 17:39:54 +02:00
}
2023-05-22 23:27:40 +02:00
2023-08-17 17:39:54 +02:00
SimpleEntity * World : : GetTarget ( const_str targetname , bool quiet )
{
2023-08-28 20:22:06 +02:00
ConSimple * list = GetTargetList ( targetname ) ;
if ( list - > NumObjects ( ) = = 1 )
{
return list - > ObjectAt ( 1 ) ;
}
else if ( list - > NumObjects ( ) > 1 )
{
if ( ! quiet ) {
warning ( " World::GetTarget " , " There are %d entities with targetname '%s'. You are using a command that requires exactly one. " , list - > NumObjects ( ) , Director . GetString ( targetname ) . c_str ( ) ) ;
}
}
return NULL ;
2023-07-02 18:31:58 +02:00
}
2023-05-22 23:27:40 +02:00
2023-08-17 17:39:54 +02:00
SimpleEntity * World : : GetScriptTarget ( str targetname )
2016-03-27 11:49:47 +02:00
{
2023-08-28 20:22:06 +02:00
return GetScriptTarget ( Director . AddString ( targetname ) ) ;
2023-08-17 17:39:54 +02:00
}
SimpleEntity * World : : GetScriptTarget ( const_str targetname )
{
2023-08-28 20:22:06 +02:00
ConSimple * list = GetTargetList ( targetname ) ;
if ( list - > NumObjects ( ) = = 1 )
{
return list - > ObjectAt ( 1 ) ;
}
else if ( list - > NumObjects ( ) > 1 )
{
ScriptError ( " There are %d entities with targetname '%s'. You are using a command that requires exactly one. " , list - > NumObjects ( ) , Director . GetString ( targetname ) . c_str ( ) ) ;
}
return NULL ;
2023-08-17 17:39:54 +02:00
}
ConSimple * World : : GetExistingTargetList ( const str & targetname )
{
2023-08-28 20:22:06 +02:00
return GetExistingTargetList ( Director . AddString ( targetname ) ) ;
2023-08-17 17:39:54 +02:00
}
ConSimple * World : : GetExistingTargetList ( const_str targetname )
{
2023-08-28 20:22:06 +02:00
return m_targetList . findKeyValue ( targetname ) ;
2023-08-17 17:39:54 +02:00
}
ConSimple * World : : GetTargetList ( str & targetname )
{
2023-08-28 20:22:06 +02:00
return GetTargetList ( Director . AddString ( targetname ) ) ;
2023-08-17 17:39:54 +02:00
}
ConSimple * World : : GetTargetList ( const_str targetname )
{
2023-08-28 20:22:06 +02:00
return & m_targetList . addKeyValue ( targetname ) ;
2023-08-17 17:39:54 +02:00
}
void World : : AddTargetEntity ( SimpleEntity * ent )
{
2023-08-28 20:22:06 +02:00
str targetname = ent - > TargetName ( ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
if ( ! targetname . length ( ) )
{
return ;
}
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
ConSimple * list = GetTargetList ( targetname ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
list - > AddObject ( ent ) ;
2023-08-17 17:39:54 +02:00
}
void World : : AddTargetEntityAt ( SimpleEntity * ent , int index )
{
2023-08-28 20:22:06 +02:00
str targetname = ent - > TargetName ( ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
if ( ! targetname . length ( ) )
{
return ;
}
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
ConSimple * list = GetTargetList ( targetname ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
list - > AddObjectAt ( index , ent ) ;
2023-08-17 17:39:54 +02:00
}
int World : : GetTargetnameIndex ( SimpleEntity * ent )
{
2023-08-28 20:22:06 +02:00
ConSimple * list = GetTargetList ( ent - > TargetName ( ) ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
return list - > IndexOfObject ( ent ) ;
2023-08-17 17:39:54 +02:00
}
void World : : RemoveTargetEntity ( SimpleEntity * ent )
{
2023-08-28 20:22:06 +02:00
if ( world - > world_dying ) {
return ;
}
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
const str targetname = ent - > TargetName ( ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
if ( ! targetname . length ( ) )
{
return ;
}
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
ConSimple * list = GetExistingTargetList ( targetname ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
if ( list )
{
list - > RemoveObject ( ent ) ;
2023-08-17 17:39:54 +02:00
2023-08-28 20:22:06 +02:00
if ( list - > NumObjects ( ) < = 0 )
{
m_targetList . remove ( Director . AddString ( targetname ) ) ;
}
}
2023-08-17 17:39:54 +02:00
}
SimpleEntity * World : : GetNextEntity ( str targetname , SimpleEntity * ent )
{
2023-08-28 20:22:06 +02:00
return GetNextEntity ( Director . AddString ( targetname ) , ent ) ;
2023-08-17 17:39:54 +02:00
}
SimpleEntity * World : : GetNextEntity ( const_str targetname , SimpleEntity * ent )
{
2023-08-28 20:22:06 +02:00
ConSimple * list = GetTargetList ( targetname ) ;
int index ;
if ( ent )
{
index = list - > IndexOfObject ( ent ) + 1 ;
}
else
{
index = 1 ;
}
if ( list - > NumObjects ( ) > = index )
{
return list - > ObjectAt ( index ) ;
}
else
{
return NULL ;
}
2023-08-17 17:39:54 +02:00
}
void World : : FreeTargetList ( )
{
2023-08-28 20:22:06 +02:00
m_targetList . clear ( ) ;
2023-08-17 17:39:54 +02:00
}