aboutsummaryrefslogtreecommitdiff
path: root/Northstar.CustomServers/scripts/vscripts/sh_calling_cards.gnut
blob: 6746194573445988fbdfb59f09bba3dc0c00cc3d (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
global function ShCallingCards_Init

global function PlayerCallingCard_GetActive
global function PlayerCallingCard_GetActiveIndex

global function CallingCard_GetRef
global function CallingCard_GetImage
global function CallingCards_GetCount
global function CallingCard_GetByIndex
global function CallingCard_GetByRef

global function PlayerCallsignIcon_GetActive
global function PlayerCallsignIcon_GetActiveIndex

global function CallsignIcon_GetRef
global function CallsignIcon_GetImage
global function CallingCard_GetLayout
global function CallsignIcon_GetSmallImage
global function CallsignIcons_GetCount
global function CallsignIcon_GetByIndex
global function CallsignIcon_GetByRef

global function PlayerCallingCard_RefOverride

#if SERVER
	global function PlayerCallsignIcon_SetActive
	global function PlayerCallingCard_SetActiveByRef
	global function PlayerCallsignIcon_SetActiveByRef
#endif

global struct CallingCard
{
	int index = -1
	string ref = ""
	asset image = $""
	int layoutType = 0
}

global struct CallsignIcon
{
	int index = -1
	string ref = ""
	asset image = $""
	asset smallImage = $""
	int layoutType = 0
}

struct
{
	table<string, CallingCard> callingCards
	array<string> callingCardRefs

	table<string, CallsignIcon> callsignIcons
	array<string> callsignIconRefs

	int nextCallingCardIndex = 0
	int nextCallsignIconIndex = 0
} file

void function ShCallingCards_Init()
{
	bool initialized = ( file.callingCardRefs.len() > 0 )

	if ( !initialized )
	{
		var dataTable = GetDataTable( $"datatable/calling_cards.rpak" )
		for ( int row = 0; row < GetDatatableRowCount( dataTable ); row++ )
		{
			string cardRef = GetDataTableString( dataTable, row, GetDataTableColumnByName( dataTable, CALLING_CARD_REF_COLUMN_NAME ) )
			asset image = GetDataTableAsset( dataTable, row, GetDataTableColumnByName( dataTable, CALLING_CARD_IMAGE_COLUMN_NAME ) )
			int layoutType = GetDataTableInt( dataTable, row, GetDataTableColumnByName( dataTable, CALLING_CARD_LAYOUT_COLUMN_NAME ) )

			CallingCard callingCard
			callingCard.ref = cardRef
			callingCard.image = image
			callingCard.index = row
			callingCard.layoutType = layoutType

			file.callingCards[cardRef] <- callingCard
			file.callingCardRefs.append( cardRef )
		}
	}

	if ( !initialized )
	{
		var dataTable = GetDataTable( $"datatable/callsign_icons.rpak" )
		for ( int row = 0; row < GetDatatableRowCount( dataTable ); row++ )
		{
			string iconRef = GetDataTableString( dataTable, row, GetDataTableColumnByName( dataTable, CALLSIGN_ICON_REF_COLUMN_NAME ) )
			asset image = GetDataTableAsset( dataTable, row, GetDataTableColumnByName( dataTable, CALLSIGN_ICON_IMAGE_COLUMN_NAME ) )
			asset smallImage = GetDataTableAsset( dataTable, row, GetDataTableColumnByName( dataTable, CALLSIGN_ICON_SMALL_IMAGE_COLUMN_NAME ) )

			CallsignIcon callsignIcon
			callsignIcon.ref = iconRef
			callsignIcon.image = image
			callsignIcon.smallImage = smallImage
			callsignIcon.index = row

			file.callsignIcons[iconRef] <- callsignIcon
			file.callsignIconRefs.append( iconRef )
		}
	}

	#if SERVER
	AddCallback_OnClientConnecting( OnClientConnecting )
	AddCallback_OnTitanBecomesPilot( OnClassChangeBecomePilot )
	AddCallback_OnPilotBecomesTitan( OnClassChangeBecomeTitan )
	#endif
}

#if SERVER
void function OnClientConnecting( entity player )
{
	// hack - don't do this because pdefs aren't fully working
	
	// initialize the persistent network vars
	// string ref = CallingCard_GetRef( PlayerCallingCard_GetActive( player ) )
	// PlayerCallingCard_SetActiveByRef( player, ref )
	// 
	// CallsignIcon callsignIcon = PlayerCallsignIcon_GetActive( player )
	// 
	// PlayerCallsignIcon_SetActive( player, callsignIcon )
	// player.SetTargetInfoIcon( callsignIcon.smallImage )
}
#endif

#if DEV
CallingCard function DEV_GetNextCallingCard()
{
	int index = file.nextCallingCardIndex
	printt( "using CallingCard index", index )
	file.nextCallingCardIndex++
	file.nextCallingCardIndex = file.nextCallingCardIndex % file.callingCardRefs.len()

	string ref = file.callingCardRefs[index]
	return file.callingCards[ref]
}

CallsignIcon function DEV_GetNextCallsignIcon()
{
	int index = file.nextCallsignIconIndex
	printt( "using CallsignIcon index", index )
	file.nextCallsignIconIndex++
	file.nextCallsignIconIndex = file.nextCallsignIconIndex % file.callsignIconRefs.len()

	string ref = file.callsignIconRefs[index]
	return file.callsignIcons[ref]
}
#endif

int function PlayerCallingCard_GetActiveIndex( entity player )
{
	#if CLIENT
		int index
		if ( player != GetLocalClientPlayer() )
			index = player.GetPlayerNetInt( "activeCallingCardIndex" )
		else
			index = player.GetPersistentVarAsInt( "activeCallingCardIndex" )
	#else
		int index = player.GetPersistentVarAsInt( "activeCallingCardIndex" )
	#endif
	return index
}

CallingCard function PlayerCallingCard_GetActive( entity player )
{
	int index = PlayerCallingCard_GetActiveIndex( player )
	string ref = file.callingCardRefs[index]
	#if CLIENT || UI
		ref = PlayerCallingCard_RefOverride( player, ref )
	#endif
	return file.callingCards[ref]
}

string function CallingCard_GetRef( CallingCard callingCard )
{
	return callingCard.ref
}

asset function CallingCard_GetImage( CallingCard callingCard )
{
	return callingCard.image
}

int function CallingCard_GetLayout( CallingCard callingCard )
{
	return callingCard.layoutType
}

int function CallingCards_GetCount()
{
	return file.callingCards.len()
}

CallingCard function CallingCard_GetByIndex( int index )
{
	// JFS: handle players with invalid indices
	//Assert( index < CallingCards_GetCount() )
	if ( index >= file.callingCards.len() )
		return file.callingCards["callsign_16_col"]

	return file.callingCards[file.callingCardRefs[index]]
}

CallingCard function CallingCard_GetByRef( string ref )
{
	return file.callingCards[ref]
}


int function PlayerCallsignIcon_GetActiveIndex( entity player )
{
	#if CLIENT
		int index
		if ( player != GetLocalClientPlayer() )
			index = player.GetPlayerNetInt( "activeCallsignIconIndex" )
		else
			index = player.GetPersistentVarAsInt( "activeCallsignIconIndex" )
	#else
		int index = player.GetPersistentVarAsInt( "activeCallsignIconIndex" )
	#endif
	return index
}

CallsignIcon function PlayerCallsignIcon_GetActive( entity player )
{
	int index = PlayerCallsignIcon_GetActiveIndex( player )
	string ref = file.callsignIconRefs[index]
	return file.callsignIcons[ref]
}

string function CallsignIcon_GetRef( CallsignIcon callsignIcon )
{
	return callsignIcon.ref
}

asset function CallsignIcon_GetImage( CallsignIcon callsignIcon )
{
	return callsignIcon.image
}

asset function CallsignIcon_GetSmallImage( CallsignIcon callsignIcon )
{
	return callsignIcon.smallImage
}

int function CallsignIcons_GetCount()
{
	return file.callsignIcons.len()
}

CallsignIcon function CallsignIcon_GetByIndex( int index )
{
	// JFS: handle players with invalid indices
	// Assert( index < CallsignIcons_GetCount() )

	if ( index >= file.callsignIconRefs.len() )
		index = 0

	return file.callsignIcons[file.callsignIconRefs[index]]
}

CallsignIcon function CallsignIcon_GetByRef( string ref )
{
	return file.callsignIcons[ref]
}


const table< string, string > dynamicCardRefMap = {
	callsign_fd_ion_dynamic = "ion",
	callsign_fd_tone_dynamic = "tone",
	callsign_fd_scorch_dynamic = "scorch",
	callsign_fd_legion_dynamic = "legion",
	callsign_fd_northstar_dynamic = "northstar",
	callsign_fd_ronin_dynamic = "ronin",
	callsign_fd_monarch_dynamic = "vanguard",
}

const table< string, array<string> > dynamicCardMap = {
	callsign_fd_ion_dynamic =
	[
		"callsign_fd_ion_dynamic",
		"callsign_fd_ion_dynamic",
		"callsign_fd_ion_hard",
		"callsign_fd_ion_master",
		"callsign_fd_ion_insane",
	],

	callsign_fd_tone_dynamic =
	[
		"callsign_fd_tone_dynamic",
		"callsign_fd_tone_dynamic",
		"callsign_fd_tone_hard",
		"callsign_fd_tone_master",
		"callsign_fd_tone_insane",
	],

	callsign_fd_scorch_dynamic =
	[
		"callsign_fd_scorch_dynamic",
		"callsign_fd_scorch_dynamic",
		"callsign_fd_scorch_hard",
		"callsign_fd_scorch_master",
		"callsign_fd_scorch_insane",
	],

	callsign_fd_legion_dynamic =
	[
		"callsign_fd_legion_dynamic",
		"callsign_fd_legion_dynamic",
		"callsign_fd_legion_hard",
		"callsign_fd_legion_master",
		"callsign_fd_legion_insane",
	],

	callsign_fd_northstar_dynamic =
	[
		"callsign_fd_northstar_dynamic",
		"callsign_fd_northstar_dynamic",
		"callsign_fd_northstar_hard",
		"callsign_fd_northstar_master",
		"callsign_fd_northstar_insane",
	],

	callsign_fd_ronin_dynamic =
	[
		"callsign_fd_ronin_dynamic",
		"callsign_fd_ronin_dynamic",
		"callsign_fd_ronin_hard",
		"callsign_fd_ronin_master",
		"callsign_fd_ronin_insane",
	],

	callsign_fd_monarch_dynamic =
	[
		"callsign_fd_monarch_dynamic",
		"callsign_fd_monarch_dynamic",
		"callsign_fd_monarch_hard",
		"callsign_fd_monarch_master",
		"callsign_fd_monarch_insane",
	],
}

string function PlayerCallingCard_RefOverride( entity player, string ref )
{
	const string CARD_DYNAMIC = "_dynamic"

	if ( ref.find( CARD_DYNAMIC ) == null )
		return ref

	if ( ref.find( CARD_DYNAMIC ) != ref.len() - CARD_DYNAMIC.len() )
		return ref

	if ( ref in dynamicCardRefMap )
	{
		string titanRef = dynamicCardRefMap[ref]
		int highestDifficulty = FD_GetHighestDifficultyForTitan( player, titanRef )

		return dynamicCardMap[ref][minint( highestDifficulty, dynamicCardMap[ref].len() - 1 )]
	}

	return ref
}

#if SERVER
/*
InitUnlockAsEntitlement( "callsign_fd_ion_dynamic", "", ET_DLC7_ION_WARPAINT )
InitUnlockAsEntitlement( "callsign_fd_tone_dynamic", "", ET_DLC7_TONE_WARPAINT )
InitUnlockAsEntitlement( "callsign_fd_scorch_dynamic", "", ET_DLC7_SCORCH_WARPAINT )
InitUnlockAsEntitlement( "callsign_fd_legion_dynamic", "", ET_DLC7_LEGION_WARPAINT )
InitUnlockAsEntitlement( "callsign_fd_northstar_dynamic", "", ET_DLC7_NORTHSTAR_WARPAINT )
InitUnlockAsEntitlement( "callsign_fd_ronin_dynamic", "", ET_DLC7_RONIN_WARPAINT )
InitUnlockAsEntitlement( "callsign_fd_monarch_dynamic", "", ET_DLC7_MONARCH_WARPAINT )
*/

void function PlayerCallingCard_SetActiveByIndex( entity player, int index )
{
//	if ( player.GetPersistentVarAsInt( "activeCallingCardIndex" ) != index )
	player.SetCallingCard( index )

	player.SetPlayerNetInt( "activeCallingCardIndex", index )
	player.SetPersistentVar( "activeCallingCardIndex", index )
}

void function PlayerCallingCard_SetActiveByRef( entity player, string ref )
{
	PlayerCallingCard_SetActiveByIndex( player, file.callingCards[ref].index )

	if ( PlayerCallingCard_RefOverride( player, ref ) != ref )
		player.SetCallingCard( file.callingCards[PlayerCallingCard_RefOverride( player, ref )].index )
}

void function PlayerCallsignIcon_SetActiveByIndex( entity player, int index )
{
//	if ( player.GetPersistentVarAsInt( "activeCallsignIconIndex" ) != index )
		player.SetCallSign( index )

	player.SetPlayerNetInt( "activeCallsignIconIndex", index )
	player.SetPersistentVar( "activeCallsignIconIndex", index )
}

void function PlayerCallsignIcon_SetActive( entity player, CallsignIcon callsignIcon )
{
	PlayerCallsignIcon_SetActiveByIndex( player, callsignIcon.index )
}

void function PlayerCallsignIcon_SetActiveByRef( entity player, string ref )
{
	PlayerCallsignIcon_SetActiveByIndex( player, file.callsignIcons[ref].index )
}

void function OnClassChangeBecomePilot( entity player, entity titan )
{
	CallsignIcon callsignIcon = PlayerCallsignIcon_GetActive( player )
	player.SetTargetInfoIcon( callsignIcon.smallImage )
}

void function OnClassChangeBecomeTitan( entity player, entity titan )
{
	string titanRef = GetTitanCharacterNameFromSetFile( player.GetPlayerSettings() )
	player.SetTargetInfoIcon( GetTitanCoreIcon( titanRef ) )
}

#endif