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

  1. //Towers Training script file
  2. //-----------------------------
  3. //Handles all automations for towers training mission
  4.  
  5. exec("game.cs");
  6. exec("Training_AI.cs");
  7. $enemyTeam[0] = 1;
  8. $enemyTeam[1] = 0;
  9. $missionOver = false;
  10. $numCaps = 0;
  11. $AIkilled = 0;
  12. $Train::missionType = "C&H";
  13.  
  14. function TowersTraining::init()
  15. {       
  16.   $trainingType = 0;
  17.   $currentWay = 1;
  18.   $numSwitches = 0;     
  19.   $numToComplete = 0;
  20.   
  21.    
  22.   for(%i = 1; (%group = nameToID("MissionGroup\\Towers\\Tower" @ %i)) != -1; %i++)
  23.   {    
  24.     
  25.     %numObj = Group::objectCount(%group);
  26.     for(%j = 0; %j < %numObj; %j++)
  27.     { 
  28.       %tempObj = Group::getObject(%group, %j);
  29.       GameBase::setTeam(%tempObj, 1);
  30.       if(GameBase::getDataName(%tempObj) == TowerSwitch)
  31.       {
  32.         
  33.         $SwitchObject[%i] = %tempObj;
  34.         $SwitchObject[%i].objectiveComplete = false;
  35.         $SwitchPosition[%i] = GameBase::getPosition($SwitchObject[%i]);
  36.         $TowerControlled[%i] = "false";
  37.         $numSwitches++;
  38.         $numToComplete++;
  39.       }
  40.     }
  41.   }
  42.   %startGroup =  nameToID("MissionGroup\\Teams\\Team0\\DropPoints\\Start");
  43.   $startPoint = Group::getObject(%startGroup, 0);
  44.   
  45.   for(%k = 1; %k <= 3; %k++)
  46.   {
  47.     %group = nameToID("MissionGroup\\Towers\\Tower" @ %k @ "\\DropPoints");
  48.     $spawnPoint[%k] = Group::getObject(%group, 0);
  49.     
  50.   }
  51.   towers::teamMissionObjectives(0, false);
  52. }
  53.  
  54.  
  55. function TowerSwitch::onCollision(%this, %object)
  56. {
  57.    $numCaps++;
  58.    if(getObjectType(%object) != "Player")
  59.       return;
  60.  
  61.    if(Player::isDead(%object))
  62.       return;
  63.  
  64.    if(Player::getClient(%object) != Client::getFirst())
  65.       return;
  66.  
  67.    %playerTeam = GameBase::getTeam(%object);
  68.    %otherTeam = GameBase::getTeam(%this);
  69.    
  70.    if(%otherTeam == %playerTeam)
  71.       return;
  72.    
  73.    for(%k = 1; %k <= $numSwitches; %k++)
  74.    {
  75.      if($SwitchObject[%k] == %this)
  76.      { 
  77.         %switchNum = %k;
  78.      }
  79.    }    
  80.    if(%playerTeam == 0 )
  81.    {
  82.      if($SwitchObject[$currentWay] != %this)
  83.      {      
  84.          TowersTraining::wrongObjective(%this, %object);
  85.          return;
  86.      }
  87.    
  88.      if($currentWay == 1)
  89.        $towerTime1 =  getSimTime();
  90.      else if($currentWay == 2)
  91.        $towerTime2 = getSimTime();
  92.      else
  93.        $towerTime3 = getSimTime();
  94.      
  95.      %this.trainingObjectiveComplete = true;
  96.      %playerClient = Player::getClient(%object);
  97.      %touchClientName = Client::getName(%playerClient);
  98.         %group = "MissionGroup\\Towers\\tower" @ $currentWay;
  99.      
  100.      //set all objects to players team.
  101.      for(%i = 0; (%obj = Group::getObject(%group, %i)) != -1; %i++)
  102.      {  
  103.        GameBase::setTeam(%obj, %playerTeam);
  104.      }  
  105.      messageAll(0, "~wCapturedTower.wav");
  106.      
  107.      if($numToComplete == 1)
  108.        %time = 0;
  109.      else 
  110.        %time = 5;
  111.      
  112.      schedule("bottomprint(" @ %playerClient @ ", \"<f1><jc>Objective " @ $currentWay @ " has been accomplished!\", 5);", %time);
  113.      ObjectiveMission::objectiveChanged(%this, false);
  114.      towers::teamMissionObjectives(%switchNum, false);
  115.          
  116.    }
  117.    else if(%playerTeam == 1)
  118.    {
  119.      bottomprint(%playerClient, "<f1><jc>The enemy has taken one of your towers!", 5);
  120.      schedule("bottomprint(" @ %playerClient @ ", \"<f1><jc>You must go back and claim the tower before you can win the mission!\", 5);", 5);
  121.      messageAll(0, "~wCapturedTower.wav");
  122.      
  123.      //set all objects to opposite team , Ai's Team.
  124.      %group = nameToId("MissionGroup\\Towers\\tower" @ %switchNum);
  125.      for(%i = 0; (%obj = Group::getObject(%group, %i)) != -1; %i++)
  126.      {  
  127.        
  128.        GameBase::setTeam(%obj, %playerTeam);
  129.      }  
  130.       
  131.      ObjectiveMission::objectiveChanged(%this, true);
  132.      towers::teamMissionObjectives(%switchNum, true);
  133.    }
  134. }
  135.  
  136. //bottomprints to all players on teamId
  137. function Teambottomprint(%teamId, %string)
  138. {
  139.   for(%i = 0; %i < getNumClients(); %i++)
  140.   {
  141.     %player = Client::getFirst();
  142.     if(GameBase::getTeam(%player) == %teamId)
  143.     { 
  144.       bottomprint(%player, %string, 5);
  145.     }
  146.     %player = Client::getNext(%player);
  147.   }
  148. }
  149.  
  150. function remoteScoresOn(%clientId)
  151. {
  152. }
  153.  
  154. function remoteScoresOff(%clientId)
  155. {
  156. }
  157.  
  158. function Game::playerSpawn(%clientId, %respawn)
  159. {
  160.    if($currentWay == 1)
  161.      %spawnMarker = $startPoint;
  162.    else
  163.      %spawnMarker = $spawnPoint[$currentWay - 1]; 
  164.    
  165.    %clientId.guiLock = "";
  166.    if(%spawnMarker == -1)
  167.    {
  168.       %spawnPos = "0 0 300";
  169.       %spawnRot = "0 0 0";
  170.    }
  171.    else
  172.    {
  173.       %spawnPos = GameBase::getPosition(%spawnMarker);
  174.       %spawnRot = GameBase::getRotation(%spawnMarker);
  175.    }
  176.  
  177.     if(!String::ICompare(Client::getGender(%clientId), "Male"))
  178.       %armor = "larmor";
  179.    else
  180.       %armor = "lfemale";
  181.  
  182.    %pl = spawnPlayer(%armor, %spawnPos, %spawnRot);
  183.     
  184.    GameBase::setTeam(%pl, Client::getTeam(%clientId));                                          
  185.    Client::setOwnedObject(%clientId, %pl);                                                      
  186.    Game::playerSpawned(%pl, %clientId, %armor, %respawn);                                       
  187.    Client::setControlObject(%clientId, %pl);                                                 
  188. }
  189.  
  190. function Towers::teamMissionObjectives(%towNum, %taken)
  191. {
  192.    //check which to replace
  193.    if(%taken)
  194.      %string = "Tower " @ %towNum @ " has not been captured.";
  195.    else
  196.      %string = "Tower " @ %towNum @ " has been captured.";
  197.    
  198.    if($missionOver)
  199.    {
  200.      Training::MissionComplete( 2049 );
  201.      return;
  202.    }  
  203.    
  204.    //title screen
  205.    Team::setObjective(0, 1, "<f5><jl>GamePlay Description:");
  206.    Team::setObjective(0, 2, "<f1><jl>    The Objective of a Capture and Hold mission are to find and to take control");  
  207.    Team::setObjective(0, 3, "<f1><jl>    of the objects placed in a mission. Once taken, any equipment associated with");
  208.    Team::setObjective(0, 4, "<f1><jl>    the object, such as turrets, stations, ect., come under your control as well.");
  209.    Team::setObjective(0, 5, "<f1><jl>    the longer you hold a location, the more points you recieve. In this training");
  210.    Team::setObjective(0, 6, "<f1><jl>    mission, all you will have to do is take control of all 3 towers.");
  211.    Team::setObjective(0, 7, "\n");
  212.    Team::setObjective(0, 8, "<f5><jl>Mission Completion:");
  213.    Team::setObjective(0, 9, "<f1>   -To own all 3 towers.");
  214.    Team::setObjective(0, 10, "\n");
  215.    Team::setObjective(0, 11, "<f5><jl>Mission Information:");
  216.    Team::setObjective(0, 12, "<f1>   -Mission Name: Capture and Hold Training.");
  217.    Team::setObjective(0, 13, "\n");
  218.    Team::setObjective(0, 14, "<f5><jl>Mission Objectives:");
  219.    
  220.    //replace string
  221.    if(%towNum == 1)
  222.    {  
  223.       Team::setObjective(0, 15, "<f1><Btower_teamcontrol.bmp>\n   " @ %string);
  224.    }
  225.    else if(%towNum == 2) 
  226.    {
  227.       Team::setObjective(0, 16, "<f1><Btower_teamcontrol.bmp>\n   " @ %string);
  228.    }                           
  229.    else if(%towNum == 3) 
  230.    {
  231.       Team::setObjective(0, 17, "<f1><Btower_teamcontrol.bmp>\n   " @ %string);
  232.    }
  233.    //initial setup
  234.    else
  235.    {
  236.       Team::setObjective(0, 15, "<f1><Btower_enemycontrol.bmp>\n   Tower 1 has not been captured.");
  237.          Team::setObjective(0, 16, "<f1><Btower_enemycontrol.bmp>\n   Tower 2 has not been captured.");
  238.       Team::setObjective(0, 17, "<f1><Btower_enemycontrol.bmp>\n   Tower 3 has not been captured.");
  239.    }
  240. }
  241.  
  242. function missionSummary()
  243. {
  244.    %time = getSimTime() - $MatchStartTime;
  245.    
  246.    Training::displayBitmap(0);
  247.    
  248.    Team::setObjective(0, 1, "<f5><jl>Mission Completion:");
  249.    Team::setObjective(0, 2, "<f1>   -Completed:");
  250.    Team::setObjective(0, 3, "\n");
  251.    Team::setObjective(0, 4, "<f5><jl>Mission Information:");
  252.    Team::setObjective(0, 5, "<f1>   -Mission Name: Capture and Hold Training");
  253.    Team::setObjective(0, 6, "\n");
  254.    
  255.    Team::setObjective(0, 7, "<f5><j1>Mission Summary:");
  256.    
  257.    Team::setObjective(0, 8, "<f1>   -Enemy Kills: " @ "<f1>" @ $AIKilled @ " out of " @ $numGuards);
  258.    Team::setObjective(0, 9, "<f1>   -Total Mission Time: " @ "<f1>" @ Time::getMinutes(%time) @ " Minutes " @ Time::getSeconds(%time) @ " Seconds");
  259.    Team::setObjective(0, 10, "");
  260.    Team::setObjective(0, 11, "");
  261.    Team::setObjective(0, 12, "");
  262.    Team::setObjective(0, 13, "");
  263.    Team::setObjective(0, 14, "");
  264.    Team::setObjective(0, 15, "");
  265.    Team::setObjective(0, 16, "");
  266.    Team::setObjective(0, 17, "");
  267.    Team::setObjective(0, 18, "");
  268.    Team::setObjective(0, 19, "");
  269.    Team::setObjective(0, 20, "");
  270. }
  271.  
  272.  
  273. function TowersTraining::setWayPoint(%clientid)
  274. {
  275.    //setup initial waypoint information
  276.    %currentPos = $switchPosition[$currentWay];
  277.    %currentx = getWord(%currentPos, 0);
  278.    %currenty = getWord(%currentPos, 1);
  279.    bottomprint(%clientId, "<f1><jc>Your Waypoint has been set to tower " @ $currentWay @ ".", 5);    
  280.    
  281.    issueCommand(%clientId, %clientId, 0, "Waypoint set to tower " @ $currentWay @ ".", %currentx, %currenty);
  282. }       
  283.  
  284. function TowersTraining::objectiveComplete(%this, %taken)
  285. {
  286.   for(%k = 1; %k <= $numSwitches; %k++)
  287.   {
  288.     if(%this == $SwitchObject[%k])
  289.     {  
  290.       if(%taken)
  291.       {
  292.         $TowerControlled[%k] = "false";
  293.         $numToComplete++;
  294.       }
  295.       else
  296.       {
  297.         $TowerControlled[%k] = "true";
  298.           $numToComplete--;
  299.       }
  300.     }
  301.   }
  302.   if($numToComplete != 0)
  303.   {
  304.     if(%this == $SwitchObject[$currentWay] && !%taken)
  305.     {
  306.       if($currentWay != 3)
  307.       {
  308.         $currentWay++;
  309.         %playerId = Client::getFirst();
  310.         %newPos = GameBase::getPosition($SwitchObject[$currentWay]);
  311.         %currentx = getWord(%newPos, 0);
  312.         %currenty = getWord(%newPos, 1);
  313.         bottomprint(%playerId, "<f1><jc>Your Waypoint has been set to tower " @ $currentWay @ ".", 5);
  314.         issueCommand(%playerId, %playerId, 0, "Goto waypoint " @ $currentWay, %currentx, %currenty);
  315.       }
  316.       //else
  317.         //setupLastWayPoint();
  318.     }
  319.     else
  320.     {
  321.       dbecho(2,"Captured secondary target, waypoint still set to primary target.");
  322.     }
  323.   } 
  324.   else
  325.   {
  326.     $missionOver = true;
  327.    
  328.   }
  329. }
  330.  
  331. function setUpLastWayPoint()
  332. {
  333.   $currentWay = 1;
  334.   %playerId = Client::getFirst();
  335.   %newPos = GameBase::getPosition($SwitchObject[$currentWay]);
  336.   %currentx = getWord(%newPos, 0);
  337.   %currenty = getWord(%newPos, 1);
  338.   bottomprint(%playerId, "<f1><jc>Your Waypoint has been set back to tower " @ $currentWay @ " for recapture.", 5);
  339.   issueCommand(%playerId, %playerId, 0, "Goto waypoint " @ $currentWay, %currentx, %currenty);
  340. }
  341.  
  342. function Game::initialMissionDrop(%clientId)
  343. {
  344.     GameBase::setTeam(%clientId, 0);
  345.     Client::setGuiMode(%clientId, $GuiModePlay);
  346.     Game::playerSpawn(%clientId, false);
  347.     //Team::clearObjectives(0);
  348.     Training::displayBitmap(0);
  349.     Training::setupAI(%clientId);
  350.     Training::startMission(%clientId);    
  351. }
  352.  
  353.  
  354. function TowersTraining::wrongObjective(%this, %object)
  355. {
  356.   %cl = client::getFirst();
  357.   bottomprint( %cl, "<f1><jc>You must take the tower that has been set by your commander first.", 5);
  358. }
  359.  
  360.  
  361. function Training::missionComplete(%cl)
  362. {
  363.   
  364.   schedule("Client::setGuiMode(" @ %cl @ ", " @ $GuiModeObjectives @ ");", 8);
  365.   missionSummary();
  366.   remoteEval(2049, TrainingEndMission);
  367. }
  368.  
  369. function remoteTrainingEndMission()
  370. {
  371.    schedule("EndGame();", 16);
  372. }
  373.  
  374. function Training::startMission(%playerId)
  375. {
  376.   schedule("bottomprint(" @ %playerId @ ", \"<f1><jc>Training Mission 6 - Capture and Hold.\", 5);", 0);
  377.   schedule("bottomprint(" @ %playerId @ ", \"<f1><jc>This mission will introduce you to the capture and hold game scenario.\", 5);", 5);
  378.   schedule("bottomprint(" @ %playerId @ ", \"<f1><jc>Bring up The Objectives screen for a gameplay description.\", 5);", 10);
  379.   schedule("messageAll(0, \"~wshell_click.wav\");", 0);
  380.   schedule("messageAll(0, \"~wshell_click.wav\");", 5);
  381.   schedule("messageAll(0, \"~wshell_click.wav\");", 10);
  382.   schedule("TowersTraining::setWayPoint(" @ %playerId @ ");", 15);
  383. }
  384.  
  385. function Player::enterMissionArea(%this)
  386. {
  387. }
  388.  
  389. function Player::leaveMissionArea(%this)
  390. {
  391. }
  392.  
  393. //init all info
  394. TowersTraining::init();
  395. towers::teamMissionObjectives(0);