00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "ui_local.h"
00012 #include "../qcommon/qfiles.h"
00013 #include "ui_force.h"
00014
00015 int uiForceSide = FORCE_LIGHTSIDE;
00016 int uiJediNonJedi = -1;
00017 int uiForceRank = FORCE_MASTERY_JEDI_KNIGHT;
00018 int uiMaxRank = MAX_FORCE_RANK;
00019 int uiMaxPoints = 20;
00020 int uiForceUsed = 0;
00021 int uiForceAvailable=0;
00022
00023 extern const char *UI_TeamName(int team);
00024
00025 qboolean gTouchedForce = qfalse;
00026 vmCvar_t ui_freeSaber, ui_forcePowerDisable;
00027
00028 #include "../namespace_begin.h"
00029 void Menu_ShowItemByName(menuDef_t *menu, const char *p, qboolean bShow);
00030 #include "../namespace_end.h"
00031
00032 qboolean uiForcePowersDisabled[NUM_FORCE_POWERS] = {
00033 qfalse,
00034 qfalse,
00035 qfalse,
00036 qfalse,
00037 qfalse,
00038 qfalse,
00039 qfalse,
00040 qfalse,
00041 qfalse,
00042 qfalse,
00043 qfalse,
00044 qfalse,
00045 qfalse,
00046 qfalse,
00047 qfalse,
00048 qfalse,
00049 qfalse,
00050 qfalse
00051 };
00052
00053 int uiForcePowersRank[NUM_FORCE_POWERS] = {
00054 0,
00055 1,
00056 0,
00057 0,
00058 0,
00059 0,
00060 0,
00061 0,
00062 0,
00063 0,
00064 0,
00065 0,
00066 0,
00067 0,
00068 0,
00069 1,
00070 1,
00071 0
00072 };
00073
00074 int uiForcePowerDarkLight[NUM_FORCE_POWERS] =
00075 {
00076 FORCE_LIGHTSIDE,
00077 0,
00078 0,
00079 0,
00080 0,
00081 FORCE_LIGHTSIDE,
00082 FORCE_DARKSIDE,
00083 FORCE_DARKSIDE,
00084 FORCE_DARKSIDE,
00085 FORCE_LIGHTSIDE,
00086 FORCE_LIGHTSIDE,
00087 FORCE_LIGHTSIDE,
00088 FORCE_DARKSIDE,
00089 FORCE_DARKSIDE,
00090 0,
00091 0,
00092 0,
00093 0
00094
00095 };
00096
00097 int uiForceStarShaders[NUM_FORCE_STAR_IMAGES][2];
00098 int uiSaberColorShaders[NUM_SABER_COLORS];
00099 void UI_InitForceShaders(void)
00100 {
00101 uiForceStarShaders[0][0] = trap_R_RegisterShaderNoMip("forcestar0");
00102 uiForceStarShaders[0][1] = trap_R_RegisterShaderNoMip("forcestar0");
00103 uiForceStarShaders[1][0] = trap_R_RegisterShaderNoMip("forcecircle1");
00104 uiForceStarShaders[1][1] = trap_R_RegisterShaderNoMip("forcestar1");
00105 uiForceStarShaders[2][0] = trap_R_RegisterShaderNoMip("forcecircle2");
00106 uiForceStarShaders[2][1] = trap_R_RegisterShaderNoMip("forcestar2");
00107 uiForceStarShaders[3][0] = trap_R_RegisterShaderNoMip("forcecircle3");
00108 uiForceStarShaders[3][1] = trap_R_RegisterShaderNoMip("forcestar3");
00109 uiForceStarShaders[4][0] = trap_R_RegisterShaderNoMip("forcecircle4");
00110 uiForceStarShaders[4][1] = trap_R_RegisterShaderNoMip("forcestar4");
00111 uiForceStarShaders[5][0] = trap_R_RegisterShaderNoMip("forcecircle5");
00112 uiForceStarShaders[5][1] = trap_R_RegisterShaderNoMip("forcestar5");
00113 uiForceStarShaders[6][0] = trap_R_RegisterShaderNoMip("forcecircle6");
00114 uiForceStarShaders[6][1] = trap_R_RegisterShaderNoMip("forcestar6");
00115 uiForceStarShaders[7][0] = trap_R_RegisterShaderNoMip("forcecircle7");
00116 uiForceStarShaders[7][1] = trap_R_RegisterShaderNoMip("forcestar7");
00117 uiForceStarShaders[8][0] = trap_R_RegisterShaderNoMip("forcecircle8");
00118 uiForceStarShaders[8][1] = trap_R_RegisterShaderNoMip("forcestar8");
00119
00120 uiSaberColorShaders[SABER_RED] = trap_R_RegisterShaderNoMip("menu/art/saber_red");
00121 uiSaberColorShaders[SABER_ORANGE] = trap_R_RegisterShaderNoMip("menu/art/saber_orange");
00122 uiSaberColorShaders[SABER_YELLOW] = trap_R_RegisterShaderNoMip("menu/art/saber_yellow");
00123 uiSaberColorShaders[SABER_GREEN] = trap_R_RegisterShaderNoMip("menu/art/saber_green");
00124 uiSaberColorShaders[SABER_BLUE] = trap_R_RegisterShaderNoMip("menu/art/saber_blue");
00125 uiSaberColorShaders[SABER_PURPLE] = trap_R_RegisterShaderNoMip("menu/art/saber_purple");
00126 }
00127
00128
00129 void UI_DrawForceStars(rectDef_t *rect, float scale, vec4_t color, int textStyle, int forceindex, int val, int min, int max)
00130 {
00131 int i,pad = 4;
00132 int xPos,width = 16;
00133 int starcolor;
00134
00135 if (val < min || val > max)
00136 {
00137 val = min;
00138 }
00139
00140 if (1)
00141 {
00142 xPos = rect->x;
00143
00144 for (i=FORCE_LEVEL_1;i<=max;i++)
00145 {
00146 starcolor = bgForcePowerCost[forceindex][i];
00147
00148 if (uiForcePowersDisabled[forceindex])
00149 {
00150 vec4_t grColor = {0.2f, 0.2f, 0.2f, 1.0f};
00151 trap_R_SetColor(grColor);
00152 }
00153
00154 if (val >= i)
00155 {
00156 UI_DrawHandlePic( xPos, rect->y+6, width, width, uiForceStarShaders[starcolor][1] );
00157 }
00158 else
00159 {
00160 UI_DrawHandlePic( xPos, rect->y+6, width, width, uiForceStarShaders[starcolor][0] );
00161 }
00162
00163 if (uiForcePowersDisabled[forceindex])
00164 {
00165 trap_R_SetColor(NULL);
00166 }
00167
00168 xPos += width + pad;
00169 }
00170 }
00171 }
00172
00173
00174 void UI_UpdateClientForcePowers(const char *teamArg)
00175 {
00176 trap_Cvar_Set( "forcepowers", va("%i-%i-%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i%i",
00177 uiForceRank, uiForceSide, uiForcePowersRank[0], uiForcePowersRank[1],
00178 uiForcePowersRank[2], uiForcePowersRank[3], uiForcePowersRank[4],
00179 uiForcePowersRank[5], uiForcePowersRank[6], uiForcePowersRank[7],
00180 uiForcePowersRank[8], uiForcePowersRank[9], uiForcePowersRank[10],
00181 uiForcePowersRank[11], uiForcePowersRank[12], uiForcePowersRank[13],
00182 uiForcePowersRank[14], uiForcePowersRank[15], uiForcePowersRank[16],
00183 uiForcePowersRank[17]) );
00184
00185 if (gTouchedForce)
00186 {
00187 if (teamArg && teamArg[0])
00188 {
00189 trap_Cmd_ExecuteText( EXEC_APPEND, va("forcechanged \"%s\"\n", teamArg) );
00190 }
00191 else
00192 {
00193 trap_Cmd_ExecuteText( EXEC_APPEND, "forcechanged\n" );
00194 }
00195 }
00196
00197 gTouchedForce = qfalse;
00198 }
00199
00200 int UI_TranslateFCFIndex(int index)
00201 {
00202 if (uiForceSide == FORCE_LIGHTSIDE)
00203 {
00204 return index-uiInfo.forceConfigLightIndexBegin;
00205 }
00206
00207 return index-uiInfo.forceConfigDarkIndexBegin;
00208 }
00209
00210 void UI_SaveForceTemplate()
00211 {
00212 char *selectedName = UI_Cvar_VariableString("ui_SaveFCF");
00213 char fcfString[512];
00214 char forceStringValue[4];
00215 fileHandle_t f;
00216 int strPlace = 0;
00217 int forcePlace = 0;
00218 int i = 0;
00219 qboolean foundFeederItem = qfalse;
00220
00221 if (!selectedName || !selectedName[0])
00222 {
00223 Com_Printf("You did not provide a name for the template.\n");
00224 return;
00225 }
00226
00227 if (uiForceSide == FORCE_LIGHTSIDE)
00228 {
00229 trap_FS_FOpenFile(va("forcecfg/light/%s.fcf", selectedName), &f, FS_WRITE);
00230 }
00231 else
00232 {
00233 trap_FS_FOpenFile(va("forcecfg/dark/%s.fcf", selectedName), &f, FS_WRITE);
00234 }
00235
00236 if (!f)
00237 {
00238 Com_Printf("There was an error writing the template file (read-only?).\n");
00239 return;
00240 }
00241
00242 Com_sprintf(fcfString, sizeof(fcfString), "%i-%i-", uiForceRank, uiForceSide);
00243 strPlace = strlen(fcfString);
00244
00245 while (forcePlace < NUM_FORCE_POWERS)
00246 {
00247 Com_sprintf(forceStringValue, sizeof(forceStringValue), "%i", uiForcePowersRank[forcePlace]);
00248
00249 fcfString[strPlace] = forceStringValue[0];
00250 strPlace++;
00251 forcePlace++;
00252 }
00253 fcfString[strPlace] = '\n';
00254 fcfString[strPlace+1] = 0;
00255
00256 trap_FS_Write(fcfString, strlen(fcfString), f);
00257 trap_FS_FCloseFile(f);
00258
00259 Com_Printf("Template saved as \"%s\".\n", selectedName);
00260
00261
00262 UI_LoadForceConfig_List();
00263
00264
00265 while (i < uiInfo.forceConfigCount)
00266 {
00267 if (!Q_stricmp(uiInfo.forceConfigNames[i], selectedName))
00268 {
00269 if ((uiForceSide == FORCE_LIGHTSIDE && uiInfo.forceConfigSide[i]) ||
00270 (uiForceSide == FORCE_DARKSIDE && !uiInfo.forceConfigSide[i]))
00271 {
00272 Menu_SetFeederSelection(NULL, FEEDER_FORCECFG, UI_TranslateFCFIndex(i), NULL);
00273 foundFeederItem = qtrue;
00274 }
00275 }
00276
00277 i++;
00278 }
00279
00280
00281 if (!foundFeederItem)
00282 {
00283 Menu_SetFeederSelection(NULL, FEEDER_FORCECFG, 0, NULL);
00284 }
00285 }
00286
00287
00288
00289 extern qboolean UI_TrueJediEnabled( void );
00290 void UpdateForceUsed()
00291 {
00292 int curpower, currank;
00293 menuDef_t *menu;
00294
00295
00296 uiForceRank = uiMaxRank;
00297
00298 uiForceUsed = 0;
00299 uiForceAvailable = forceMasteryPoints[uiForceRank];
00300
00301
00302 if (uiForcePowersRank[FP_LEVITATION]<1)
00303 {
00304 uiForcePowersRank[FP_LEVITATION]=1;
00305 }
00306
00307 if ( UI_TrueJediEnabled() )
00308 {
00309 if ( uiJediNonJedi == -1 )
00310 {
00311 int x = 0;
00312 qboolean clear = qfalse, update = qfalse;
00313 uiJediNonJedi = FORCE_NONJEDI;
00314 while ( x < NUM_FORCE_POWERS )
00315 {
00316 if ( x == FP_LEVITATION || x == FP_SABER_OFFENSE )
00317 {
00318 if ( uiForcePowersRank[x] > 1 )
00319 {
00320 uiJediNonJedi = FORCE_JEDI;
00321 break;
00322 }
00323 else if ( uiForcePowersRank[x] > 0 )
00324 {
00325 clear = qtrue;
00326 }
00327 }
00328 else if ( uiForcePowersRank[x] > 0 )
00329 {
00330 uiJediNonJedi = FORCE_JEDI;
00331 break;
00332 }
00333 x++;
00334 }
00335 if ( uiJediNonJedi == FORCE_JEDI )
00336 {
00337 if ( uiForcePowersRank[FP_SABER_OFFENSE] < 1 )
00338 {
00339 uiForcePowersRank[FP_SABER_OFFENSE]=1;
00340 update = qtrue;
00341 }
00342 }
00343 else if ( clear )
00344 {
00345 x = 0;
00346 while ( x < NUM_FORCE_POWERS )
00347 {
00348 uiForcePowersRank[x] = 0;
00349 x++;
00350 }
00351 update = qtrue;
00352 }
00353 if ( update )
00354 {
00355 int myTeam;
00356 myTeam = (int)(trap_Cvar_VariableValue("ui_myteam"));
00357 if ( myTeam != TEAM_SPECTATOR )
00358 {
00359 UI_UpdateClientForcePowers(UI_TeamName(myTeam));
00360 }
00361 else
00362 {
00363 UI_UpdateClientForcePowers(NULL);
00364 }
00365 }
00366 }
00367 }
00368
00369 menu = Menus_FindByName("ingame_playerforce");
00370
00371 if (ui_freeSaber.integer)
00372 {
00373 bgForcePowerCost[FP_SABER_OFFENSE][FORCE_LEVEL_1] = 0;
00374 bgForcePowerCost[FP_SABER_DEFENSE][FORCE_LEVEL_1] = 0;
00375
00376 if (uiForcePowersRank[FP_SABER_OFFENSE]<1)
00377 {
00378 uiForcePowersRank[FP_SABER_OFFENSE]=1;
00379 }
00380 if (uiForcePowersRank[FP_SABER_DEFENSE]<1)
00381 {
00382 uiForcePowersRank[FP_SABER_DEFENSE]=1;
00383 }
00384 if (menu)
00385 {
00386 Menu_ShowItemByName(menu, "setFP_SABER_DEFENSE", qtrue);
00387 Menu_ShowItemByName(menu, "setfp_saberthrow", qtrue);
00388 Menu_ShowItemByName(menu, "effectentry", qtrue);
00389 Menu_ShowItemByName(menu, "effectfield", qtrue);
00390 Menu_ShowItemByName(menu, "nosaber", qfalse);
00391 }
00392 }
00393 else
00394 {
00395 bgForcePowerCost[FP_SABER_OFFENSE][FORCE_LEVEL_1] = 1;
00396 bgForcePowerCost[FP_SABER_DEFENSE][FORCE_LEVEL_1] = 1;
00397
00398 if (uiForcePowersRank[FP_SABER_OFFENSE]<1)
00399 {
00400 uiForcePowersRank[FP_SABER_DEFENSE]=0;
00401 uiForcePowersRank[FP_SABERTHROW]=0;
00402 if (menu)
00403 {
00404 Menu_ShowItemByName(menu, "setfp_saberdefend", qfalse);
00405 Menu_ShowItemByName(menu, "setfp_saberthrow", qfalse);
00406 Menu_ShowItemByName(menu, "effectentry", qfalse);
00407 Menu_ShowItemByName(menu, "effectfield", qfalse);
00408 Menu_ShowItemByName(menu, "nosaber", qtrue);
00409 }
00410 }
00411 else
00412 {
00413 if (menu)
00414 {
00415 Menu_ShowItemByName(menu, "setfp_saberdefend", qtrue);
00416 Menu_ShowItemByName(menu, "setfp_saberthrow", qtrue);
00417 Menu_ShowItemByName(menu, "effectentry", qtrue);
00418 Menu_ShowItemByName(menu, "effectfield", qtrue);
00419 Menu_ShowItemByName(menu, "nosaber", qfalse);
00420 }
00421 }
00422 }
00423
00424
00425 for (curpower=0;curpower<NUM_FORCE_POWERS;curpower++)
00426 {
00427 if (uiForcePowersRank[curpower]<0)
00428 uiForcePowersRank[curpower]=0;
00429 else if (uiForcePowersRank[curpower]>=NUM_FORCE_POWER_LEVELS)
00430 uiForcePowersRank[curpower]=(NUM_FORCE_POWER_LEVELS-1);
00431
00432 for (currank=FORCE_LEVEL_1;currank<=uiForcePowersRank[curpower];currank++)
00433 {
00434 if (uiForcePowersRank[curpower]>0)
00435 {
00436 if ( (curpower == FP_LEVITATION && currank == FORCE_LEVEL_1) ||
00437 (curpower == FP_SABER_OFFENSE && currank == FORCE_LEVEL_1 && ui_freeSaber.integer) ||
00438 (curpower == FP_SABER_DEFENSE && currank == FORCE_LEVEL_1 && ui_freeSaber.integer) )
00439 {
00440
00441 }
00442 else
00443 {
00444 if (bgForcePowerCost[curpower][currank] > uiForceAvailable)
00445 {
00446
00447 uiForcePowersRank[curpower] = currank-1;
00448 break;
00449 }
00450 else
00451 {
00452 uiForceUsed += bgForcePowerCost[curpower][currank];
00453 uiForceAvailable -= bgForcePowerCost[curpower][currank];
00454 }
00455 }
00456 }
00457 }
00458 }
00459
00460 }
00461
00462
00463
00464
00465 void UI_ReadLegalForce(void)
00466 {
00467 char fcfString[512];
00468 char forceStringValue[4];
00469 int strPlace = 0;
00470 int forcePlace = 0;
00471 int i = 0;
00472 char singleBuf[64];
00473 char info[MAX_INFO_VALUE];
00474 int c = 0;
00475 int iBuf = 0;
00476 int forcePowerRank = 0;
00477 int currank = 0;
00478 int forceTeam = 0;
00479 qboolean updateForceLater = qfalse;
00480
00481
00482 Com_sprintf(fcfString, sizeof(fcfString), "%i-%i-", uiForceRank, uiForceSide);
00483 strPlace = strlen(fcfString);
00484
00485 while (forcePlace < NUM_FORCE_POWERS)
00486 {
00487 Com_sprintf(forceStringValue, sizeof(forceStringValue), "%i", uiForcePowersRank[forcePlace]);
00488
00489 fcfString[strPlace] = forceStringValue[0];
00490 strPlace++;
00491 forcePlace++;
00492 }
00493 fcfString[strPlace] = '\n';
00494 fcfString[strPlace+1] = 0;
00495
00496 info[0] = '\0';
00497 trap_GetConfigString(CS_SERVERINFO, info, sizeof(info));
00498
00499 if (atoi( Info_ValueForKey( info, "g_forceBasedTeams" ) ))
00500 {
00501 switch((int)(trap_Cvar_VariableValue("ui_myteam")))
00502 {
00503 case TEAM_RED:
00504 forceTeam = FORCE_DARKSIDE;
00505 break;
00506 case TEAM_BLUE:
00507 forceTeam = FORCE_LIGHTSIDE;
00508 break;
00509 default:
00510 break;
00511 }
00512 }
00513
00514 if (!BG_LegalizedForcePowers(fcfString, uiMaxRank, ui_freeSaber.integer, forceTeam, atoi( Info_ValueForKey( info, "g_gametype" )), 0))
00515 {
00516 updateForceLater = qtrue;
00517 }
00518
00519
00520 i = 0;
00521
00522 while (fcfString[i] && fcfString[i] != '-')
00523 {
00524 singleBuf[c] = fcfString[i];
00525 c++;
00526 i++;
00527 }
00528 singleBuf[c] = 0;
00529 c = 0;
00530 i++;
00531
00532 iBuf = atoi(singleBuf);
00533
00534 if (iBuf > uiMaxRank || iBuf < 0)
00535 {
00536
00537
00538 }
00539
00540 uiForceRank = iBuf;
00541
00542 while (fcfString[i] && fcfString[i] != '-')
00543 {
00544 singleBuf[c] = fcfString[i];
00545 c++;
00546 i++;
00547 }
00548 singleBuf[c] = 0;
00549 c = 0;
00550 i++;
00551
00552 uiForceSide = atoi(singleBuf);
00553
00554 if (uiForceSide != FORCE_LIGHTSIDE &&
00555 uiForceSide != FORCE_DARKSIDE)
00556 {
00557 uiForceSide = FORCE_LIGHTSIDE;
00558 return;
00559 }
00560
00561
00562 while (c < NUM_FORCE_POWERS)
00563 {
00564 uiForcePowersRank[c] = 0;
00565 c++;
00566 }
00567 uiForceUsed = 0;
00568 uiForceAvailable = forceMasteryPoints[uiForceRank];
00569 gTouchedForce = qtrue;
00570
00571 for (c=0;fcfString[i]&&c<NUM_FORCE_POWERS;c++,i++)
00572 {
00573 singleBuf[0] = fcfString[i];
00574 singleBuf[1] = 0;
00575 iBuf = atoi(singleBuf);
00576
00577 if (iBuf < 0)
00578 {
00579 iBuf = 0;
00580 }
00581
00582 forcePowerRank = iBuf;
00583
00584 if (forcePowerRank > FORCE_LEVEL_3 || forcePowerRank < 0)
00585 {
00586 continue;
00587 }
00588
00589 if (uiForcePowerDarkLight[c] && uiForcePowerDarkLight[c] != uiForceSide)
00590 {
00591 continue;
00592 }
00593
00594
00595 for (currank=FORCE_LEVEL_1;currank<=forcePowerRank;currank++)
00596 {
00597 if (bgForcePowerCost[c][currank] > uiForceAvailable)
00598 {
00599 break;
00600 }
00601
00602 uiForceUsed += bgForcePowerCost[c][currank];
00603 uiForceAvailable -= bgForcePowerCost[c][currank];
00604
00605 uiForcePowersRank[c]++;
00606 }
00607 }
00608
00609 if (uiForcePowersRank[FP_LEVITATION] < 1)
00610 {
00611 uiForcePowersRank[FP_LEVITATION]=1;
00612 }
00613 if (uiForcePowersRank[FP_SABER_OFFENSE] < 1 && ui_freeSaber.integer)
00614 {
00615 uiForcePowersRank[FP_SABER_OFFENSE]=1;
00616 }
00617 if (uiForcePowersRank[FP_SABER_DEFENSE] < 1 && ui_freeSaber.integer)
00618 {
00619 uiForcePowersRank[FP_SABER_DEFENSE]=1;
00620 }
00621
00622 UpdateForceUsed();
00623
00624 if (updateForceLater)
00625 {
00626 gTouchedForce = qtrue;
00627 UI_UpdateClientForcePowers(NULL);
00628 }
00629 }
00630
00631 void UI_UpdateForcePowers()
00632 {
00633 char *forcePowers = UI_Cvar_VariableString("forcepowers");
00634 char readBuf[256];
00635 int i = 0, i_f = 0, i_r = 0;
00636
00637 uiForceSide = 0;
00638
00639 if (forcePowers && forcePowers[0])
00640 {
00641 while (forcePowers[i])
00642 {
00643 i_r = 0;
00644
00645 while (forcePowers[i] && forcePowers[i] != '-' && i_r < 255)
00646 {
00647 readBuf[i_r] = forcePowers[i];
00648 i_r++;
00649 i++;
00650 }
00651 readBuf[i_r] = '\0';
00652 if (i_r >= 255 || !forcePowers[i] || forcePowers[i] != '-')
00653 {
00654 uiForceSide = 0;
00655 goto validitycheck;
00656 }
00657 uiForceRank = atoi(readBuf);
00658 i_r = 0;
00659
00660 if (uiForceRank > uiMaxRank)
00661 {
00662 uiForceRank = uiMaxRank;
00663 }
00664
00665 i++;
00666
00667 while (forcePowers[i] && forcePowers[i] != '-' && i_r < 255)
00668 {
00669 readBuf[i_r] = forcePowers[i];
00670 i_r++;
00671 i++;
00672 }
00673 readBuf[i_r] = '\0';
00674 if (i_r >= 255 || !forcePowers[i] || forcePowers[i] != '-')
00675 {
00676 uiForceSide = 0;
00677 goto validitycheck;
00678 }
00679 uiForceSide = atoi(readBuf);
00680 i_r = 0;
00681
00682 i++;
00683
00684 i_f = FP_HEAL;
00685
00686 while (forcePowers[i] && i_f < NUM_FORCE_POWERS)
00687 {
00688 readBuf[0] = forcePowers[i];
00689 readBuf[1] = '\0';
00690 uiForcePowersRank[i_f] = atoi(readBuf);
00691
00692 if (i_f == FP_LEVITATION &&
00693 uiForcePowersRank[i_f] < 1)
00694 {
00695 uiForcePowersRank[i_f] = 1;
00696 }
00697
00698 if (i_f == FP_SABER_OFFENSE &&
00699 uiForcePowersRank[i_f] < 1 &&
00700 ui_freeSaber.integer)
00701 {
00702 uiForcePowersRank[i_f] = 1;
00703 }
00704
00705 if (i_f == FP_SABER_DEFENSE &&
00706 uiForcePowersRank[i_f] < 1 &&
00707 ui_freeSaber.integer)
00708 {
00709 uiForcePowersRank[i_f] = 1;
00710 }
00711
00712 i_f++;
00713 i++;
00714 }
00715
00716 if (i_f < NUM_FORCE_POWERS)
00717 {
00718 uiForceSide = 0;
00719 goto validitycheck;
00720 }
00721 i++;
00722 }
00723 }
00724
00725 validitycheck:
00726
00727 if (!uiForceSide)
00728 {
00729 uiForceSide = 1;
00730 uiForceRank = 1;
00731 i = 0;
00732 while (i < NUM_FORCE_POWERS)
00733 {
00734 if (i == FP_LEVITATION)
00735 {
00736 uiForcePowersRank[i] = 1;
00737 }
00738 else if (i == FP_SABER_OFFENSE && ui_freeSaber.integer)
00739 {
00740 uiForcePowersRank[i] = 1;
00741 }
00742 else if (i == FP_SABER_DEFENSE && ui_freeSaber.integer)
00743 {
00744 uiForcePowersRank[i] = 1;
00745 }
00746 else
00747 {
00748 uiForcePowersRank[i] = 0;
00749 }
00750
00751 i++;
00752 }
00753
00754 UI_UpdateClientForcePowers(NULL);
00755 }
00756
00757 UpdateForceUsed();
00758 }
00759 extern int uiSkinColor;
00760 extern int uiHoldSkinColor;
00761
00762 qboolean UI_SkinColor_HandleKey(int flags, float *special, int key, int num, int min, int max, int type)
00763 {
00764 if (key == A_MOUSE1 || key == A_MOUSE2 || key == A_ENTER || key == A_KP_ENTER)
00765 {
00766 int i = num;
00767
00768 if (key == A_MOUSE2)
00769 {
00770 i--;
00771 }
00772 else
00773 {
00774 i++;
00775 }
00776
00777 if (i < min)
00778 {
00779 i = max;
00780 }
00781 else if (i > max)
00782 {
00783 i = min;
00784 }
00785
00786 num = i;
00787
00788 uiSkinColor = num;
00789
00790 uiHoldSkinColor = uiSkinColor;
00791
00792 UI_FeederSelection(FEEDER_Q3HEADS, uiInfo.q3SelectedHead, NULL);
00793
00794 return qtrue;
00795 }
00796 return qfalse;
00797 }
00798
00799
00800
00801
00802 qboolean UI_ForceSide_HandleKey(int flags, float *special, int key, int num, int min, int max, int type)
00803 {
00804 char info[MAX_INFO_VALUE];
00805
00806 info[0] = '\0';
00807 trap_GetConfigString(CS_SERVERINFO, info, sizeof(info));
00808
00809 if (atoi( Info_ValueForKey( info, "g_forceBasedTeams" ) ))
00810 {
00811 switch((int)(trap_Cvar_VariableValue("ui_myteam")))
00812 {
00813 case TEAM_RED:
00814 return qfalse;
00815 case TEAM_BLUE:
00816 return qfalse;
00817 default:
00818 break;
00819 }
00820 }
00821
00822 if (key == A_MOUSE1 || key == A_MOUSE2 || key == A_ENTER || key == A_KP_ENTER)
00823 {
00824 int i = num;
00825 int x = 0;
00826
00827
00828 Menu_SetFeederSelection(NULL, FEEDER_FORCECFG, 0, NULL);
00829
00830 if (key == A_MOUSE2)
00831 {
00832 i--;
00833 }
00834 else
00835 {
00836 i++;
00837 }
00838
00839 if (i < min)
00840 {
00841 i = max;
00842 }
00843 else if (i > max)
00844 {
00845 i = min;
00846 }
00847
00848 num = i;
00849
00850 uiForceSide = num;
00851
00852
00853 while (x < NUM_FORCE_POWERS)
00854 {
00855 if (uiForcePowerDarkLight[x] && uiForceSide != uiForcePowerDarkLight[x])
00856 {
00857 uiForcePowersRank[x] = 0;
00858 }
00859 x++;
00860 }
00861
00862 UpdateForceUsed();
00863
00864 gTouchedForce = qtrue;
00865 return qtrue;
00866 }
00867 return qfalse;
00868 }
00869
00870 qboolean UI_JediNonJedi_HandleKey(int flags, float *special, int key, int num, int min, int max, int type)
00871 {
00872 char info[MAX_INFO_VALUE];
00873
00874 info[0] = '\0';
00875 trap_GetConfigString(CS_SERVERINFO, info, sizeof(info));
00876
00877 if ( !UI_TrueJediEnabled() )
00878 {
00879 return qfalse;
00880 }
00881
00882 if (key == A_MOUSE1 || key == A_MOUSE2 || key == A_ENTER || key == A_KP_ENTER)
00883 {
00884 int i = num;
00885 int x = 0;
00886
00887 if (key == A_MOUSE2)
00888 {
00889 i--;
00890 }
00891 else
00892 {
00893 i++;
00894 }
00895
00896 if (i < min)
00897 {
00898 i = max;
00899 }
00900 else if (i > max)
00901 {
00902 i = min;
00903 }
00904
00905 num = i;
00906
00907 uiJediNonJedi = num;
00908
00909
00910 if ( !num )
00911 {
00912 int myTeam = (int)(trap_Cvar_VariableValue("ui_myteam"));
00913 while ( x < NUM_FORCE_POWERS )
00914 {
00915 uiForcePowersRank[x] = 0;
00916 x++;
00917 }
00918 if ( myTeam != TEAM_SPECTATOR )
00919 {
00920 UI_UpdateClientForcePowers(UI_TeamName(myTeam));
00921 }
00922 else
00923 {
00924 UI_UpdateClientForcePowers(NULL);
00925 }
00926 }
00927 else if ( num )
00928 {
00929 if ( uiForcePowersRank[FP_LEVITATION] < FORCE_LEVEL_1 )
00930 {
00931 uiForcePowersRank[FP_LEVITATION] = FORCE_LEVEL_1;
00932 }
00933 if ( uiForcePowersRank[FP_SABER_OFFENSE] < FORCE_LEVEL_1 )
00934 {
00935 uiForcePowersRank[FP_SABER_OFFENSE] = FORCE_LEVEL_1;
00936 }
00937 }
00938
00939 UpdateForceUsed();
00940
00941 gTouchedForce = qtrue;
00942 return qtrue;
00943 }
00944 return qfalse;
00945 }
00946
00947 qboolean UI_ForceMaxRank_HandleKey(int flags, float *special, int key, int num, int min, int max, int type)
00948 {
00949 if (key == A_MOUSE1 || key == A_MOUSE2 || key == A_ENTER || key == A_KP_ENTER)
00950 {
00951 int i = num;
00952
00953 if (key == A_MOUSE2)
00954 {
00955 i--;
00956 }
00957 else
00958 {
00959 i++;
00960 }
00961
00962 if (i < min)
00963 {
00964 i = max;
00965 }
00966 else if (i > max)
00967 {
00968 i = min;
00969 }
00970
00971 num = i;
00972
00973 uiMaxRank = num;
00974
00975 trap_Cvar_Set( "g_maxForceRank", va("%i", num));
00976
00977
00978 UpdateForceUsed();
00979
00980 gTouchedForce = qtrue;
00981
00982 return qtrue;
00983 }
00984 return qfalse;
00985 }
00986
00987
00988
00989 qboolean UI_ForcePowerRank_HandleKey(int flags, float *special, int key, int num, int min, int max, int type)
00990 {
00991 qboolean raising;
00992
00993 if (key == A_MOUSE1 || key == A_MOUSE2 || key == A_ENTER || key == A_KP_ENTER || key == A_BACKSPACE)
00994 {
00995 int forcepower, rank;
00996
00997
00998 forcepower = (type-UI_FORCE_RANK)-1;
00999
01000
01001 if (uiForcePowersDisabled[forcepower])
01002 {
01003 return qtrue;
01004 }
01005
01006
01007 if (uiForcePowerDarkLight[forcepower] && uiForceSide != uiForcePowerDarkLight[forcepower])
01008 {
01009 return qtrue;
01010 }
01011 else if (forcepower == FP_SABER_DEFENSE || forcepower == FP_SABERTHROW)
01012 {
01013 if (uiForcePowersRank[FP_SABER_OFFENSE] < 1)
01014 {
01015 return qtrue;
01016 }
01017 }
01018
01019 if (type == UI_FORCE_RANK_LEVITATION)
01020 {
01021 min += 1;
01022 }
01023 if (type == UI_FORCE_RANK_SABERATTACK && ui_freeSaber.integer)
01024 {
01025 min += 1;
01026 }
01027 if (type == UI_FORCE_RANK_SABERDEFEND && ui_freeSaber.integer)
01028 {
01029 min += 1;
01030 }
01031
01032 if (key == A_MOUSE2 || key == A_BACKSPACE)
01033 {
01034 if (uiForcePowersRank[forcepower]<=min)
01035 {
01036 return qtrue;
01037 }
01038 raising = qfalse;
01039 }
01040 else
01041 {
01042 if (uiForcePowersRank[forcepower]>=max)
01043 {
01044 return qtrue;
01045 }
01046 raising = qtrue;
01047 }
01048
01049 if (raising)
01050 {
01051 rank = uiForcePowersRank[forcepower]+1;
01052 if (bgForcePowerCost[forcepower][rank] > uiForceAvailable)
01053 {
01054 return qtrue;
01055 }
01056 else
01057 {
01058 uiForceUsed += bgForcePowerCost[forcepower][rank];
01059 uiForceAvailable -= bgForcePowerCost[forcepower][rank];
01060 uiForcePowersRank[forcepower]=rank;
01061 }
01062 }
01063 else
01064 {
01065 rank = uiForcePowersRank[forcepower];
01066 uiForceUsed -= bgForcePowerCost[forcepower][rank];
01067 uiForceAvailable += bgForcePowerCost[forcepower][rank];
01068 uiForcePowersRank[forcepower]--;
01069 }
01070
01071 UpdateForceUsed();
01072
01073 gTouchedForce = qtrue;
01074
01075 return qtrue;
01076 }
01077 return qfalse;
01078 }
01079
01080
01081 int gCustRank = 0;
01082 int gCustSide = 0;
01083
01084 int gCustPowersRank[NUM_FORCE_POWERS] = {
01085 0,
01086 1,
01087 0,
01088 0,
01089 0,
01090 0,
01091 0,
01092 0,
01093 0,
01094 0,
01095 0,
01096 0,
01097 0,
01098 0,
01099 0,
01100 0,
01101 0,
01102 0
01103 };
01104
01105
01106
01107
01108
01109
01110 void UI_ForceConfigHandle( int oldindex, int newindex )
01111 {
01112 fileHandle_t f;
01113 int len = 0;
01114 int i = 0;
01115 int c = 0;
01116 int iBuf = 0, forcePowerRank, currank;
01117 char fcfBuffer[8192];
01118 char singleBuf[64];
01119 char info[MAX_INFO_VALUE];
01120 int forceTeam = 0;
01121
01122 if (oldindex == 0)
01123 {
01124 i = 0;
01125
01126 while (i < NUM_FORCE_POWERS)
01127 {
01128 gCustPowersRank[i] = uiForcePowersRank[i];
01129 i++;
01130 }
01131 gCustRank = uiForceRank;
01132 gCustSide = uiForceSide;
01133 }
01134
01135 if (newindex == 0)
01136 {
01137 i = 0;
01138 uiForceUsed = 0;
01139 gTouchedForce = qtrue;
01140
01141 while (i < NUM_FORCE_POWERS)
01142 {
01143 uiForcePowersRank[i] = gCustPowersRank[i];
01144 uiForceUsed += uiForcePowersRank[i];
01145 i++;
01146 }
01147 uiForceRank = gCustRank;
01148 uiForceSide = gCustSide;
01149
01150 UpdateForceUsed();
01151 return;
01152 }
01153
01154
01155 if (uiForceSide == FORCE_LIGHTSIDE)
01156 {
01157 newindex += uiInfo.forceConfigLightIndexBegin;
01158 if (newindex >= uiInfo.forceConfigCount)
01159 {
01160 return;
01161 }
01162 len = trap_FS_FOpenFile(va("forcecfg/light/%s.fcf", uiInfo.forceConfigNames[newindex]), &f, FS_READ);
01163 }
01164 else
01165 {
01166 newindex += uiInfo.forceConfigDarkIndexBegin;
01167 if (newindex >= uiInfo.forceConfigCount || newindex > uiInfo.forceConfigLightIndexBegin)
01168 {
01169 return;
01170 }
01171 len = trap_FS_FOpenFile(va("forcecfg/dark/%s.fcf", uiInfo.forceConfigNames[newindex]), &f, FS_READ);
01172 }
01173
01174 if (len <= 0)
01175 {
01176 if (uiForceSide == FORCE_LIGHTSIDE)
01177 {
01178 len = trap_FS_FOpenFile(va("forcecfg/dark/%s.fcf", uiInfo.forceConfigNames[newindex]), &f, FS_READ);
01179 }
01180 else
01181 {
01182 len = trap_FS_FOpenFile(va("forcecfg/light/%s.fcf", uiInfo.forceConfigNames[newindex]), &f, FS_READ);
01183 }
01184
01185 if (len <= 0)
01186 {
01187 return;
01188 }
01189 }
01190
01191 if (len >= 8192)
01192 {
01193 return;
01194 }
01195
01196 trap_FS_Read(fcfBuffer, len, f);
01197 fcfBuffer[len] = 0;
01198 trap_FS_FCloseFile(f);
01199
01200 i = 0;
01201
01202 info[0] = '\0';
01203 trap_GetConfigString(CS_SERVERINFO, info, sizeof(info));
01204
01205 if (atoi( Info_ValueForKey( info, "g_forceBasedTeams" ) ))
01206 {
01207 switch((int)(trap_Cvar_VariableValue("ui_myteam")))
01208 {
01209 case TEAM_RED:
01210 forceTeam = FORCE_DARKSIDE;
01211 break;
01212 case TEAM_BLUE:
01213 forceTeam = FORCE_LIGHTSIDE;
01214 break;
01215 default:
01216 break;
01217 }
01218 }
01219
01220 BG_LegalizedForcePowers(fcfBuffer, uiMaxRank, ui_freeSaber.integer, forceTeam, atoi( Info_ValueForKey( info, "g_gametype" )), 0);
01221
01222
01223
01224
01225 while (fcfBuffer[i] && fcfBuffer[i] != '-')
01226 {
01227 singleBuf[c] = fcfBuffer[i];
01228 c++;
01229 i++;
01230 }
01231 singleBuf[c] = 0;
01232 c = 0;
01233 i++;
01234
01235 iBuf = atoi(singleBuf);
01236
01237 if (iBuf > uiMaxRank || iBuf < 0)
01238 {
01239
01240 return;
01241 }
01242
01243 uiForceRank = iBuf;
01244
01245 while (fcfBuffer[i] && fcfBuffer[i] != '-')
01246 {
01247 singleBuf[c] = fcfBuffer[i];
01248 c++;
01249 i++;
01250 }
01251 singleBuf[c] = 0;
01252 c = 0;
01253 i++;
01254
01255 uiForceSide = atoi(singleBuf);
01256
01257 if (uiForceSide != FORCE_LIGHTSIDE &&
01258 uiForceSide != FORCE_DARKSIDE)
01259 {
01260 uiForceSide = FORCE_LIGHTSIDE;
01261 return;
01262 }
01263
01264
01265 while (c < NUM_FORCE_POWERS)
01266 {
01267
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286 uiForcePowersRank[c] = 0;
01287 c++;
01288 }
01289 uiForceUsed = 0;
01290 uiForceAvailable = forceMasteryPoints[uiForceRank];
01291 gTouchedForce = qtrue;
01292
01293 for (c=0;fcfBuffer[i]&&c<NUM_FORCE_POWERS;c++,i++)
01294 {
01295 singleBuf[0] = fcfBuffer[i];
01296 singleBuf[1] = 0;
01297 iBuf = atoi(singleBuf);
01298
01299 if (iBuf < 0)
01300 {
01301 iBuf = 0;
01302 }
01303
01304 forcePowerRank = iBuf;
01305
01306 if (forcePowerRank > FORCE_LEVEL_3 || forcePowerRank < 0)
01307 {
01308 continue;
01309 }
01310
01311 if (uiForcePowerDarkLight[c] && uiForcePowerDarkLight[c] != uiForceSide)
01312 {
01313 continue;
01314 }
01315
01316
01317 for (currank=FORCE_LEVEL_1;currank<=forcePowerRank;currank++)
01318 {
01319 if (bgForcePowerCost[c][currank] > uiForceAvailable)
01320 {
01321 break;
01322 }
01323
01324 uiForceUsed += bgForcePowerCost[c][currank];
01325 uiForceAvailable -= bgForcePowerCost[c][currank];
01326
01327 uiForcePowersRank[c]++;
01328 }
01329 }
01330
01331 if (uiForcePowersRank[FP_LEVITATION] < 1)
01332 {
01333 uiForcePowersRank[FP_LEVITATION]=1;
01334 }
01335 if (uiForcePowersRank[FP_SABER_OFFENSE] < 1 && ui_freeSaber.integer)
01336 {
01337 uiForcePowersRank[FP_SABER_OFFENSE]=1;
01338 }
01339 if (uiForcePowersRank[FP_SABER_DEFENSE] < 1 && ui_freeSaber.integer)
01340 {
01341 uiForcePowersRank[FP_SABER_DEFENSE]=1;
01342 }
01343
01344 UpdateForceUsed();
01345 }