1 // Property of Alientrap/AK
2 // custom/creategame/maps.qc
12 Item_Nex_Map_Info_Destroy
15 void() Item_Nex_Map_Info_Destroy =
17 String_EntityFree( self, link );
18 String_EntityFree( self, picture );
19 String_EntityFree( self, text );
20 String_EntityFree( self, normal );
25 Item_Nex_Map_Info_Spawn
28 void() Item_Nex_Map_Info_Spawn =
30 String_EntityZone( self, link );
31 String_EntityZone( self, picture );
32 String_EntityZone( self, text );
33 String_EntityZone( self, normal );
35 Gfx_Precache( self.picture );
37 self._destroy = Item_Nex_Map_Info_Destroy;
45 string _Nex_MapList_FullPath;
46 string _Nex_MapList_Name;
47 entity _Nex_MapList_Root;
51 Item_Nex_MapDB_EnumFiles
54 // map definition format
56 // rest: description text
57 void() Item_Nex_MapDB_EnumFiles =
59 local float lSearchHandle;
60 local float lSearchSize;
61 local float lSearchCounter;
64 lSearchHandle = search_begin( "maps/*.bsp", true, true );
65 if( lSearchHandle < 0 )
67 for( lSearchSize = search_getsize( lSearchHandle ), lSearchCounter = 0;
68 lSearchCounter < lSearchSize; ++lSearchCounter ) {
71 local string lFilename;
72 local string lStripped;
74 local string lDescription;
77 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
78 lStripped = String_Zone( substring( lFilename, 0, strlen( lFilename ) - 4 ) );
79 lName = String_Zone( substring( lStripped, 5, 100000 ) );
81 lHandle = fopen( strcat( lStripped, ".txt" ), FILE_READ );
83 lTitle = String_Zone( lName );
84 lDescription = String_Zone( strcat( "--NO INFORMATION AVAILABLE--\n", lFilename ) );
86 // uncomment this line and comment the other if you have the old map info files
87 //lTitle = String_Zone( lName );
88 lTitle = String_Zone( fgets( lHandle ) );
90 lDescription = String_Create();
94 lLine = fgets( lHandle );
95 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
96 } while( validstring( lLine ) );
101 // save this in a new Map_Info
102 lMap = Menu_CreateItem( "Item_Nex_Map_Info", ftos( lSearchCounter ), self.name );
106 if( Gfx_Precache( lStripped ) ) {
107 lMap.picture = lStripped;
109 lMap.picture = "gfx/m_nomap";
111 lMap.normal = lTitle;
112 lMap.text = lDescription;
114 _Nex_MapList_FullPath = Util_AltStringPushBack( _Nex_MapList_FullPath, lName );
115 _Nex_MapList_Name = Util_AltStringPushBack( _Nex_MapList_Name, lTitle );
117 Menu_LinkItem( lMap );
119 String_Free( lTitle );
120 String_Free( lName );
121 String_Free( lStripped );
122 String_Free( lDescription );
125 search_end( lSearchHandle );
127 Menu_LinkChildren( self );
131 self.maxValue = fabs( lMap.orderPos );
136 Item_Nex_MapDB_Destroy
139 void() Item_Nex_MapDB_Destroy =
141 String_Free( _Nex_MapList_FullPath );
142 String_Free( _Nex_MapList_Name );
144 _Nex_MapList_Root = null_entity;
152 void() Item_Nex_MapDB_Spawn =
154 if( _Nex_MapList_Root )
155 error( "There is already another Item_Nex_MapDB object!" );
157 _Nex_MapList_FullPath = String_Create();
158 _Nex_MapList_Name = String_Create();
159 _Nex_MapList_Root = self;
161 Item_Nex_MapDB_EnumFiles();
163 self._destroy = Item_Nex_MapDB_Destroy;
171 entity( string pPath ) Nex_MapDB_GetByPath =
175 if( !_Nex_MapList_Root )
176 error( "No Item_Nex_MapDB found!" );
178 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
179 if( lNode.link == pPath ) {
192 entity( float pIndex ) Nex_MapDB_GetByIndex =
196 if( !_Nex_MapList_Root )
197 error( "No Item_Nex_MapDB found!" );
199 pIndex = fabs( pIndex );
200 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
201 if( fabs( lNode.orderPos ) == pIndex ) {
211 Nex_MapDB_GetPathAltString
214 string() Nex_MapDB_GetPathAltString =
216 return _Nex_MapList_FullPath;
221 Nex_MapDB_GetNameAltString
224 string() Nex_MapDB_GetNameAltString =
226 return _Nex_MapList_Name;
234 float( entity pItem ) Nex_MapDB_GetIndex =
236 return fabs( pItem.orderPos );
239 void() Item_DataLink_Nex_MapList_Save =
243 local string lOutput;
245 lOutput = String_Create();
247 lCount = Util_GetAltStringCount( self.valueList );
248 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
249 lOutput = String_Append( lOutput, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
252 cvar_set( self.cvarName, lOutput );
253 cvar_set( strcat( self.cvarName, "_index" ), "0" );
255 String_Free( lOutput );
258 void() Item_DataLink_Nex_MapList_Load =
261 local entity lMapInfo;
262 local float lCounter;
265 DataLink_Nex_MapList_Clear( self );
267 lCount = tokenize( cvar_string( self.cvarName ) );
269 lEntry = String_Create();
270 for( lCounter = 0 ; lCounter < lCount ; lCounter++ ) {
271 lEntry = String_Set( lEntry, argv( lCounter ) );
273 lMapInfo = Nex_MapDB_GetByPath( lEntry );
274 if( lMapInfo == null_entity ) {
275 print( self.cvarName, ": Map '", lEntry, "' not found in database - ignored\n" );
279 self.descList = Util_AltStringPushBack( self.descList, lMapInfo.normal );
280 self.valueList = Util_AltStringPushBack( self.valueList, lMapInfo.link );
282 String_Free( lEntry );
284 DataLink_Nex_MapList_UpdateRange( self );
285 Nex_MapSelector_Synchronize();
288 void() Item_DataLink_Nex_MapList_ExecString =
293 Data_ExecString = String_Append( Data_ExecString, strcat( "set \"", self.cvarName, "_index\" \"0\"\nset \"", self.cvarName, "\" \"" ) );
295 lCount = Util_GetAltStringCount( self.valueList );
296 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
297 Data_ExecString = String_Append( Data_ExecString, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
300 Data_ExecString = String_Append( Data_ExecString, "\"\n" );
305 Item_DataLink_Nex_MapList_DataEvent
308 void( float pEvent ) Item_DataLink_Nex_MapList_DataEvent =
312 if( self.cvarName != "" ) {
313 Item_DataLink_Nex_MapList_Load();
317 if( self.cvarName != "" ) {
318 Item_DataLink_Nex_MapList_Save();
321 case ITEM_DATA_RESET:
322 self._realValue = 1.0;
324 case ITEM_DATA_TEST_START:
326 case ITEM_DATA_TEST_END:
328 case ITEM_DATA_SAVE_EXECSTRING:
329 if( self.cvarName != "" ) {
330 Item_DataLink_Nex_MapList_ExecString();
333 case ITEM_DATALINK_SET:
334 case ITEM_DATALINK_GET:
335 self._realValue = floor( self._realValue );
336 if( self._realValue < 1.0 ) {
337 self._realValue = 1.0;
338 } else if( self._realValue > self.maxValue ) {
339 self._realValue = self.maxValue;
346 void() IDLNML_Reinit =
348 Raise_DataEvent( self, ITEM_DATA_SYNC );
353 Item_DataLink_Nex_MapList_Destroy
356 void() Item_DataLink_Nex_MapList_Destroy =
358 String_EntityFree( self, valueList );
359 String_EntityFree( self, cvarName );
361 Item_DataLink_Switch_Destroy();
366 Item_DataLink_Nex_MapList_Spawn
369 void() Item_DataLink_Nex_MapList_Spawn =
371 Item_DataLink_Switch_Init();
372 String_EntityZone( self, valueList );
373 String_EntityZone( self, cvarName );
375 if( self.cvarName != "" ) {
376 registercvar( self.cvarName, "", CVAR_SAVE );
377 registercvar( strcat( self.cvarName, "_index" ), "", CVAR_SAVE );
382 self.stepValue = 0.0;
384 self._reinit = IDLNML_Reinit;
385 self._dataEvent = Item_DataLink_Nex_MapList_DataEvent;
386 self._destroy = Item_DataLink_Nex_MapList_Destroy;
393 Item_DataLink_Nex_MapList_InitWithMapList
396 void() Item_DataLink_Nex_MapList_InitWithMapList =
398 String_EntitySet( self, valueList, Nex_MapDB_GetPathAltString() );
399 String_EntitySet( self, descList, Nex_MapDB_GetNameAltString() );
401 DataLink_Nex_MapList_UpdateRange( self );
406 DataLink_Nex_MapList_UpdateRange
409 void( entity pItem ) DataLink_Nex_MapList_UpdateRange =
411 pItem.minValue = 1.0;
412 pItem.maxValue = Util_GetAltStringCount( pItem.descList );
414 if( pItem.maxValue >= 1 ) {
415 pItem.stepValue = 1.0;
417 pItem.maxValue = 1.0;
418 pItem.stepValue = 0.0;
424 DataLink_Nex_MapList_InsertEntryAfter
427 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_InsertEntryAfter =
431 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
432 // - 1, because minValue == 1
433 lIndex = pItem._realValue - 1;
434 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndex, pName );
435 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndex, pPath );
437 DataLink_Nex_MapList_UpdateRange( pItem );
442 DataLink_Nex_MapList_DeleteEntry
445 void( entity pItem ) DataLink_Nex_MapList_DeleteEntry =
449 if( pItem.stepValue == 0.0 )
452 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
453 lIndex = pItem._realValue - 1;
454 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndex );
455 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndex );
457 DataLink_Nex_MapList_UpdateRange( pItem );
462 DataLink_Nex_MapList_MoveEntryUp
465 void( entity pItem ) DataLink_Nex_MapList_MoveEntryUp =
469 local float lIndexNew;
470 local float lIndexOld;
472 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
473 if( pItem._realValue == 1 )
476 // map 1..n to 0..n-1
477 lIndexOld = pItem._realValue - 1;
479 // we want to insert it up by one, ie. insert it after up by two
480 lIndexNew = lIndexOld - 2;
482 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
483 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
485 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
486 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
488 // adjust lIndexOld for the entry that has been inserted before it
489 lIndexOld = lIndexOld + 1;
491 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
492 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
494 DataLink_Nex_MapList_UpdateRange( pItem );
499 DataLink_Nex_MapList_MoveEntryDown
502 void( entity pItem ) DataLink_Nex_MapList_MoveEntryDown =
506 local float lIndexNew;
507 local float lIndexOld;
509 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
510 if( pItem._realValue == pItem.maxValue )
513 // map 1..n to 0..n-1
514 lIndexOld = pItem._realValue - 1;
516 // we want to insert it down by one
517 lIndexNew = lIndexOld + 1;
519 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
520 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
522 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
523 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
525 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
526 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
528 DataLink_Nex_MapList_UpdateRange( pItem );
533 DataLink_Nex_MapList_SetFirst
536 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_SetFirst =
538 if( pItem.stepValue == 0.0 ) {
539 pItem.descList = Util_AltStringPush( pItem.descList, pName );
540 pItem.valueList = Util_AltStringPush( pItem.valueList, pPath );
542 pItem.descList = Util_SetAltStringItem( pItem.descList, 0, pName );
543 pItem.valueList = Util_SetAltStringItem( pItem.valueList, 0, pPath );
546 DataLink_Nex_MapList_UpdateRange( pItem );
551 DataLink_Nex_MapList_Clear
554 void( entity pItem ) DataLink_Nex_MapList_Clear =
556 String_EntitySet( pItem, descList, "" );
557 String_EntitySet( pItem, valueList, "" );
559 DataLink_Nex_MapList_UpdateRange( pItem );
564 DataLink_Nex_MapList_GetCurrentName
567 string( entity pItem ) DataLink_Nex_MapList_GetCurrentName =
569 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
570 return Util_GetAltStringItem( pItem.descList, pItem._realValue - 1 );
575 DataLink_Nex_MapList_GetCurrentPath
578 string( entity pItem ) DataLink_Nex_MapList_GetCurrentPath =
580 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
581 return Util_GetAltStringItem( pItem.valueList, pItem._realValue - 1 );