aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/_objective.gnut
blob: 893861bf0dc11697b6a6b7317472ed941694ba3e (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
untyped

global function Objective_Init

global function RegisterObjective
global function SetCurrentTeamObjectiveForPlayer
global function SetTeamActiveObjective
global function ClearTeamActiveObjective

global function SetPlayerActiveObjective
global function ClearPlayerActiveObjective

int convIndex = 0 //Note that objectiveIndex 0 is reserved by code to mean no objective active!

//Split this out into _objective_shared, _objective and cl_objective once QA gets a chance to hammer at it.
function Objective_Init()
{
	level.objToIndex <- {}
	level.teamActiveObjective <- { [TEAM_IMC] = null, [TEAM_MILITIA] = null }

}

function RegisterObjective( objectiveName )
{
	convIndex++
	level.objToIndex[ objectiveName ] <- convIndex
}

function CreateTeamActiveObjectiveTable( objectiveName, objectiveTimer = 0, objectiveEntity = null )
{
	local Table = {}
	Table.objectiveName <- objectiveName
	Table.objectiveTimer <- objectiveTimer
	Table.objectiveEntity <- objectiveEntity

	return Table
}

function SetCurrentTeamObjectiveForPlayer( entity player )
{
	int team = player.GetTeam()
	local objectiveTable = GetTeamActiveObjective( team )

	if ( objectiveTable )
	{
		local objectiveName = objectiveTable.objectiveName
		local objectiveTimer = objectiveTable.objectiveTimer
		local objectiveEntity = objectiveTable.objectiveEntity
		SetPlayerActiveObjective( player, objectiveName, objectiveTimer, objectiveEntity )
	}
}

function GetTeamActiveObjective( team )
{
	if ( (team != TEAM_IMC) && (team != TEAM_MILITIA) )
		return null
	return level.teamActiveObjective[team]
}

function SetTeamActiveObjective( team, objectiveName, objectiveTimer = 0, objectiveEntity = null )
{
	Assert( team == TEAM_IMC || team == TEAM_MILITIA )
	array<entity> players = GetPlayerArrayOfTeam( team )

	local objectiveIndex = level.objToIndex[ objectiveName ]

	foreach ( player in players )
	{
		SetPlayerActiveObjective_Internal( player, objectiveIndex, objectiveTimer, objectiveEntity )
	}

	level.teamActiveObjective[ team ] = CreateTeamActiveObjectiveTable( objectiveName, objectiveTimer, objectiveEntity )
}

function ClearTeamActiveObjective( team )
{
	Assert( team == TEAM_IMC || team == TEAM_MILITIA )
	array<entity> players = GetPlayerArrayOfTeam( team )
	foreach ( player in players )
	{
		ClearPlayerActiveObjective( player )
	}

	level.teamActiveObjective[ team ] = null

}

function SetPlayerActiveObjective( player, objectiveName, objectiveTimer = 0, objectiveEntity = null )
{
	local objectiveIndex = level.objToIndex[ objectiveName ]

	SetPlayerActiveObjective_Internal( player, objectiveIndex, objectiveTimer, objectiveEntity )
}

function SetPlayerActiveObjective_Internal( player, objectiveIndex, objectiveTimer, objectiveEntity  )
{
	player.SetObjectiveEndTime( objectiveTimer )
	player.SetObjectiveEntity( objectiveEntity )
	player.SetObjectiveIndex( objectiveIndex )
}

function ClearPlayerActiveObjective( player )
{
	player.SetObjectiveEndTime( 0 )
	player.SetObjectiveEntity( null )
	player.SetObjectiveIndex( 0 )
}