aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/mod/scripts/vscripts/_objective.gnut
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-31 23:14:58 +0100
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-08-31 23:14:58 +0100
commit9a96d0bff56f1969c68bb52a2f33296095bdc67d (patch)
tree4175928e488632705692e3cccafa1a38dd854615 /Northstar.CustomServers/mod/scripts/vscripts/_objective.gnut
parent27bd240871b7c0f2f49fef137718b2e3c208e3b4 (diff)
downloadNorthstarMods-9a96d0bff56f1969c68bb52a2f33296095bdc67d.tar.gz
NorthstarMods-9a96d0bff56f1969c68bb52a2f33296095bdc67d.zip
move to new mod format
Diffstat (limited to 'Northstar.CustomServers/mod/scripts/vscripts/_objective.gnut')
-rw-r--r--Northstar.CustomServers/mod/scripts/vscripts/_objective.gnut108
1 files changed, 108 insertions, 0 deletions
diff --git a/Northstar.CustomServers/mod/scripts/vscripts/_objective.gnut b/Northstar.CustomServers/mod/scripts/vscripts/_objective.gnut
new file mode 100644
index 00000000..893861bf
--- /dev/null
+++ b/Northstar.CustomServers/mod/scripts/vscripts/_objective.gnut
@@ -0,0 +1,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 )
+}
+