home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58b_TRIBES.iso / Tribes / base / scripts.vol / client.cs < prev    next >
Encoding:
Text File  |  1998-12-16  |  13.2 KB  |  622 lines

  1. //----------------------------------------------------------------------------
  2. // Client side convience scripts
  3. //
  4. function buy(%desc)
  5. {
  6.     %type = getItemType(%desc);
  7.     if (%type != -1) {
  8.         remoteEval(2048,buyItem,%type);
  9.     }
  10.     else {
  11.         echo("Unknown item \"" @ %desc @ "\"");
  12.     }
  13. }
  14.  
  15. function markFavorites()
  16. {
  17.     // Currently done by the shell
  18. }
  19.  
  20. function remoteSetInfoLine(%mgr, %lineNum, %text)
  21. {
  22.    if(%mgr != 2048)
  23.       return;
  24.  
  25.     if (%lineNum == 1)
  26.     {
  27.         if (%text == "") Control::setVisible(InfoCtrlBox, FALSE);
  28.         else Control::setVisible(InfoCtrlBox, TRUE);
  29.     }
  30.  
  31.    Control::setText("InfoCtrlLine" @ %lineNum, %text);
  32. }
  33.  
  34.  
  35. function buyFavorites()
  36. {
  37.     // This function is invoked by the shell.
  38.     for (%i = 0; %i < 20; %i = %i + 1) {
  39.         if ($pref::itemFavorite[%i] != "") {
  40.             %type = getItemType($pref::itemFavorite[%i]);
  41.             if (%type != -1) {
  42.                 %list = %list @ "," @ %type;
  43.             }
  44.         }
  45.     }
  46.     if (%list != "") {
  47.         eval("remoteEval(2048,buyFavorites" @ %list @ ");");
  48.     }
  49. }    
  50.  
  51. function sell(%desc)
  52. {
  53.     %type = getItemType(%desc);
  54.     if (%type != -1) {
  55.         remoteEval(2048,sellItem,%type);
  56.     }
  57.     else {
  58.         echo("Unknown item \"" @ %desc @ "\"");
  59.     }
  60. }
  61.  
  62. function use(%desc)
  63. {
  64.     %type = getItemType(%desc);
  65.     if (%type != -1) {
  66.         // The client useItem function will make sure the use is
  67.         // sequenced correctly with trigger events.  The remoteEval
  68.         // works fine but may be delivered out of order.
  69.         // remoteEval(2048,useItem,%type);
  70.         useItem(%type);
  71.     }
  72.     else {
  73.         echo("Unknown item \"" @ %desc @ "\"");
  74.     }
  75. }
  76.  
  77. function drop(%desc)
  78. {
  79.     %type = getItemType(%desc);
  80.     if (%type != -1) {
  81.         remoteEval(2048,dropItem,%type);
  82.     }
  83.     else {
  84.         echo("Unknown item \"" @ %desc @ "\"");
  85.     }
  86. }
  87.  
  88. function throwStart()
  89. {
  90.     $throwStartTime = getSimTime();
  91. }
  92.  
  93. function throwRelease(%desc)
  94. {
  95.     %type = getItemType(%desc);
  96.     if (%type != -1) {
  97.         %delta = getSimTime() - $throwStartTime;
  98.         if (%delta > 1)
  99.             %delta = 100;
  100.         else
  101.             %delta = floor(%delta * 100);
  102.         remoteEval(2048,throwItem,%type,%delta);
  103.     }
  104.     else {
  105.         echo("Unknown item \"" @ %desc @ "\"");
  106.     }
  107. }
  108.  
  109. function deploy(%desc)
  110. {
  111.     %type = getItemType(%desc);
  112.     if (%type != -1) {
  113.         remoteEval(2048,deployItem,%type);
  114.     }
  115.     else {
  116.         echo("Unknown item \"" @ %desc @ "\"");
  117.     }
  118. }
  119.  
  120. function nextWeapon()
  121. {
  122.     // Up to the server right now
  123.     remoteEval(2048,nextWeapon);
  124. }    
  125.  
  126. function prevWeapon()
  127. {
  128.     // Up to the server right now
  129.     remoteEval(2048,prevWeapon);
  130. }
  131.  
  132. function commandAck()
  133. {
  134.     // Placed here to avoid binding problems with gui.
  135.     remoteEval(2048,CStatus,1,"Command Acknowledged~wacknow");
  136. }
  137.  
  138. function commandDeclined()
  139. {
  140.     // Placed here to avoid binding problems with gui.
  141.     remoteEval(2048,CStatus,0,"Unable to complete objective~wobjxcmp");
  142. }
  143.  
  144. function CommandCompleted()
  145. {
  146.     // Placed here to avoid binding problems with gui.
  147.     remoteEval(2048,CStatus,0,"Objective Completed~wobjcomp");
  148. }
  149.  
  150. function Client::filterMessage(%client, %msg)
  151. {
  152.    // filter messages here
  153.    return true;
  154. }
  155.  
  156. function clearCenterPrint(%id)
  157. {
  158.    if(%id == $centerPrintId)
  159.       Client::centerPrint("", 0);
  160. }
  161.  
  162. function remoteITXT(%manager, %msg)
  163. {
  164.    if(%manager == 2048)
  165.       Control::setValue(EnergyDisplayText, %msg);
  166. }
  167.  
  168. function remoteCP(%manager, %msg, %timeout)
  169. {
  170.    if(%manager == 2048)
  171.    {
  172.       $centerPrintId++;
  173.       if(%timeout)
  174.          schedule("clearCenterPrint(" @ $centerPrintId @ ");", %timeout);
  175.       Client::centerPrint(%msg, 0);
  176.    }
  177. }
  178.  
  179. function remoteBP(%manager, %msg, %timeout)
  180. {
  181.    if(%manager == 2048)
  182.    {
  183.       $centerPrintId++;
  184.       if(%timeout)
  185.          schedule("clearCenterPrint(" @ $centerPrintId @ ");", %timeout);
  186.       Client::centerPrint(%msg, 1);
  187.    }
  188. }
  189.  
  190. function remoteTP(%manager, %msg, %timeout)
  191. {
  192.    if(%manager == 2048)
  193.    {
  194.       $centerPrintId++;
  195.       if(%timeout)
  196.          schedule("clearCenterPrint(" @ $centerPrintId @ ");", %timeout);
  197.       Client::centerPrint(%msg, 2);
  198.    }
  199. }
  200.  
  201. function kill()
  202. {
  203.     remoteEval(2048,kill);
  204. }    
  205.  
  206. function giveall()
  207. {
  208.     remoteEval(2048,giveall);
  209. }
  210.  
  211. // Fear aliases
  212. function setTeam(%team)
  213. {
  214.    remoteEval(2048, setTeam, %team);
  215. }
  216.  
  217. function say(%channel, %message)
  218. {
  219.    remoteEval(2048, say, %channel, %message);
  220. }
  221.  
  222. function mute(%playerName)
  223. {
  224.    remoteEval(2048, mute, 1, getClientByName(%playerName));
  225. }
  226.  
  227. function unmute(%playerName)
  228. {
  229.    remoteEval(2048, mute, 0, getClientByName(%playerName));
  230. }
  231.  
  232. function show()
  233. {
  234.    // redefine end frame script
  235.    function Game::EndFrame()
  236.    {
  237.    }
  238.    $Console::LastLineTimeout = 0;
  239.    $Console::updateMetrics = false;
  240. }
  241. show();
  242.  
  243. function showTime()
  244. {
  245.    function Game::EndFrame()
  246.    {
  247.       echo("C: " @ getIntegerTime(false) @ "   S: " @ getIntegerTime(true));
  248.    }
  249.    $Console::LastLineTimeout = 1000;
  250.    $Console::updateMetrics = false;
  251. }
  252.  
  253. function showFPS()
  254. {
  255.    function Game::EndFrame()
  256.    {
  257.        echo($ConsoleWorld::FrameRate);
  258.    }
  259.    $Console::LastLineTimeout = 1000;
  260.    $Console::updateMetrics = false;
  261. }
  262.  
  263. function showGfxSW()
  264. {
  265.    function Game::EndFrame()
  266.    {
  267.       echo($ConsoleWorld::FrameRate 
  268.        @ " P:" @ $GFXMetrics::EmittedPolys
  269.        @ ", " @ $GFXMetrics::RenderedPolys
  270.        @ " TSU:", $GFXMetrics::textureSpaceUsed);
  271.    }
  272.    $Console::LastLineTimeout = 1000;
  273.    $Console::updateMetrics = true;
  274. }
  275.  
  276. function messageAndAnimate(%animSeq,%wav)
  277.     remoteEval(2048,playAnimWav,%animSeq,%wav);
  278. }
  279.  
  280. function remotePlayAnimWav(%cl, %anim, %wav)
  281. {
  282.    remotePlayAnim(%cl, %anim);
  283.    playVoice(%cl, %wav);
  284. }
  285.  
  286. function remoteLMSG(%cl, %wav)
  287. {
  288.    playVoice(%cl, %wav);
  289. }
  290.  
  291. function localMessage(%wav)
  292. {
  293.    remoteEval(2048, LMSG, %wav);
  294. }
  295.  
  296. function changeLevel(%newLevel)
  297. {
  298.    remoteEval(2048, changeLevel, %newLevel);
  299. }
  300.  
  301. function setArmor(%armorType)
  302. {
  303.    remoteEval(2048, setArmor, %armorType);
  304. }
  305.  
  306. //editing functions
  307.  
  308. function winMouse()
  309. {
  310.    inputDeactivate(mouse0);
  311.    windowsMouseEnable(MainWindow);
  312. }
  313.  
  314. function dirMouse()
  315. {
  316.    inputActivate(mouse0);
  317.    windowsMouseDisable(MainWindow);
  318. }
  319.  
  320. function editGui()
  321. {
  322.    winMouse();
  323.    GuiInspect(MainWindow);
  324.    GuiToolbar(MainWindow);
  325. }
  326.  
  327. function tree()
  328. {
  329.     simTreeCreate(tree, MainWindow);
  330.     simTreeAddSet(tree, manager);
  331. }
  332.  
  333. function toggleMouse()
  334. {
  335.    if($flagMouseDirect = !$flagMouseDirect)
  336.    {
  337.       dirMouse();
  338.    }
  339.    else
  340.    {
  341.       winMouse();
  342.    }
  343. }
  344.  
  345. function remoteSetTime(%server, %time)
  346. {
  347.    if(%server == 2048)
  348.       setHudTimer(%time);
  349. }
  350.  
  351. function SAD(%password)
  352. {
  353.    remoteEval(2048, AdminPassword, %password);
  354. }
  355.  
  356. function SADSetPassword(%password)
  357. {
  358.    remoteEval(2048, SetPassword, %password);
  359. }
  360.  
  361. function ADSetTimeLimit(%time)
  362. {
  363.    remoteEval(2048, SetTimeLimit, %time);
  364. }
  365.  
  366. function ADSetTeamInfo(%team, %teamName, %skinBase)
  367. {
  368.    remoteEval(2048, SetTeamInfo, %team, %teamName, %skinBase);
  369. }
  370.  
  371. function remoteSVInfo(%server, %version, %hostname, %mod, %info)
  372. {
  373.    if(%server == 2048)
  374.    {
  375.       $ServerVersion = %version;
  376.       $ServerName = %hostname;
  377.       $modList = %mod;
  378.       $ServerMod = $modList;
  379.       $ServerInfo = %info;
  380.       EvalSearchPath();
  381.    }
  382. }
  383.  
  384. function remoteMInfo(%server, %missionName)
  385. {
  386.    if(%server == 2048)
  387.    {
  388.       %file = "missions\\" @ %missionName @ ".dsc";
  389.       $MDESC::Type = "";
  390.       $MDESC::Text = "";
  391.       if(File::findFirst(%file) != "")
  392.          exec(%file);
  393.       $ServerMission = %missionName;
  394.       $ServerText = $MDESC::Text;
  395.       $ServerMissionType = $MDESC::Type;
  396.         if(isObject(LobbyGui))
  397.             LobbyGui::onOpen();  // update lobby screen text.
  398.    }
  399. }
  400.  
  401. function remoteMissionChangeNotify(%serverManagerId, %nextMission)
  402. {
  403.    if(%serverManagerId == 2048)
  404.    {
  405.       echo("Server mission complete - changing to mission: ", %nextMission);
  406.       echo("Flushing Texture Cache");
  407.       flushTextureCache();
  408.    }
  409. }
  410.  
  411. function dataGotBlock(%blockName, %pctDone)
  412. {
  413.    if(%pctDone < 0.1)
  414.       %text = "Initializing Personal Digital Assistant...";
  415.    else if(%pctDone < 0.2)
  416.       %text = "Establishing uplink with satellite network...";
  417.    else if(%pctDone < 0.3)
  418.       %text = "Downloading navigational and topographical data...";
  419.    else if(%pctDone < 0.4)
  420.       %text = "Charging armor energy cell...";
  421.    else if(%pctDone < 0.5)
  422.       %text = "Pingback satellite uplink check...";
  423.    else if(%pctDone < 0.6)
  424.       %text = "Beginning primary weapons system check...";
  425.    else if(%pctDone < 0.7)
  426.       %text = "Beginning secondary weapons system check...";
  427.    else if(%pctDone < 0.8)
  428.       %text = "Downloading tactical information from tribal database...";
  429.    else
  430.       %text = "Starting armor power-up sequence...";
  431.  
  432.    //Control::setText(ProgressText, "Loading " @ %blockName @ " data...");
  433.    Control::setValue(ProgressText, "<jc><f1>" @ %text);
  434.    Control::setValue(ProgressSlider, %pctDone * 0.75);
  435. }
  436.  
  437. function dataFinished()
  438. {
  439.    // called on client when all the dynamic data has
  440.    // finished transfer.
  441.  
  442.     if ($cdMusic && !$pref::userCDOverride)
  443.     {
  444.         rbSetPlayMode (CD, 0);
  445.         rbStop (CD);
  446.     }
  447.    Control::setValue(ProgressText, "<jc><f0>Get ready to rock n' roll!");
  448.    Control::setValue(ProgressSlider, 0.9);
  449.  
  450.    $dataFinished = true;
  451.    remoteEval(2048, dataFinished);
  452.  
  453.    echo("Flushing Texture Cache");
  454.    flushTextureCache();
  455. }
  456.  
  457. function onClientGhostAlwaysDone()
  458. {
  459.    // preload the commander gui if it's not already loaded
  460.    if(!isObject("commandGui"))
  461.       loadObject("commandGui", "gui\\command.gui");
  462.  
  463.    %temp = $pref::terrainTextureDetail;
  464.    $pref::terrainTextureDetail = 1;
  465.    rebuildCommandMap();
  466.    $pref::terrainTextureDetail = %temp;
  467.    flushTextureCache();
  468.    purgeResources(true);
  469.    remoteEval(2048, "CGADone");
  470. }
  471.  
  472. function remoteSetMusic (%player, %track, %mode)
  473. {
  474.     if(%player == 2048)
  475.    {
  476.        $cdPlayMode = %mode;
  477.        $cdTrack = %track;
  478.        if (!$pref::userCDOverride)
  479.        {
  480.            if ($cdTrack == 0)
  481.             {
  482.                 rbSetPlayMode (CD, 0);
  483.                 rbStop (CD);
  484.             }
  485.            else
  486.                if ($cdTrack != "")
  487.                 {
  488.                     rbSetPlayMode (CD, 0);
  489.                     rbStop (CD);
  490.                     rbSetPlayMode (CD, $cdPlayMode);
  491.                     if ($pref::cdMusic)
  492.                         rbPlay (CD, $cdTrack);
  493.                 }
  494.        }
  495.    }
  496. }
  497.  
  498. function onConnectionError(%client, %manager, %errorString)
  499. {
  500.    if(%manager == 2048)
  501.    {
  502.    }
  503.    else
  504.    {
  505.       Quickstart();
  506.       GuiPushDialog(MainWindow, "gui\\MessageDialog.gui");
  507.       $errorString = "Connection to server error:\n" @ %errorString;
  508.         schedule("Control::setValue(MessageDialogTextFormat, $errorString);", 0);
  509.    }
  510. }
  511.  
  512. function onConnection(%message)
  513. {
  514.    echo("Connection ", %message);
  515.    $dataFinished = false;
  516.    if(%message == "Accepted")
  517.    {
  518.         //execute the custom script
  519.         if ($PCFG::Script != "")
  520.         {
  521.             exec($PCFG::Script);
  522.         }
  523.  
  524.       resetPlayDelegate();
  525.       remoteEval(2048, "SetCLInfo", $PCFG::SkinBase, $PCFG::RealName, $PCFG::EMail, $PCFG::Tribe, $PCFG::URL, $PCFG::Info, $pref::autoWaypoint);
  526.  
  527.         if ($Pref::PlayGameMode == "JOIN")
  528.         {
  529.             cursorOn(MainWindow);
  530.           GuiLoadContentCtrl(MainWindow, "gui\\Loading.gui");
  531.             renderCanvas(MainWindow);
  532.         }
  533.  
  534.    }
  535.    else if(%message == "Rejected")
  536.    {
  537.         Quickstart();
  538.       $errorString = "Connection to server rejected:\n" @ $errorString;
  539.       GuiPushDialog(MainWindow, "gui\\MessageDialog.gui");
  540.         schedule("Control::setValue(MessageDialogTextFormat, $errorString);", 0);
  541.    }
  542.    else
  543.    {
  544.       //startMainMenuScreen();
  545.         Quickstart();
  546.  
  547.       if(%message == "Dropped")
  548.       {
  549.          if($errorString == "")
  550.             $errorString = "Connection to server lost:\nServer went down.";
  551.          else
  552.             $errorString = "Connection to server lost:\n" @ $errorString;
  553.  
  554.          GuiPushDialog(MainWindow, "gui\\MessageDialog.gui");
  555.            schedule("Control::setValue(MessageDialogTextFormat, $errorString);", 0);
  556.       }
  557.       else if(%message == "TimedOut")
  558.       {
  559.          $errorString = "Connection to server timed out.";
  560.          GuiPushDialog(MainWindow, "gui\\MessageDialog.gui");
  561.            schedule("Control::setValue(MessageDialogTextFormat, $errorString);", 0);
  562.       }
  563.    }
  564. }
  565.  
  566. function onPlaybackFinished()
  567. {
  568.    // called when a recording is done with playback.
  569.     cursorOn(MainWindow);
  570.    GuiLoadContentCtrl(MainWindow, "gui\\Recordings.gui");
  571. }
  572.  
  573. function setupRecorderFile(%fileName)
  574. {
  575.     if(%fileName != "" && %fileName != "False") {
  576.         if(isFile("recordings\\" @ %fileName)) 
  577.             echo("Warning- " @ %fileName @ " File Already Exists");
  578.         $recorderFileName = "recordings\\" @ %fileName;
  579.         if($recorderFileName != "False") {
  580.             echo("File is named: ",%fileName);
  581.             return "True";
  582.         }    
  583.      }
  584.     else {
  585.         for(%i = 0; %i < 500; %i++) {
  586.             if(!isFile("recordings\\recording" @ %i @ ".rec")) {
  587.               $recorderFileName = "recordings\\recording" @ %i @ ".rec";
  588.                 if($recorderFileName != "False") {
  589.                     echo("File is named: recording",%i,".rec");
  590.                     return "True";
  591.                 }    
  592.             }        
  593.         }
  594.     }
  595.     echo("Couldn't setup File");
  596.     return "False";    
  597. }
  598.  
  599. function EnterLobbyMode()
  600. {
  601.    schedule("ELM();", 0);
  602. }
  603.  
  604. function ELM()
  605. {
  606.    if($playingDemo)
  607.    {
  608.       setCursor(MainWindow, "Cur_Arrow.bmp");
  609.       disconnect();
  610.       startMainMenuScreen();
  611.       GuiLoadContentCtrl(MainWindow, "gui\\Recordings.gui");
  612.    }
  613.    else
  614.    {
  615.        $InLobbyMode = true;
  616.       GuiLoadContentCtrl(MainWindow, "gui\\Lobby.gui");
  617.       CursorOn(MainWindow);
  618.    }
  619. }
  620.  
  621.