]> icculus.org git repositories - divverent/nexuiz.git/blob - data/oldmenuqc/custom/player/avatar.qc
Now overtime also gets initiated by equal frags and reaching the fraglimit.
[divverent/nexuiz.git] / data / oldmenuqc / custom / player / avatar.qc
1 // Property of Alientrap/AK
2 // custom/player/avatar.qm
3
4 /*
5 ===================
6 Item_Nex_Avatar_Info
7 ===================
8 */
9
10 void() Item_Nex_Avatar_Info_Destroy =
11 {
12         String_EntityFree( self, target );
13         String_EntityFree( self, link );
14         String_EntityFree( self, picture );
15         String_EntityFree( self, text );
16         String_EntityFree( self, normal );
17 };
18
19 void() Item_Nex_Avatar_Info_Spawn =
20 {
21         String_EntityZone( self, target );
22         String_EntityZone( self, link );
23         String_EntityZone( self, picture );
24         String_EntityZone( self, text );
25         String_EntityZone( self, normal );
26
27         Gfx_Precache( self.picture );
28
29         self._destroy = Item_Nex_Avatar_Info_Destroy;
30 };
31
32 /*
33 ===================
34 Item_Data_Nex_Avatar
35 ===================
36 */
37
38
39 // Nex_Action_Player_BuildAvatarList
40 // model definition format
41 // name
42 // picture\n
43 // skin filename\n
44 // model filename\n
45 // rest: description text
46 void() _IDNA_BuildList =
47 {
48         local float     lSearchHandle;
49         local float     lSearchSize;
50         local float     lSearchCounter;
51         local entity    lAvatar;
52
53         Menu_EmptyWindow( self );
54
55         // legacy mode
56         // TODO:
57         // FIXME: only accept *.mdef later
58         lSearchHandle = search_begin( "models/player/*.txt", true, true );
59         if( lSearchHandle < 0 )
60                 return;
61         lSearchCounter = 0;
62         for( lSearchSize = search_getsize( lSearchHandle );
63         lSearchCounter < lSearchSize; ++lSearchCounter ) {
64                 local string    lFilename;
65                 local float     lHandle;
66
67                 local string    lName;
68                 local string    lPicture;
69                 local string    lSkin;
70                 local string    lModel;
71                 local string    lDescription;
72
73                 lFilename = search_getfilename( lSearchHandle, lSearchCounter );
74                 lHandle = fopen( lFilename, FILE_READ );
75                 if( lHandle < 0 ) {
76                         print( "Menu: Couldn't open model definition file '", lFilename, "'\n" );
77                         continue;
78                 }
79
80                 lName = String_Zone( fgets( lHandle ) );
81                 lPicture = String_Zone(  fgets( lHandle ) );
82                 lSkin = String_Zone( fgets( lHandle ) );
83                 lModel = String_Zone( fgets( lHandle ) );
84                 if( !lName || !lPicture || !lSkin || !lModel ) {
85                         String_Free( lName );
86                         String_Free( lPicture );
87                         String_Free( lSkin );
88                         String_Free( lModel );
89                         print( "Menu: Couldn't parse model definition file '",
90                          search_getfilename( lSearchHandle, lSearchCounter ), "'\n" );
91                         fclose( lHandle );
92                         continue;
93                 }
94                 lDescription = String_Create();
95                 do {
96                         local string lLine;
97
98                         lLine = fgets( lHandle );
99                         lDescription = String_Append( lDescription, strcat( lLine, "\n" ) );
100                 } while( validstring( lLine ) );
101                 if( lDescription ) { // add this avatar_info
102                         lAvatar = Menu_CreateItem( "Item_Nex_Avatar_Info", ftos( lSearchCounter ), self.name );
103
104                         lAvatar.target = lModel;
105                         lAvatar.link = lSkin;
106                         lAvatar.picture = lPicture;
107                         lAvatar.normal = lName;
108                         lAvatar.text = lDescription;
109
110                         Menu_LinkItem( lAvatar );
111                 }
112                 String_Free( lName );
113                 String_Free( lPicture );
114                 String_Free( lSkin );
115                 String_Free( lModel );
116                 String_Free( lDescription );
117                 fclose( lHandle );
118         }
119
120         search_end( lSearchHandle );
121
122         Menu_LinkChildren( self );
123
124         self.minValue = 1;
125         self.stepValue = 1;
126         self.maxValue = fabs( lAvatar.orderPos );
127 };
128
129 void() _IDNA_Sync =
130 {
131         local string lModel, lSkin;
132         local entity lMatch;
133
134         lModel = String_Zone( cvar_string( "_cl_playermodel" ) );
135         lSkin = String_Zone( cvar_string( "_cl_playerskin" ) );
136
137         for( lMatch = self._child ; lMatch._next ; lMatch = lMatch._next )
138                 if( lMatch.target == lModel && lMatch.link == lSkin )
139                         break;
140
141         if( lMatch ) {
142                 self._link = lMatch;
143                 self._realValue = fabs( lMatch.orderPos );
144                 String_EntitySet( self, value, ftos( self._realValue ) );
145                 String_EntitySet( self, _syncValue, self.value );
146         }
147
148         String_Free( lModel );
149         String_Free( lSkin );
150 };
151
152 void() _IDNA_UpdateLink =
153 {
154         local float lCurrent;
155         local float lTarget;
156         local entity lMatch;
157
158         lCurrent = fabs( self._link.orderPos );
159         lTarget = self._realValue;
160         if( lCurrent < lTarget )
161                 for( lMatch = self._link; lMatch._next && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._next );
162         else
163                 for( lMatch = self._link; lMatch._prev && fabs( lMatch.orderPos ) != lTarget; lMatch = lMatch._prev );
164         // lMatch always is valid if there are any children
165         self._link = lMatch;
166
167         self._realValue = fabs( self._link.orderPos );
168         String_EntitySet( self, value, ftos( self._realValue ) );
169 };
170
171 void() _IDNA_RawSet =
172 {
173         _IDNA_UpdateLink();
174
175         cmd( "playermodel \"", self._link.target, "\";" );
176         cmd( "playerskin \"", self._link.link, "\"\n" );
177 };
178
179 void() _IDNA_Send =
180 {
181         _IDNA_RawSet();
182
183         String_EntitySet( self, _syncValue, self.value );
184 };
185
186 void() _IDNA_Test_Start =
187 {
188         _IDNA_RawSet();
189 };
190
191 void() _IDNA_Test_End =
192 {
193         String_EntitySet( self, value, self._syncValue );
194         _IDNA_RawSet();
195 };
196
197 void() _IDNA_Reset =
198 {
199         String_EntitySet( self, value, self.defValue );
200         _IDNA_Send();
201 };
202
203 void( float pEvent ) Item_Data_Nex_Avatar_DataEvent =
204 {
205         switch( pEvent ) {
206         case ITEM_DATA_SYNC:
207                 _IDNA_Sync();
208                 break;
209         case ITEM_DATA_SEND:
210                 _IDNA_Send();
211                 break;
212         case ITEM_DATA_RESET:
213                 _IDNA_Reset();
214                 break;
215         case ITEM_DATA_TEST_START:
216                 _IDNA_Test_Start();
217                 break;
218         case ITEM_DATA_TEST_END:
219                 _IDNA_Test_End();
220                 break;
221         case ITEM_DATALINK_SET:
222                 _IDNA_UpdateLink();
223                 break;
224         }
225 };
226
227 void() Item_Data_Nex_Avatar_Spawn =
228 {
229         Item_Data_Init();
230
231         self.flag = self.flag | FLAG_HIDDEN;
232
233         self._reinit = _IDNA_Sync;
234         self._dataEvent = Item_Data_Nex_Avatar_DataEvent;
235
236         _IDNA_BuildList();
237 };