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

  1. //Training_retrieval.cs
  2.  
  3. $Train::missionType = "F&R";
  4. exec("game.cs");
  5. exec(Training_AI);
  6.  
  7. function Retrieval::init(%clientId)
  8. {
  9.    bottomprint(%clientId, "<jc><f1>Training Mission 7 - Find and Retrieve", 5);
  10.    schedule("bottomprint(" @ %clientId @ ", \"<f1><jc>This mission will introduce you to the Find and Retrieve game scenario.\", 5);", 5);
  11.    schedule("bottomprint(" @ %clientId @ ", \"<f1><jc>Bring up The Objectives screen for a gameplay description.\", 5);", 10);
  12.    schedule("messageAll(0, \"~wshell_click.wav\");", 0);
  13.    schedule("messageAll(0, \"~wshell_click.wav\");", 5);
  14.    schedule("messageAll(0, \"~wshell_click.wav\");", 10);
  15.    %player = Client::getOwnedObject(%clientId);
  16.    %player.hasFlag = false;
  17.    $flagDropped = false;
  18.    %player.flag    = "";
  19.    $flagReturnTime = 30;
  20.    %lineNum = 13;
  21.    $capsToWin = 0;
  22.    $captures = 0;
  23.    $ourBase = "-125.978 -91.6377 172.689";
  24.    $flagBase = "247.425 -284.296 211.108";
  25.    
  26.    %group = nameToID("MissionGroup\\Flags");
  27.     
  28.    %numObj = Group::objectCount(%group);
  29.    
  30.    for(%j = 0; %j < %numObj; %j++)
  31.    { 
  32.       %tempObj = Group::getObject(%group, %j);
  33.       
  34.       if(GameBase::getDataName(%tempObj) == flag)
  35.       {
  36.         %tempObj.lineNum = %lineNum++;
  37.         %tempObj.isMounted = false;
  38.         %tempObj.lost = false;
  39.         %tempObj.conveyed = false;
  40.         %tempObj.originalPos = GameBase::getPosition(%tempObj);
  41.         $capsToWin++;
  42.         retrieval::checkMissionObjectives(%clientId, %tempObj);
  43.       }
  44.    }
  45.    schedule("retrieval::setWayPoint(" @ %tempObj @ ", " @ %clientId @ ", " @ true @ ");", 15);
  46. }
  47.  
  48. function Game::initialMissionDrop(%clientId)
  49. {
  50.    GameBase::setTeam(%clientId, 0);
  51.    Client::setGuiMode(%clientId, $GuiModePlay);
  52.    Game::playerSpawn(%clientId, false);
  53.    Retrieval::init(%clientId);
  54.    Training::setupAI( %clientId );
  55. }
  56.  
  57. ///////////////////////////////////////
  58. //Flag functions
  59. ///////////////////////////////////////
  60. function FlagStand::onCollision(%this, %object)
  61. {
  62.    
  63.    %standTeam = GameBase::getTeam(%this);
  64.    %playerTeam = GameBase::getTeam(%object);
  65.    %playerClient = Player::getClient(%object);
  66.    
  67.    
  68.    if(getObjectType(%object) != "Player" || %playerTeam != %standTeam || %this.hasFlag)
  69.       return;
  70.  
  71.    if(%object.hasFlag)
  72.    {   
  73.       // if we're here, we're carrying a flag, we've hit 
  74.       // our flag stand, it doesn't have a flag.
  75.       
  76.       %flag = %object.flag;
  77.       Item::hide(%object.flag, false);
  78.       GameBase::setPosition(%object.flag, GameBase::getPosition(%this));
  79.        
  80.       Player::setItemCount(%object, "Flag", 0);
  81.       %this.hasFlag = true;
  82.       %object.hasFlag = false;
  83.       %object.flag.isMounted = true;
  84.       $captures++;
  85.       
  86.       if($captures != 3)
  87.       {  
  88.          bottomprint(%playerClient, "<jc><f1>You conveyed the " @ %object.flag.objective @ " to your base.", 5);
  89.            Training::moreAI($captures);
  90.       }
  91.       messageAll(%playerClient, "~wflagcapture.wav");
  92.       %object.flag = "";
  93.       %flag.conveyed = true;
  94.       
  95.       retrieval::checkMissionObjectives(%playerClient, %flag);
  96.       if($captures != 3)
  97.          retrieval::setWayPoint(%flag, %playerClient, false);
  98.    }
  99. }
  100.  
  101. function Flag::onCollision(%this, %object)
  102. {
  103.    if(getObjectType(%object) != "Player" || %object.hasFlag || %this.isMounted)
  104.       return;
  105.  
  106.    %playerClient = Player::getclient(%object);
  107.    %flagTeam = GameBase::getTeam(%this);
  108.    
  109.    Player::setItemCount(%object, "Flag", 1); 
  110.    Player::mountItem(%object, "Flag", $FlagSlot, %flagTeam);
  111.    Item::hide(%this, true);
  112.    %object.flag = %this;
  113.    %object.hasFlag = true;    
  114.    
  115.    if(!$flagDropped)
  116.      bottomprint(%playerClient, "<jc><f1>You took the " @ %this.objective @ " !", 5);
  117.    else
  118.    {  
  119.      bottomprint(%playerClient, "<jc><f1>You recovered the " @ %this.objective @ " !", 5);
  120.      %this.lost = "false";
  121.    }
  122.    messageall(%playerClient, "~wflag1.wav");
  123.    retrieval::checkMissionObjectives(%playerClient, %this);
  124.    retrieval::setWayPoint(%this, %playerClient, false);
  125. }
  126.  
  127. function Flag::onDrop(%player, %type)
  128. {
  129.    %playerTeam = GameBase::getTeam(%player);
  130.    %playerClient = Player::getClient(%player);
  131.    %dropClientName = Client::getName(Player::getClient(%player));
  132.    %flag = %player.flag;
  133.    %player.flag = "";
  134.    %player.hasFlag = false;
  135.    %flag.lost = true;
  136.    
  137.    bottomprint(%playerClient, "<jc><f1>You dropped the " @ %flag.objective @ " !", 5);
  138.    GameBase::throw(%flag, %player, 10, false);
  139.    Item::hide(%flag, false);
  140.    Player::setItemCount(%player, "Flag", 0);
  141.    
  142.    schedule("Retrieval::checkFlagReturn(" @ %flag @ ", " @ %playerClient @ ");", $flagReturnTime);
  143.    retrieval::checkMissionObjectives(%playerClient, %flag);
  144.    $flagDropped = true;
  145.    retrieval::setWayPoint(%flag, %playerClient, false);
  146. }
  147.  
  148. function Retrieval::checkFlagReturn(%this, %clientId)
  149. {
  150.    if(%this.lost)
  151.    {
  152.       bottomprint(%clientId, "<f1><jc>" @ %this.objective @ " was returned to its base.", 5);
  153.       dbecho(2,"moving flag to " @ %this.originalPos);
  154.       GameBase::startFadeOut(%this);
  155.       GameBase::setPosition(%this, %this.originalPos);
  156.       GameBase::startFadeIn(%this);
  157.       $flagDropped = false;
  158.       %this.lost = false;
  159.       retrieval::checkMissionObjectives(%clientId, %this);
  160.       retrieval::setWayPoint(%this, %clientId, false);
  161.    }
  162. }
  163.  
  164. function retrieval::setWayPoint(%flag, %cl, %init)
  165. {
  166.    %player = Client::getOwnedObject(%cl);
  167.    %flagPos = GameBase::getPosition(%flag);
  168.    %flagx = getWord(%flagpos, 0);
  169.    %flagy = getWord(%flagpos, 1);
  170.    
  171.    %homebasePos = $ourBase;
  172.    %homebasex = getWord(%homebasePos, 0);
  173.    %homebasey = getWord(%homebasePos, 1);
  174.    
  175.    %flagbasePos = $flagBase;
  176.    %flagbasex = getWord(%flagbasePos, 0);
  177.    %flagbasey = getWord(%flagbasePos, 1);  
  178.  
  179.    
  180.    if(%flag.lost)
  181.    {
  182.       schedule("bottomprint(" @ %cl @ ", \"<jc><f1>Waypoint set to " @ %flag.objective @ "\", 5);", 5);
  183.       issueCommand(%cl, %cl, 0, "Waypoint set to " @ %flag.objective, %flagx, %flagy);
  184.    }
  185.    else    if(%flag.conveyed || %init)
  186.    {
  187.       schedule("bottomprint(" @ %cl @ ", \"<jc><f1>Waypoint set to next objective\", 5);", 5);
  188.       issueCommand(%cl, %cl, 0, "Waypoint set to next objective", %flagbasex, %flagbasey);
  189.    }
  190.    else if(%player.hasFlag)
  191.    {
  192.       schedule("bottomprint(" @ %cl @ ", \"<jc><f1>Waypoint set back to your base\", 5);", 5);
  193.       issueCommand(%cl, %cl, 0, "Waypoint set to your base", %homebasex, %homebasey);
  194.    }
  195. }
  196.  
  197. function retrieval::checkMissionObjectives(%cl, %flag)
  198. {
  199.   if(retrieval::MissionObjectives( Client::getTeam(%cl), %cl, %flag ))
  200.    {
  201.       retrieval::MissionComplete( %cl );
  202.    }
  203. }
  204.  
  205. function retrieval::MissionObjectives( %teamId, %cl, %this )
  206. {
  207.    %enemyTeam = $enemyTeam[%teamId];
  208.    %teamName = getTeamName(%teamId); 
  209.    %player = Client::getOwnedObject(%cl);
  210.    %enemyTeamName = getTeamName(%enemyTeam);
  211.    %capsNeeded = $capstowin - $captures;
  212.   
  213.    if(%capsNeeded == 0)
  214.    {
  215.      return "True";
  216.    }
  217.    
  218.    Training::displayBitmap(0);
  219.    
  220.    Team::setObjective(%teamId, 1, "<f5><jl>GamePlay Description:");
  221.    Team::setObjective(0, 2, "<f1><jl>   In a Find and Retrieve mission, your team must find objectives placed in a");  
  222.    Team::setObjective(0, 3, "<f1><jl>   mission and bring them back to your base. This is similar to CTF, but the");
  223.    Team::setObjective(0, 4, "<f1><jl>   objectives are not owned by any one team in the beginning.  For every");
  224.    Team::setObjective(0, 5, "<f1><jl>   objective you return to your base, your team scores points.");
  225.    Team::setObjective(%teamId, 6, "\n");
  226.    Team::setObjective(%teamId, 7, "<f5><jl>Mission Completion:"); 
  227.    Team::setObjective(%teamId, 8, "<f1>   -Convey all objective flags to your base");
  228.    Team::setObjective(%teamId, 9, "\n");
  229.    Team::setObjective(%teamId, 10, "<f5>Mission Information:");
  230.    Team::setObjective(%teamId, 11, "<f1>   -Mission Name: Find and Retrieve Training"); 
  231.    Team::setObjective(%teamId, 12, "\n");
  232.    Team::setObjective(%teamId, 13, "<f5><jl>Mission Objectives:");
  233.  
  234.    if(%this.conveyed)
  235.    {
  236.       %status = "<Bflag_atbase.bmp><F1>\n    " @ %this.objective @ " has been conveyed";
  237.       
  238.    }
  239.    else
  240.    {
  241.       
  242.       if(%this.lost)
  243.       {
  244.          %status = "<Bflag_notatbase.bmp><f1>\n    " @ %this.objective @ " was dropped in the field";
  245.       }
  246.       else if($captures == 0 && !%player.hasFlag)
  247.       {
  248.          %status = "<Bflag_neutral.bmp><f1>\n    " @ %this.objective @ " has not been conveyed";
  249.       }
  250.       else if(%player.hasFlag)
  251.       {
  252.          %status = "<Bflag_atbase.bmp><f1>\n    Convey " @ %this.objective @ " to your base";
  253.       }
  254.       else
  255.          %status = "<Bflag_neutral.bmp><f1>\n    " @ %this.objective @ " has not been conveyed";
  256.    }
  257.    
  258.    if(%this.lineNum == 14)
  259.       Team::setObjective(%teamId, %this.lineNum, %status);
  260.    else if(%this.lineNum == 15)
  261.       Team::setObjective(%teamId, %this.lineNum, %status);
  262.    else if(%this.lineNum == 16)
  263.       Team::setObjective(%teamId, %this.lineNum, %status);
  264.  
  265.    return "False";
  266. }
  267.  
  268. function Retrieval::missionComplete(%cl)
  269. {
  270.   
  271.   schedule("Client::setGuiMode(" @ %cl @ ", " @ $GuiModeObjectives @ ");", 8);
  272.   missionSummary();
  273.   remoteEval(2049, TrainingEndMission);
  274. }
  275.  
  276. function remoteTrainingEndMission()
  277. {
  278.    schedule("EndGame();", 16);
  279. }
  280.  
  281. function missionSummary()
  282. {
  283.    %time = getSimTime() - $MatchStartTime;
  284.    
  285.    Training::displayBitmap(0);
  286.    
  287.    Team::setObjective(0, 1, "<f5><jl>Mission Completion:");
  288.    Team::setObjective(0, 2, "<f1><t>   -Completed:");
  289.    Team::setObjective(0, 3, "\n");
  290.    Team::setObjective(0, 4, "<f5><jl>Mission Information:");
  291.    Team::setObjective(0, 5, "<f1><t>   -Mission Name: Find and Retrieve Training");
  292.    Team::setObjective(0, 6, "\n");
  293.    
  294.    Team::setObjective(0, 7, "<f5><j1>Mission Summary:");
  295.    
  296.    Team::setObjective(0, 8, "<f1><t>   -Enemy Kills: " @ "<f1>" @ $AIKilled @ " out of " @ $numGuards);
  297.    Team::setObjective(0, 9, "<f1><t>   -Total Mission Time: " @ "<f1>" @ Time::getMinutes(%time) @ " Minutes " @ Time::getSeconds(%time) @ " Seconds");
  298.    Team::setObjective(0, 10, "");
  299.    Team::setObjective(0, 11, "");
  300.    Team::setObjective(0, 12, "");
  301.    Team::setObjective(0, 13, "");
  302.    Team::setObjective(0, 14, "");
  303.    Team::setObjective(0, 15, "");
  304.    Team::setObjective(0, 16, "");
  305.    Team::setObjective(0, 17, "");
  306.    Team::setObjective(0, 18, "");
  307.    Team::setObjective(0, 19, "");
  308.    Team::setObjective(0, 20, "");
  309.  
  310. }
  311.  
  312.  
  313. function Training::MoreAI(%wave)
  314. {
  315.   if(%wave == 1)
  316.     %group = nameToId("MissionGroup\\AIwave1");
  317.   else if(%wave == 2)
  318.     %group = nameToId("MissionGroup\\AIwave2");
  319.  
  320.   if(%group == -1)
  321.      dbecho(2,"No AI exists...");  
  322.    
  323.   else 
  324.   {  
  325.      %clientId = Client::getFirst(); 
  326.      %AIname = "guard" @ $numGuards + 1;
  327.      createAI(%AIname, %group, larmor, $AI_Names[ floor(getRandom() * 10) ]);
  328.      %aiId = AI::getId( %AIname );
  329.      GameBase::setTeam(%aiId, 1);
  330.      AI::setVar( %AIname,  iq,  70 );
  331.      AI::setVar( %AIname,  attackMode, 0);
  332.      AI::DirectiveTarget(%AIname, %clientId);
  333.   }
  334.   AI::callWithId(%AIname, Player::setItemCount, blaster, 1);
  335.   AI::callWithId(%AIname, Player::mountItem, blaster, 0);
  336.   AI::SetVar(%AIname, triggerPct, 0.04 );
  337.   $numGuards++;
  338.   
  339. }
  340.  
  341. function remoteScoresOn(%clientId)
  342. {
  343. }
  344.  
  345. function remoteScoresOff(%clientId)
  346. {
  347. }
  348.