aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/gamemodes/_riff_floor_is_lava.nut
blob: 99f5139673cd484745ce622d487d2f333ccb5ade (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
global function RiffFloorIsLava_Init

void function RiffFloorIsLava_Init()
{
	AddCallback_OnPlayerRespawned( FloorIsLava_PlayerRespawned )
	
	AddSpawnCallback( "env_fog_controller", InitLavaFogController )
	AddCallback_EntitiesDidLoad( CreateCustomSpawns )
	AddSpawnpointValidationRule( VerifyFloorIsLavaSpawnpoint )
}

bool function VerifyFloorIsLavaSpawnpoint( entity spawnpoint, int team )
{
	return spawnpoint.GetOrigin().z > GetLethalFogTop()
}

void function InitLavaFogController( entity fogController )
{
	fogController.kv.fogztop = GetVisibleFogTop()
	fogController.kv.fogzbottom = GetVisibleFogBottom()
	fogController.kv.foghalfdisttop = "60000"
	fogController.kv.foghalfdistbottom = "200"
	fogController.kv.fogdistoffset = "0"
	fogController.kv.fogdensity = ".85"

	fogController.kv.forceontosky = true
	//fogController.kv.foghalfdisttop = "10000"
}

void function CreateCustomSpawns()
{
	thread CreateCustomSpawns_Threaded()
}

void function CreateCustomSpawns_Threaded()
{
	WaitEndFrame() // wait for spawns to clear
	
	float raycastTop = GetLethalFogTop() + 2500.0
	array< vector > raycastPositions
	foreach ( entity hardpoint in GetEntArrayByClass_Expensive( "info_hardpoint" ) )
	{
		if ( !hardpoint.HasKey( "hardpointGroup" ) )
			continue
			
		//if ( hardpoint.kv.hardpointGroup != "A" && hardpoint.kv.hardpointGroup != "B" && hardpoint.kv.hardpointGroup != "C" )
		if ( hardpoint.kv.hardpointGroup != "B" ) // roughly map center
			continue
			
		vector pos = hardpoint.GetOrigin()
		for ( int x = -2000; x < 2000; x += 200 )
			for ( int y = -2000; y < 2000; y += 200 )
				raycastPositions.append( < x, y, raycastTop > )
	}
	
	int validSpawnsCreated = 0
	foreach ( vector raycastPos in raycastPositions )
	{
		//vector hardpoint = validHardpoints[ RandomInt( validHardpoints.len() ) ].GetOrigin()
		//float a = RandomFloat( 1 ) * 2 * PI
		//float r = 1000.0 * sqrt( RandomFloat( 1 ) )
		//
		//vector castStart = < hardpoint.x + r * cos( a ), hardpoint.y + r * sin( a ),  >
		//vector castEnd = < hardpoint.x + r * cos( a ), hardpoint.y + r * sin( a ), GetLethalFogBottom() >
		
		TraceResults trace = TraceLine( raycastPos, < raycastPos.x, raycastPos.y, GetLethalFogBottom() >, [], TRACE_MASK_SOLID, TRACE_COLLISION_GROUP_NONE ) // should only hit world
		print( "raycast: " + trace.endPos )
		if ( trace.endPos.z >= GetLethalFogTop() )
		{
			print( "creating floor is lava spawn at " + trace.endPos )
			validSpawnsCreated++
		
			// valid spot, create a spawn
			entity spawnpoint = CreateEntity( "info_spawnpoint_human" )
			spawnpoint.SetOrigin( trace.endPos )
			spawnpoint.kv.ignoreGamemode = 1
			DispatchSpawn( spawnpoint )
		}
	}
}

void function FloorIsLava_PlayerRespawned( entity player )
{
	thread FloorIsLava_ThinkForPlayer( player )
}

void function FloorIsLava_ThinkForPlayer( entity player )
{
	player.EndSignal( "OnDestroy" )
	player.EndSignal( "OnDeath" )
	
	float lastHeight
	
	while ( true )
	{
		WaitFrame()
		
		float height = player.GetOrigin().z
		if ( height < GetLethalFogTop() )
		{
			// do damage
			float damageMultiplier
			if ( player.IsTitan() )
				damageMultiplier = 0.0025
			else
				damageMultiplier = 0.05
				
			// scale damage by time spent in fog and depth
			player.TakeDamage( player.GetMaxHealth() * GraphCapped( ( GetLethalFogTop() - height ) / ( GetLethalFogTop() - GetLethalFogBottom() ), 0.0, 1.0, 0.2, 1.0 ) * damageMultiplier, null, null, { damageSourceId = eDamageSourceId.floor_is_lava } )
		
			wait 0.1
		}
		
		lastHeight = height
	}
}