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 )
70 for( lSearchSize = search_getsize( lSearchHandle ), lSearchCounter = 0;
71 lSearchCounter < lSearchSize; ++lSearchCounter ) {
74 local string lFilename;
75 local string lStripped;
78 local string lDescription;
81 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
82 lStripped = String_Zone( substring( lFilename, 0, strlen( lFilename ) - 7 ) );
83 lName = String_Zone( substring( lStripped, 5, 100000 ) );
85 lHandle = fopen( strcat( lStripped, ".txt" ), FILE_READ );
87 lTitle = String_Zone( lName );
88 lDescription = String_Zone( strcat( "--NO INFORMATION AVAILABLE--\n", lFilename ) );
90 // uncomment this line and comment the other if you have the old map info files
91 //lTitle = String_Zone( lName );
92 lTitle = String_Zone( fgets( lHandle ) );
93 lPic = fgets( lHandle ); // also get picture
96 lStripped = String_Zone( lPic );
99 lDescription = String_Create();
103 lLine = fgets( lHandle );
104 lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
105 } while( validstring( lLine ) );
110 // save this in a new Map_Info
111 lMap = Menu_CreateItem( "Item_Nex_Map_Info", ftos( lSearchCounter ), self.name );
115 if( Gfx_Precache( lStripped ) ) {
116 lMap.picture = lStripped;
118 lMap.picture = "gfx/m_nomap";
120 lMap.normal = lTitle;
121 lMap.text = lDescription;
123 _Nex_MapList_FullPath = Util_AltStringPushBack( _Nex_MapList_FullPath, lName );
124 _Nex_MapList_Name = Util_AltStringPushBack( _Nex_MapList_Name, lTitle );
126 Menu_LinkItem( lMap );
128 String_Free( lTitle );
129 String_Free( lName );
130 String_Free( lStripped );
131 String_Free( lDescription );
134 search_end( lSearchHandle );
136 _Nex_MapList_FilteredFullPath = String_Set( _Nex_MapList_FilteredFullPath, _Nex_MapList_FullPath );
137 _Nex_MapList_FilteredName = String_Set( _Nex_MapList_FilteredName, _Nex_MapList_Name );
139 Menu_LinkChildren( self );
143 self.maxValue = fabs( lMap.orderPos );
148 Item_Nex_MapDB_Destroy
151 void() Item_Nex_MapDB_Destroy =
153 String_Free( _Nex_MapList_FullPath );
154 String_Free( _Nex_MapList_Name );
155 String_Free( _Nex_MapList_FilteredFullPath );
156 String_Free( _Nex_MapList_FilteredName );
157 String_Free( _Nex_MapList_Filter );
159 _Nex_MapList_Root = null_entity;
167 void() Item_Nex_MapDB_Spawn =
169 if( _Nex_MapList_Root )
170 error( "There is already another Item_Nex_MapDB object!" );
172 _Nex_MapList_FullPath = String_Create();
173 _Nex_MapList_Name = String_Create();
174 _Nex_MapList_FilteredFullPath = String_Create();
175 _Nex_MapList_FilteredName = String_Create();
176 _Nex_MapList_Filter = String_Create();
177 _Nex_MapList_Root = self;
179 Item_Nex_MapDB_EnumFiles();
181 self._destroy = Item_Nex_MapDB_Destroy;
189 entity( string pPath ) Nex_MapDB_GetByPath =
193 if( !_Nex_MapList_Root )
194 error( "No Item_Nex_MapDB found!" );
196 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
197 if( lNode.link == pPath ) {
207 Nex_MapDB_GetFilteredByIndex
210 entity( float pIndex ) Nex_MapDB_GetFilteredByIndex =
213 local float lFilteredIndex;
215 if( !_Nex_MapList_Root )
216 error( "No Item_Nex_MapDB found!" );
218 pIndex = fabs( pIndex );
220 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
221 if( substring( lNode.link, 0, strlen( _Nex_MapList_Filter ) ) == _Nex_MapList_Filter ) {
224 if( pIndex == lFilteredIndex ) {
237 entity( float pIndex ) Nex_MapDB_GetByIndex =
241 if( !_Nex_MapList_Root )
242 error( "No Item_Nex_MapDB found!" );
244 pIndex = fabs( pIndex );
245 for( lNode = _Nex_MapList_Root._child ; lNode ; lNode = lNode._next ) {
246 if( fabs( lNode.orderPos ) == pIndex ) {
259 void( string pPrefix ) Nex_MapDB_FilterMaps =
261 local float lPrefixLength;
262 local float lCounter;
265 _Nex_MapList_Filter = String_Set( _Nex_MapList_Filter, pPrefix );
267 _Nex_MapList_FilteredFullPath = String_Set( _Nex_MapList_FilteredFullPath, "" );
268 _Nex_MapList_FilteredName = String_Set( _Nex_MapList_FilteredName, "" );
270 lPrefixLength = strlen( pPrefix );
271 lSize = Util_GetAltStringCount( _Nex_MapList_FullPath );
272 for( lCounter = 0 ; lCounter < lSize ; ++lCounter ) {
275 lPath = Util_GetAltStringItem( _Nex_MapList_FullPath, lCounter );
276 if( substring( lPath, 0, lPrefixLength ) == pPrefix ) {
278 lName = Util_GetAltStringItem( _Nex_MapList_Name, lCounter );
280 _Nex_MapList_FilteredFullPath = Util_AltStringPushBack( _Nex_MapList_FilteredFullPath, lPath );
281 _Nex_MapList_FilteredName = Util_AltStringPushBack( _Nex_MapList_FilteredName, lName );
283 String_Free( lName );
286 String_Free( lPath );
292 Nex_MapDB_GetFilteredPathAltString
295 string() Nex_MapDB_GetFilteredPathAltString =
297 return _Nex_MapList_FilteredFullPath;
302 Nex_MapDB_GetFilteredNameAltString
305 string() Nex_MapDB_GetFilteredNameAltString =
307 return _Nex_MapList_FilteredName;
312 Nex_MapDB_GetPathAltString
315 string() Nex_MapDB_GetPathAltString =
317 return _Nex_MapList_FullPath;
322 Nex_MapDB_GetNameAltString
325 string() Nex_MapDB_GetNameAltString =
327 return _Nex_MapList_Name;
332 Nex_MapDB_GetFilteredIndex
335 float( entity pItem ) Nex_MapDB_GetFilteredIndex =
340 lCount = Util_GetAltStringCount( _Nex_MapList_FilteredFullPath );
341 for( lIndex = 0 ; lIndex < lCount ; ++lIndex ) {
343 lPath = String_Normal( Util_GetAltStringItem( _Nex_MapList_FilteredFullPath, lIndex ) );
344 if( lPath == pItem.link ) {
353 Item_DataLink_Nex_MapList_Save
356 void() Item_DataLink_Nex_MapList_Save =
360 local string lOutput;
362 lOutput = String_Create();
364 lCount = Util_GetAltStringCount( self.valueList );
365 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
366 lOutput = String_Append( lOutput, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
369 cvar_set( self.cvarName, lOutput );
370 cvar_set( strcat( self.cvarName, "_index" ), "0" );
372 String_Free( lOutput );
377 Item_DataLink_Nex_MapList_Load
380 void() Item_DataLink_Nex_MapList_Load =
383 local entity lMapInfo;
384 local float lCounter;
387 DataLink_Nex_MapList_Clear( self );
389 lCount = tokenize( cvar_string( self.cvarName ) );
391 lEntry = String_Create();
392 for( lCounter = 0 ; lCounter < lCount ; lCounter++ ) {
393 lEntry = String_Set( lEntry, argv( lCounter ) );
395 lMapInfo = Nex_MapDB_GetByPath( lEntry );
396 if( lMapInfo == null_entity ) {
397 print( self.cvarName, ": Map '", lEntry, "' not found in database - ignored\n" );
401 self.descList = Util_AltStringPushBack( self.descList, lMapInfo.normal );
402 self.valueList = Util_AltStringPushBack( self.valueList, lMapInfo.link );
404 String_Free( lEntry );
406 DataLink_Nex_MapList_UpdateRange( self );
407 Nex_MapSelector_Synchronize();
412 Item_DataLink_Nex_MapList_ExecString
415 void() Item_DataLink_Nex_MapList_ExecString =
420 Data_ExecString = String_Append( Data_ExecString, strcat( "set \"", self.cvarName, "_index\" \"0\"\nset \"", self.cvarName, "\" \"" ) );
422 lCount = Util_GetAltStringCount( self.valueList );
423 for( lIndex = 0 ; lIndex < lCount ; lIndex++ ) {
424 Data_ExecString = String_Append( Data_ExecString, strcat( "\'", String_Normal( Util_GetAltStringItem( self.valueList, lIndex ) ), "\'" ) );
427 Data_ExecString = String_Append( Data_ExecString, "\"\n" );
432 Item_DataLink_Nex_MapList_DataEvent
435 void( float pEvent ) Item_DataLink_Nex_MapList_DataEvent =
439 if( self.cvarName != "" ) {
440 Item_DataLink_Nex_MapList_Load();
444 if( self.cvarName != "" ) {
445 Item_DataLink_Nex_MapList_Save();
448 case ITEM_DATA_RESET:
449 self._realValue = 1.0;
451 case ITEM_DATA_TEST_START:
453 case ITEM_DATA_TEST_END:
455 case ITEM_DATA_SAVE_EXECSTRING:
456 if( self.cvarName != "" ) {
457 Item_DataLink_Nex_MapList_ExecString();
460 case ITEM_DATALINK_SET:
461 case ITEM_DATALINK_GET:
462 self._realValue = floor( self._realValue );
463 if( self._realValue < 1.0 ) {
464 self._realValue = 1.0;
465 } else if( self._realValue > self.maxValue ) {
466 self._realValue = self.maxValue;
478 void() IDLNML_Reinit =
480 Raise_DataEvent( self, ITEM_DATA_SYNC );
485 Item_DataLink_Nex_MapList_Destroy
488 void() Item_DataLink_Nex_MapList_Destroy =
490 String_EntityFree( self, valueList );
491 String_EntityFree( self, cvarName );
493 Item_DataLink_Switch_Destroy();
498 Item_DataLink_Nex_MapList_Spawn
501 void() Item_DataLink_Nex_MapList_Spawn =
503 Item_DataLink_Switch_Init();
504 String_EntityZone( self, valueList );
505 String_EntityZone( self, cvarName );
507 if( self.cvarName != "" ) {
508 registercvar( self.cvarName, "", CVAR_SAVE );
509 registercvar( strcat( self.cvarName, "_index" ), "", CVAR_SAVE );
514 self.stepValue = 0.0;
516 self._reinit = IDLNML_Reinit;
517 self._dataEvent = Item_DataLink_Nex_MapList_DataEvent;
518 self._destroy = Item_DataLink_Nex_MapList_Destroy;
525 Item_DataLink_Nex_MapList_InitWithMapList
528 void() Item_DataLink_Nex_MapList_InitWithMapList =
530 String_EntitySet( self, valueList, Nex_MapDB_GetFilteredPathAltString() );
531 String_EntitySet( self, descList, Nex_MapDB_GetFilteredNameAltString() );
533 self._realValue = 1.0;
534 DataLink_Nex_MapList_UpdateRange( self );
539 DataLink_Nex_MapList_UpdateRange
542 void( entity pItem ) DataLink_Nex_MapList_UpdateRange =
544 pItem.minValue = 1.0;
545 pItem.maxValue = Util_GetAltStringCount( pItem.descList );
547 if( pItem.maxValue >= 1 ) {
548 pItem.stepValue = 1.0;
550 pItem.maxValue = 1.0;
551 pItem.stepValue = 0.0;
557 DataLink_Nex_MapList_InsertEntryAfter
560 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_InsertEntryAfter =
564 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
565 // - 1, because minValue == 1
566 lIndex = pItem._realValue - 1;
567 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndex, pName );
568 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndex, pPath );
570 DataLink_Nex_MapList_UpdateRange( pItem );
575 DataLink_Nex_MapList_DeleteEntry
578 void( entity pItem ) DataLink_Nex_MapList_DeleteEntry =
582 if( pItem.stepValue == 0.0 )
585 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
586 lIndex = pItem._realValue - 1;
587 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndex );
588 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndex );
590 DataLink_Nex_MapList_UpdateRange( pItem );
595 DataLink_Nex_MapList_MoveEntryUp
598 void( entity pItem ) DataLink_Nex_MapList_MoveEntryUp =
602 local float lIndexNew;
603 local float lIndexOld;
605 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
606 if( pItem._realValue == 1 )
609 // map 1..n to 0..n-1
610 lIndexOld = pItem._realValue - 1;
612 // we want to insert it up by one, ie. insert it after up by two
613 lIndexNew = lIndexOld - 2;
615 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
616 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
618 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
619 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
621 // adjust lIndexOld for the entry that has been inserted before it
622 lIndexOld = lIndexOld + 1;
624 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
625 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
627 DataLink_Nex_MapList_UpdateRange( pItem );
632 DataLink_Nex_MapList_MoveEntryDown
635 void( entity pItem ) DataLink_Nex_MapList_MoveEntryDown =
639 local float lIndexNew;
640 local float lIndexOld;
642 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
643 if( pItem._realValue == pItem.maxValue )
646 // map 1..n to 0..n-1
647 lIndexOld = pItem._realValue - 1;
649 // we want to insert it down by one
650 lIndexNew = lIndexOld + 1;
652 lName = Util_GetAltStringItem( pItem.descList, lIndexOld );
653 lPath = Util_GetAltStringItem( pItem.valueList, lIndexOld );
655 pItem.descList = Util_InsAltStringItem( pItem.descList, lIndexNew, String_Normal( lName ) );
656 pItem.valueList = Util_InsAltStringItem( pItem.valueList, lIndexNew, String_Normal( lPath ) );
658 pItem.descList = Util_DelAltStringItem( pItem.descList, lIndexOld );
659 pItem.valueList = Util_DelAltStringItem( pItem.valueList, lIndexOld );
661 DataLink_Nex_MapList_UpdateRange( pItem );
666 DataLink_Nex_MapList_SetFirst
669 void( entity pItem, string pName, string pPath ) DataLink_Nex_MapList_SetFirst =
671 if( pItem.stepValue == 0.0 ) {
672 pItem.descList = Util_AltStringPush( pItem.descList, pName );
673 pItem.valueList = Util_AltStringPush( pItem.valueList, pPath );
675 pItem.descList = Util_SetAltStringItem( pItem.descList, 0, pName );
676 pItem.valueList = Util_SetAltStringItem( pItem.valueList, 0, pPath );
679 DataLink_Nex_MapList_UpdateRange( pItem );
684 DataLink_Nex_MapList_Clear
687 void( entity pItem ) DataLink_Nex_MapList_Clear =
689 String_EntitySet( pItem, descList, "" );
690 String_EntitySet( pItem, valueList, "" );
692 DataLink_Nex_MapList_UpdateRange( pItem );
697 DataLink_Nex_MapList_GetCurrentName
700 string( entity pItem ) DataLink_Nex_MapList_GetCurrentName =
702 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
703 return Util_GetAltStringItem( pItem.descList, pItem._realValue - 1 );
708 DataLink_Nex_MapList_GetCurrentPath
711 string( entity pItem ) DataLink_Nex_MapList_GetCurrentPath =
713 Raise_DataEvent( pItem, ITEM_DATALINK_GET );
714 return Util_GetAltStringItem( pItem.valueList, pItem._realValue - 1 );