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

  1. //Training_CTF.cs
  2. //----------------------
  3. //
  4. //Handles all automation of the Capture the Flag Training mission
  5. //----------------------------------------------------------------
  6.  
  7. $Train::missionType = "CTF";
  8. exec("game.cs");
  9. exec("Training_AI.cs");
  10.  
  11.  
  12. function ctf::init()
  13. {
  14.   
  15.   %group0 = "MissionGroup\\teams\\team0\\flag";
  16.   %group1 = "MissionGroup\\teams\\team1\\flag";
  17.   
  18.   $flagObject[0] = Group::getObject(%group0, 0);
  19.   $flagObject[1] = Group::getObject(%group1, 0);
  20.  
  21.   $flagAtHome[0] = true;
  22.   $flagAtHome[1] = true;
  23.   $enemyTeam[0] = 1;
  24.   $enemyTeam[1] = 0;
  25.  
  26.   $enemyFlagName[0] = "Flag1";
  27.   $enemyFlagName[1] = "Flag0";
  28.  
  29.   $flagCarrier[0] = -1;
  30.   $flagCarrier[1] = -1;
  31.  
  32.   $flagPosition[0] = GameBase::getPosition($flagObject[0]);
  33.   $flagPosition[1] = GameBase::getPosition($flagObject[1]);
  34.  
  35.   dbecho(2, "flagObject 0 pos:" @ $flagPosition[0]);
  36.   dbecho(2, "flagObject 1 pos:" @ $flagPosition[1]);
  37.  
  38.   $lastTeamSpawn[0] = -1;
  39.   $lastTeamSpawn[1] = -1;
  40.  
  41.   $captures = 0;
  42.   $capstowin = 3;
  43.   $pickupSequence[0] = 0;
  44.   $pickupSequence[1] = 0;
  45.   $flagReturnTime = 45;
  46.   $flagDropped = false;
  47.  
  48. }
  49.  
  50. function TeamMessages(%mtype, %team1, %message1, %team2, %message2)
  51. {
  52.    %numPlayers = getNumClients();
  53.    for(%i = 0; %i < %numPlayers; %i++)
  54.    {
  55.       %id = getClientByIndex(%i);
  56.       if(Client::getTeam(%id) == %team1)
  57.       {
  58.          Client::sendMessage(%id, %mtype, %message1);
  59.       }
  60.       else if(Client::getTeam(%id) == %team2)
  61.       {
  62.          Client::sendMessage(%id, %mtype, %message2);
  63.       }
  64.    }
  65. }
  66.  
  67. function CTFTraining::setWayPoint(%this, %init)
  68. {
  69.    %flagTeam = GameBase::getTeam(%this);
  70.    //setup waypoint information
  71.    if(GameBase::getTeam(%this) == 1)
  72.      %currentPos = GameBase::getPosition($flagObject[0]);
  73.    else
  74.      %currentPos = GameBase::getPosition($flagObject[1]);
  75.    
  76.      %currentx = getWord(%currentPos, 0);
  77.      %currenty = getWord(%currentPos, 1);
  78.      %clFirst = Client::getFirst();    
  79.    
  80.    if(!$flagDropped)
  81.    {
  82.      if(!%init)
  83.      {
  84.        
  85.        if($flagAtHome[1])
  86.        {  
  87.          for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  88.          {
  89.            %this.trainingObjectiveComplete = "";
  90.            issueCommand(%clFirst, %cl, 0, "Make your way to the enemy's base.", %currentx, %currenty);
  91.            schedule("bottomprint( " @ %cl @ ", \"<jc><f1>WayPoint set to enemy base.\", 5);", 5);
  92.  
  93.             }
  94.        }
  95.        else
  96.        {  
  97.          %this.trainingObjectiveComplete = "";
  98.          for(%cl = Client::getFirst(); %cl != -1; %cl = Client::getNext(%cl))
  99.             {
  100.               issueCommand(%clFirst, %cl, 0, "Return enemy flag to your base.", %currentx, %currenty);
  101.               schedule("bottomprint(" @ %cl @ ", \"<jc><f1>Bring enemy flag back to your base for a capture.\", 5);", 5);
  102.             }
  103.           }
  104.      }
  105.      else
  106.      {  
  107.          issueCommand(%clFirst, %clFirst, 0, "Make your way to the enemy's base.", %currentx, %currenty);
  108.          schedule("bottomprint(" @ %clFirst @ ", \"<jc><f1>WayPoint set to enemy base.\", 5);", 15);
  109.      }
  110.    }
  111.    else
  112.    {  
  113.      issueCommand(%clFirst, %clFirst, 0, "Make your way to the enemy's flag.", %currentx, %currenty);
  114.      schedule("bottomprint(" @ %clFirst @ ", \"<jc><f1>WayPoint set to dropped flag.\", 5);", 5);
  115.    }
  116. }       
  117.   
  118.  
  119. function Flag::onDrop(%player, %type)
  120. {
  121.    %playerTeam = GameBase::getTeam(%player);
  122.    %flagTeam = $enemyTeam[%playerTeam];
  123.    %playerClient = Player::getClient(%player);
  124.    %dropClientName = Client::getName(Player::getClient(%player));
  125.    
  126.    
  127.    bottomprint(%playerClient, "<f1><jc>You dropped the " @ getTeamName(%flagTeam) @ " flag!", 5);
  128.    
  129.  
  130.    GameBase::throw($flagObject[%flagTeam], %player, 10, false);
  131.    Item::hide($flagObject[%flagTeam], false);
  132.    Player::setItemCount(%player, "Flag", 0);
  133.    
  134.    $flagCarrier[%flagTeam] = -1;
  135.    schedule("CTF::checkFlagReturn(" @ %flagTeam @ ", " @ $pickupSequence[%flagTeam] @ ");", $flagReturnTime);
  136.    CTF::checkMissionObjectives();
  137.    $flagDropped = true;
  138.    
  139.    CTFTraining::setWayPoint($flagObject[0]);
  140.  
  141. }
  142. function CTF::checkMissionObjectives()
  143. {
  144.    if(CTF::teamMissionObjectives(0))
  145.    {
  146.       Training::MissionComplete( 2049 );
  147.    }
  148. }
  149.  
  150.  
  151. function CTF::checkFlagReturn(%team, %sequenceNum)
  152. {
  153.    dbecho(2, "checking for flag return: ", %team, ", ", %sequenceNum);
  154.    if($pickupSequence[%team] == %sequenceNum)
  155.    {
  156.       messageAll(0, "The enemy flag was returned to thier base.~wflagreturn.wav");
  157.       GameBase::startFadeOut($flagObject[%team]);
  158.       GameBase::setPosition($flagObject[%team], $flagPosition[%team]);
  159.       GameBase::startFadeIn($flagObject[%team]);
  160.       $flagAtHome[%team] = true;
  161.       CTF::checkMissionObjectives();
  162.       $flagDropped = false;
  163.       CTFTraining::setWayPoint($flagObject[0], true);
  164.    }
  165. }
  166.  
  167. function Flag::onCollision(%this, %object)
  168. {
  169.    if(Player::getClient(%object) != 2049)
  170.          return;
  171.    
  172.    if(getObjectType(%object) == "Player")
  173.    {
  174.       %name = Item::getItemData(%this);
  175.       %playerTeam = GameBase::getTeam(%object);
  176.       %flagTeam = GameBase::getTeam(%this);
  177.       %touchClientName = Client::getName(Player::getClient(%object));
  178.       %enemyTeam = $enemyTeam[%playerTeam];
  179.  
  180.       dbecho(2, %name, " ", %playerTeam, " ", %flagTeam, " ", %touchClientName, " ", %enemyTeam);
  181.       dbecho(2, $flagObject[%flagTeam], " ", $flagPosition[%flagTeam]);
  182.       %playerClient = Player::getClient(%object);
  183.  
  184.       if(%flagTeam == %playerTeam)
  185.       {
  186.          // player is touching his own flag...
  187.          if(!$flagAtHome[%playerTeam])
  188.          {
  189.             // the flag isn't home! so return it.
  190.             GameBase::setPosition(%this, $flagPosition[%flagTeam]);
  191.             $flagAtHome[%playerTeam] = true;
  192.             bottomprint(%playerClient, "<jc><f1>You returned the " @ getTeamName(%playerTeam) @ " flag!" @ "~wflagreturn.wav", 5);
  193.             CTF::checkMissionObjectives();
  194.             $pickupSequence[%flagTeam] = $pickupSequence[%flagTeam] + 1;
  195.             
  196.          }
  197.          else
  198.          {
  199.             // it's at home - see if we have the enemy flag!
  200.             
  201.             if(Player::getItemCount(%playerClient, "Flag") > 0)
  202.             {
  203.                bottomprint(%playerClient, "<jc><f1>You captured the " @ getTeamName(%enemyTeam) @ " flag!", 5);
  204.                messageAll(%playerClient, "~wflagcapture.wav");
  205.                $flagAtHome[%enemyTeam] = true;
  206.                $flagCarrier[%enemyTeam] = -1;
  207.                GameBase::setPosition($flagObject[%enemyTeam], $flagPosition[%enemyTeam]);
  208.                Item::hide($flagObject[%enemyTeam], false);
  209.                Player::setItemCount(%object, "Flag", 0);
  210.                $captures++;
  211.                CTF::checkMissionObjectives();
  212.                CTFTraining::setWayPoint(%this);
  213.                moreAI($captures);
  214.             }
  215.          }
  216.       }
  217.       else
  218.       {
  219.          // it's the enemy's flag! woohoo!
  220.          Player::setItemCount(%object, %name, 1);
  221.          Player::mountItem(%object, %name, $FlagSlot, %flagTeam);
  222.          Item::hide($flagObject[%enemyTeam], true);
  223.          $flagAtHome[%enemyTeam] = false;
  224.          
  225.          if(!$flagDropped)
  226.            bottomprint(%playerClient, "<jc><f1>You took the " @ getTeamName(%enemyTeam) @ " flag!", 5);
  227.          else
  228.            bottomprint(%playerClient, "<jc><f1>You recovered the " @ getTeamName(%enemyTeam) @ " flag!", 5);
  229.          
  230.          messageall(%playerClient, "~wflag1.wav");
  231.          
  232.          $flagDropped = false;
  233.          $flagCarrier[%enemyTeam] = %object;
  234.          CTF::checkMissionObjectives();
  235.          $pickupSequence[%flagTeam] = $pickupSequence[%flagTeam] + 1;
  236.          CTFTraining::setWayPoint(%this);
  237.       }
  238.    }
  239. }
  240.  
  241. function CTF::teamMissionObjectives(%teamId)
  242. {
  243.    %enemyTeam = $enemyTeam[%teamId];
  244.    %teamName = getTeamName(%teamId);
  245.      
  246.    %enemyTeamName = getTeamName(%enemyTeam);
  247.    %flagCarrier = $flagCarrier[%teamId];
  248.    %enemyFlagCarrier = $flagCarrier[%enemyTeam];
  249.  
  250.  
  251.    %capsNeeded = $capstowin - $captures;
  252.   
  253.    if(%capsNeeded == 0)
  254.    {
  255.      return "True";
  256.    }
  257.    Team::setObjective(%teamId, 1, "<f5><jl>GamePlay Description:");
  258.    Team::setObjective(0, 2, "<f1><jl>    The objectives of a Capture the Flag mission are to find the enemy flag, take");  
  259.    Team::setObjective(0, 3, "<f1><jl>    it from their base, bring it back to your base and touch it to your flag.");
  260.    Team::setObjective(%teamId, 4, "\n");
  261.    Team::setObjective(%teamId, 5, "<f5><jl>Mission Completion:");
  262.    Team::setObjective(%teamId, 6, "<f1>   -3 flag captures");
  263.    Team::setObjective(%teamId, 7, "\n");
  264.    Team::setObjective(%teamId, 8, "<f5><jl>Mission Information:");
  265.    Team::setObjective(%teamId, 9, "<f1>   -Mission Name: Capture the Flag Training");
  266.    Team::setObjective(%teamId, 10, "<f1>   -Total Captures: " @ $captures);
  267.    Team::setObjective(%teamId, 12, "\n");
  268.    Team::setObjective(%teamId, 13, "<f5>Mission Objectives:");
  269.    
  270.    if($flagAtHome[%enemyTeam])
  271.    {
  272.       Team::setObjective(%teamId, 14,"<Bflag_enemycaptured.bmp>\n<f1>   Infiltrate the " @ %enemyTeamName @ " base and take their flag.");
  273.    }
  274.    else
  275.    {
  276.       if(%enemyFlagCarrier == -1)
  277.       {
  278.          Team::setObjective(%teamId, 14,"<Bflag_notatbase.bmp>\n<f1>   Enemy flag was dropped in the field.");
  279.       }
  280.       else
  281.       {
  282.          Team::setObjective(%teamId, 14,"<Bflag_atbase.bmp>\n<f1>   Return enemy flag to base for a capture.");
  283.       }
  284.    }
  285.    
  286.    
  287.    
  288.    return "False";
  289. }
  290.  
  291. function Player::leaveMissionArea(%this)
  292. {
  293.    // if a guy leaves the area, warp the flag back to its base
  294.    %flag = Player::getMountedItem(%this, $FlagSlot);
  295.    if(%flag != -1)
  296.    {
  297.       %playerClient = Player::getClient(%this);
  298.       bottomprint(%playerClient, "<f1><jc>You left the mission area while carrying the " @ getTeamName(1) @ " flag!", 5);
  299.       messageAll(0, "~wshell_click.wav");
  300.       messageAll(0, "The enemy flag was returned to thier base.~wflagreturn.wav");
  301.       Item::hide($flagObject[1], false);
  302.       Player::setItemCount(%this, "Flag", 0);
  303.       $flagCarrier[0] = -1;
  304.       $flagAtHome[1] = true;
  305.       GameBase::setPosition($flagObject[1], $flagPosition[1]);
  306.       ctf::checkMissionObjectives();
  307.       CTFTraining::setWayPoint($flagObject[0]);   
  308.    }   
  309. }
  310.  
  311. function Game::initialMissionDrop(%clientId)
  312. {
  313.   GameBase::setTeam(%clientId, 0);
  314.   Client::setGuiMode(%clientId, $GuiModePlay);
  315.   Game::playerSpawn(%clientId, false);
  316.   ctf::init(%clientId);
  317.   schedule("bottomprint(" @ %clientId @ ", \"<f1><jc>Training Mission 5 - Capture the Flag.\", 5);", 0);
  318.   schedule("messageAll(0, \"~wshell_click.wav\");", 0);
  319.   schedule("bottomprint(" @ %clientId @ ", \"<f1><jc>This mission will introduce you to the capture the flag game scenario.\", 5);", 5);
  320.   schedule("messageAll(0, \"~wshell_click.wav\");", 5);
  321.   schedule("bottomprint(" @ %clientId @ ", \"<f1><jc>Bring up The Objectives screen for a gameplay description.\", 5);", 10);
  322.   schedule("messageAll(0, \"~wshell_click.wav\");", 10);
  323.   Training::displayBitmap(0);
  324.   CTFTraining::setWayPoint($flagObject[0], true);
  325.   Training::setupAI(%clientId);
  326.       
  327. }
  328.                                                                                                       
  329. function missionSummary()
  330. {
  331.    %time = getSimTime() - $MatchStartTime;
  332.    
  333.    Training::displayBitmap(0);
  334.    
  335.    Team::setObjective(0, 1, "<f5><jl>Mission Completion:");
  336.    Team::setObjective(0, 2, "<f1><t>   -Completed:");
  337.    Team::setObjective(0, 3, "\n");
  338.    Team::setObjective(0, 4, "<f5><jl>Mission Information:");
  339.    Team::setObjective(0, 5, "<f1><t>   -Mission Name: Capture the Flag Training");
  340.    Team::setObjective(0, 6, "\n");
  341.    
  342.    Team::setObjective(0, 7, "<f5><j1>Mission Summary:");
  343.    
  344.    Team::setObjective(0, 8, "<f1><t>   -Enemy Kills: " @ "<f1>" @ $AIKilled @ " out of " @ $numGuards);
  345.    Team::setObjective(0, 9, "<f1><t>   -Total Mission Time: " @ "<f1>" @ Time::getMinutes(%time) @ " Minutes " @ Time::getSeconds(%time) @ " Seconds");
  346.    Team::setObjective(0, 10, "");
  347.    Team::setObjective(0, 11, "");
  348.    Team::setObjective(0, 12, "");
  349.    Team::setObjective(0, 13, "");
  350.    Team::setObjective(0, 14, "");
  351.    Team::setObjective(0, 15, "");
  352.    Team::setObjective(0, 16, "");
  353.    Team::setObjective(0, 17, "");
  354.    Team::setObjective(0, 18, "");
  355.    Team::setObjective(0, 19, "");
  356.    Team::setObjective(0, 20, "");
  357. }
  358.  
  359. function moreAI(%wave)
  360. {
  361.   if(%wave == 1)
  362.     %group = nameToId("MissionGroup\\AIwave1");
  363.   else if(%wave == 2)
  364.     %group = nameToId("MissionGroup\\AIwave2");
  365.  
  366.   if(%group == -1)
  367.      dbecho(2, "No AI exists...");  
  368.    
  369.   else 
  370.   {  
  371.      %clientId = Client::getFirst(); 
  372.      %AIname = "guard" @ $numGuards + 1;
  373.      createAI(%AIname, %group, larmor, $AI_Names[floor(getRandom() * 15)]);
  374.      %aiId = AI::getId( %AIname );
  375.      GameBase::setTeam(%aiId, 1);
  376.      AI::setVar( %AIname,  iq,  60 );
  377.      AI::setVar( %AIname,  attackMode, 0);
  378.      AI::DirectiveTarget(%AIname, %clientId);
  379.      
  380.   }
  381.     
  382.   AI::callWithId(%AIname, Player::setItemCount, disclauncher, 1);
  383.   AI::callWithId(%AIname, Player::setItemCount, discammo, 1000);
  384.   AI::callWithId(%AIname, Player::mountItem, disclauncher, 0);
  385.   //AI::SetVar(%AIname, triggerPct, 0.04 );
  386.   $numGuards++;
  387.   
  388. }
  389.  
  390. function Training::missionComplete(%cl)
  391. {
  392.   
  393.   schedule("Client::setGuiMode(" @ %cl @ ", " @ $GuiModeObjectives @ ");", 8);
  394.   missionSummary();
  395.   remoteEval(2049, TrainingEndMission);
  396. }
  397.  
  398. function remoteTrainingEndMission()
  399. {
  400.    schedule("EndGame();", 16);
  401. }
  402.  
  403.  
  404. function remoteScoresOn(%clientId)
  405. {
  406. }
  407.  
  408. function remoteScoresOff(%clientId)
  409. {
  410. }
  411.  
  412.  
  413. // set up initial objectives screen stuff.
  414. ctf::init();
  415. CTF::checkMissionObjectives();