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 string _Nex_MapList_FilteredFullPath;
48 string _Nex_MapList_FilteredName;
49 string _Nex_MapList_Filter;
50 entity _Nex_MapList_Root;
54 Item_Nex_MapDB_EnumFiles
57 // map definition format
59 // rest: description text
60 void() Item_Nex_MapDB_EnumFiles =
62 local float lSearchHandle;
63 local float lSearchSize;
64 local float lSearchCounter;
67 lSearchHandle = search_begin( "maps/*.mapcfg", true, true );
68 if( lSearchHandle < 0 )
71 for( lSearchSize = search_getsize( lSearchHandle );
72 lSearchCounter < lSearchSize; ++lSearchCounter ) {
75 local string lFilename;
76 local string lStripped;
79 local string lDescription;
82 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
83 lStripped = String_Zone( substring( lFilename, 0, strlen( lFilename ) - 7 ) );
84 lName = String_Zone( substring( lStripped, 5, 100000 ) );
86 lHandle = fopen( strcat( lStripped, ".txt" ), FILE_READ );
88 lTitle = String_Zone( lName );
89 lDescription = String_Zone( strcat( "--NO INFORMATION AVAILABLE--\n", lFilename ) );
91 // uncomment this line and comment the other if you have the old map info files
92 //lTitle = String_Zone( lName );
93 lTitle = String_Zone( fgets( lHandle ) );
94 lPic = fgets( lHandle ); // also get picture
97 lStripped = String_Zone( lPic );
100 lDescription = String_Create();
104 lLine = fgets( lHandle );
105 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
106 } while( validstring( lLine ) );
111 // save this in a new Map_Info
112 lMap = Menu_CreateItem( "Item_Nex_Map_Info", ftos( lSearchCounter ), self.name );
116 if( Gfx_Precache( lStripped ) ) {
117 lMap.picture = lStripped;
119 lMap.picture = "gfx/m_nomap";
121 lMap.normal = lTitle;
122 lMap.text = lDescription;
124 _Nex_MapList_FullPath = Util_AltStringPushBack( _Nex_MapList_FullPath, lName );
125 _Nex_MapList_Name = Util_AltStringPushBack( _Nex_MapList_Name, lTitle );
127 Menu_LinkItem( lMap );
129 String_Free( lTitle );
130 String_Free( lName );
131 String_Free( lStripped );
132 String_Free( lDescription );
135 search_end( lSearchHandle );
137 _Nex_MapList_FilteredFullPath = String_Set( _Nex_MapList_FilteredFullPath, _Nex_MapList_FullPath );
138 _Nex_MapList_FilteredName = String_Set( _Nex_MapList_FilteredName, _Nex_MapList_Name );
140 Menu_LinkChildren( self );
144 self.maxValue = fabs( lMap.orderPos );
149 Item_Nex_MapDB_Destroy
152 void() Item_Nex_MapDB_Destroy =
154 String_Free( _Nex_MapList_FullPath );
155 String_Free( _Nex_MapList_Name );
156 String_Free( _Nex_MapList_FilteredFullPath );
157 String_Free( _Nex_MapList_FilteredName );
158 String_Free( _Nex_MapList_Filter );
160 _Nex_MapList_Root = null_entity;
168 void() Item_Nex_MapDB_Spawn =
170 if( _Nex_MapList_Root )
171 error( "There is already another Item_Nex_MapDB object!" );
173 _Nex_MapList_FullPath = String_Create();
174 _Nex_MapList_Name = String_Create();
175 _Nex_MapList_FilteredFullPath = String_Create();
176 _Nex_MapList_FilteredName = String_Create();
177 _Nex_MapList_Filter = String_Create();
178 _Nex_MapList_Root = self;
180 Item_Nex_MapDB_EnumFiles();
182 self._destroy = Item_Nex_MapDB_Destroy;
190 entity( string pPath ) Nex_MapDB_GetByPath =
194 if( !_Nex_MapList_Root )
195 error( "No Item_Nex_MapDB found!" );
197 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
198 if( lNode.link == pPath ) {
208 Nex_MapDB_GetFilteredByIndex
211 entity( float pIndex ) Nex_MapDB_GetFilteredByIndex =
214 local float lFilteredIndex;
216 if( !_Nex_MapList_Root )
217 error( "No Item_Nex_MapDB found!" );
219 pIndex = fabs( pIndex );
221 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
222 if( substring( lNode.link, 0, strlen( _Nex_MapList_Filter ) ) == _Nex_MapList_Filter ) {
225 if( pIndex == lFilteredIndex ) {
238 entity( float pIndex ) Nex_MapDB_GetByIndex =
242 if( !_Nex_MapList_Root )
243 error( "No Item_Nex_MapDB found!" );
245 pIndex = fabs( pIndex );
246 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
247 if( fabs( lNode.orderPos ) == pIndex ) {
260 void( string pPrefix ) Nex_MapDB_FilterMaps =
262 local float lPrefixLength;
263 local float lCounter;
266 _Nex_MapList_Filter = String_Set( _Nex_MapList_Filter, pPrefix );
268 _Nex_MapList_FilteredFullPath = String_Set( _Nex_MapList_FilteredFullPath, "" );
269 _Nex_MapList_FilteredName = String_Set( _Nex_MapList_FilteredName, "" );
271 lPrefixLength = strlen( pPrefix );
272 lSize = Util_GetAltStringCount( _Nex_MapList_FullPath );
273 for( lCounter = 0 ; lCounter < lSize ; ++lCounter ) {
276 lPath = Util_GetAltStringItem( _Nex_MapList_FullPath, lCounter );
277 if( substring( lPath, 0, lPrefixLength ) == pPrefix ) {
279 lName = Util_GetAltStringItem( _Nex_MapList_Name, lCounter );
281 _Nex_MapList_FilteredFullPath = Util_AltStringPushBack( _Nex_MapList_FilteredFullPath, lPath );
282 _Nex_MapList_FilteredName = Util_AltStringPushBack( _Nex_MapList_FilteredName, lName );
284 String_Free( lName );
287 String_Free( lPath );
293 Nex_MapDB_GetFilteredPathAltString
296 string() Nex_MapDB_GetFilteredPathAltString =
298 return _Nex_MapList_FilteredFullPath;
303 Nex_MapDB_GetFilteredNameAltString
306 string() Nex_MapDB_GetFilteredNameAltString =
308 return _Nex_MapList_FilteredName;
313 Nex_MapDB_GetPathAltString
316 string() Nex_MapDB_GetPathAltString =
318 return _Nex_MapList_FullPath;
323 Nex_MapDB_GetNameAltString
326 string() Nex_MapDB_GetNameAltString =
328 return _Nex_MapList_Name;
333 Nex_MapDB_GetFilteredIndex
336 float( entity pItem ) Nex_MapDB_GetFilteredIndex =
341 lCount = Util_GetAltStringCount( _Nex_MapList_FilteredFullPath );
342 for( lIndex = 0 ; lIndex < lCount ; ++lIndex ) {
344 lPath = String_Normal( Util_GetAltStringItem( _Nex_MapList_FilteredFullPath, lIndex ) );
345 if( lPath == pItem.link ) {
354 Item_DataLink_Nex_MapList_Save
357 void() Item_DataLink_Nex_MapList_Save =
361 local string lOutput;
363 lOutput = String_Create();
365 lCount = Util_GetAltStringCount( self.valueList );
366 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
367 lOutput = String_Append( lOutput, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
370 cvar_set( self.cvarName, lOutput );
371 cvar_set( strcat( self.cvarName, "_index" ), "0" );
373 String_Free( lOutput );
378 Item_DataLink_Nex_MapList_Load
381 void() Item_DataLink_Nex_MapList_Load =
384 local entity lMapInfo;
385 local float lCounter;
388 DataLink_Nex_MapList_Clear( self );
390 lCount = tokenize( cvar_string( self.cvarName ) );
392 lEntry = String_Create();
393 for( lCounter = 0 ; lCounter < lCount ; lCounter++ ) {
394 lEntry = String_Set( lEntry, argv( lCounter ) );
396 lMapInfo = Nex_MapDB_GetByPath( lEntry );
397 if( lMapInfo == null_entity ) {
398 print( self.cvarName, ": Map '", lEntry, "' not found in database - ignored\n" );
402 self.descList = Util_AltStringPushBack( self.descList, lMapInfo.normal );
403 self.valueList = Util_AltStringPushBack( self.valueList, lMapInfo.link );
405 String_Free( lEntry );
407 DataLink_Nex_MapList_UpdateRange( self );
408 Nex_MapSelector_Synchronize();
413 Item_DataLink_Nex_MapList_ExecString
416 void() Item_DataLink_Nex_MapList_ExecString =
421 Data_ExecString = String_Append( Data_ExecString, strcat( "set \"", self.cvarName, "_index\" \"0\"\nset \"", self.cvarName, "\" \"" ) );
423 lCount = Util_GetAltStringCount( self.valueList );
424 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
425 Data_ExecString = String_Append( Data_ExecString, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
428 Data_ExecString = String_Append( Data_ExecString, "\"\n" );
433 Item_DataLink_Nex_MapList_DataEvent
436 void( float pEvent ) Item_DataLink_Nex_MapList_DataEvent =
440 if( self.cvarName != "" ) {
441 Item_DataLink_Nex_MapList_Load();
445 if( self.cvarName != "" ) {
446 Item_DataLink_Nex_MapList_Save();
449 case ITEM_DATA_RESET:
450 self._realValue = 1.0;
452 case ITEM_DATA_TEST_START:
454 case ITEM_DATA_TEST_END:
456 case ITEM_DATA_SAVE_EXECSTRING:
457 if( self.cvarName != "" ) {
458 Item_DataLink_Nex_MapList_ExecString();
461 case ITEM_DATALINK_SET:
462 case ITEM_DATALINK_GET:
463 self._realValue = floor( self._realValue );
464 if( self._realValue < 1.0 ) {
465 self._realValue = 1.0;
466 } else if( self._realValue > self.maxValue ) {
467 self._realValue = self.maxValue;
479 void() IDLNML_Reinit =
481 Raise_DataEvent( self, ITEM_DATA_SYNC );
486 Item_DataLink_Nex_MapList_Destroy
489 void() Item_DataLink_Nex_MapList_Destroy =
491 String_EntityFree( self, valueList );
492 String_EntityFree( self, cvarName );
494 Item_DataLink_Switch_Destroy();
499 Item_DataLink_Nex_MapList_Spawn
502 void() Item_DataLink_Nex_MapList_Spawn =
504 Item_DataLink_Switch_Init();
505 String_EntityZone( self, valueList );
506 String_EntityZone( self, cvarName );
508 if( self.cvarName != "" ) {
509 registercvar( self.cvarName, "", CVAR_SAVE );
510 registercvar( strcat( self.cvarName, "_index" ), "", CVAR_SAVE );
515 self.stepValue = 0.0;
517 self._reinit = IDLNML_Reinit;
518 self._dataEvent = Item_DataLink_Nex_MapList_DataEvent;
519 self._destroy = Item_DataLink_Nex_MapList_Destroy;
526 Item_DataLink_Nex_MapList_InitWithMapList
529 void() Item_DataLink_Nex_MapList_InitWithMapList =
531 String_EntitySet( self, valueList, Nex_MapDB_GetFilteredPathAltString() );
532 String_EntitySet( self, descList, Nex_MapDB_GetFilteredNameAltString() );
534 self._realValue = 1.0;
535 DataLink_Nex_MapList_UpdateRange( self );
540 DataLink_Nex_MapList_UpdateRange
543 void( entity pItem ) DataLink_Nex_MapList_UpdateRange =
545 pItem.minValue = 1.0;
546 pItem.maxValue = Util_GetAltStringCount( pItem.descList );
548 if( pItem.maxValue >= 1 ) {
549 pItem.stepValue = 1.0;
551 pItem.maxValue = 1.0;
552 pItem.stepValue = 0.0;
558 DataLink_Nex_MapList_InsertEntryAfter
561 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_InsertEntryAfter =
565 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
566 // - 1, because minValue == 1
567 lIndex = pItem._realValue - 1;
568 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndex, pName );
569 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndex, pPath );
571 DataLink_Nex_MapList_UpdateRange( pItem );
576 DataLink_Nex_MapList_DeleteEntry
579 void( entity pItem ) DataLink_Nex_MapList_DeleteEntry =
583 if( pItem.stepValue == 0.0 )
586 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
587 lIndex = pItem._realValue - 1;
588 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndex );
589 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndex );
591 DataLink_Nex_MapList_UpdateRange( pItem );
596 DataLink_Nex_MapList_MoveEntryUp
599 void( entity pItem ) DataLink_Nex_MapList_MoveEntryUp =
603 local float lIndexNew;
604 local float lIndexOld;
606 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
607 if( pItem._realValue == 1 )
610 // map 1..n to 0..n-1
611 lIndexOld = pItem._realValue - 1;
613 // we want to insert it up by one, ie. insert it after up by two
614 lIndexNew = lIndexOld - 2;
616 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
617 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
619 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
620 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
622 // adjust lIndexOld for the entry that has been inserted before it
623 lIndexOld = lIndexOld + 1;
625 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
626 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
628 DataLink_Nex_MapList_UpdateRange( pItem );
633 DataLink_Nex_MapList_MoveEntryDown
636 void( entity pItem ) DataLink_Nex_MapList_MoveEntryDown =
640 local float lIndexNew;
641 local float lIndexOld;
643 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
644 if( pItem._realValue == pItem.maxValue )
647 // map 1..n to 0..n-1
648 lIndexOld = pItem._realValue - 1;
650 // we want to insert it down by one
651 lIndexNew = lIndexOld + 1;
653 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
654 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
656 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
657 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
659 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
660 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
662 DataLink_Nex_MapList_UpdateRange( pItem );
667 DataLink_Nex_MapList_SetFirst
670 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_SetFirst =
672 if( pItem.stepValue == 0.0 ) {
673 pItem.descList = Util_AltStringPush( pItem.descList, pName );
674 pItem.valueList = Util_AltStringPush( pItem.valueList, pPath );
676 pItem.descList = Util_SetAltStringItem( pItem.descList, 0, pName );
677 pItem.valueList = Util_SetAltStringItem( pItem.valueList, 0, pPath );
680 DataLink_Nex_MapList_UpdateRange( pItem );
685 DataLink_Nex_MapList_Clear
688 void( entity pItem ) DataLink_Nex_MapList_Clear =
690 String_EntitySet( pItem, descList, "" );
691 String_EntitySet( pItem, valueList, "" );
693 DataLink_Nex_MapList_UpdateRange( pItem );
698 DataLink_Nex_MapList_GetCurrentName
701 string( entity pItem ) DataLink_Nex_MapList_GetCurrentName =
703 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
704 return Util_GetAltStringItem( pItem.descList, pItem._realValue - 1 );
709 DataLink_Nex_MapList_GetCurrentPath
712 string( entity pItem ) DataLink_Nex_MapList_GetCurrentPath =
714 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
715 return Util_GetAltStringItem( pItem.valueList, pItem._realValue - 1 );