home *** CD-ROM | disk | FTP | other *** search
/ Classic Fond 54 / ClassicFond54.iso / games / stars.rar / multiplayer / CTFstdLib.cs < prev    next >
Text File  |  1999-02-19  |  23KB  |  829 lines

  1. //
  2. // ctfStdLib.cs 
  3. //
  4. // Simple capture the flag routines
  5. //
  6.  
  7. // variables set by mission scripts
  8. // $flagValue: how many points gained for capturing a flag
  9. // $carrierValue: how many points gained for killing flag carrier
  10. // $killPoints:   how many points gained for killing non-flag carrier
  11. // $deathPoints:  how many points lost for getting killed
  12. // $maxFlagCount: how many flags must be captured to win
  13. // $flagTime: how much time does carrier have to return flag
  14.  
  15.  
  16. // internal globals
  17. // $teamFlagPoints:  how many points does a team get for capturing a flag
  18. // $scoringFreeze: if true, no more points can be scored
  19. // $<color>flagCarried: if true, flag has been grabbed
  20. // $<color>flagCount: if 1, flag is at home
  21. // $<color>carriersKilled: scorekeeping
  22. // $<color>flagsCollected: scorekeeping
  23. // $<color>navPoint: object id of each base's nav marker (if any)
  24.  
  25.  
  26. // stuff that has to be in the mission
  27. // four simGroups, one for each color:
  28. // MissionGroup\\<color>Base, containing:
  29. //    a staticShape called <color>Flag
  30. //    an ESNavmarker called NavPoint (optional)
  31.       
  32. //--------------------------------------------------------------------------------
  33.  
  34. // default values
  35. $teamFlagPoints = 1;
  36.  
  37. function setRules()
  38. {
  39.    // compose a big "rich text" string of the rules to be displayed in the 
  40.    // game info panel
  41.  
  42.    %rules = "<tIDMULT_CTF_GAMETYPE>"      @        
  43.             "<tIDMULT_CTF_MAPNAME>"       @ 
  44.             $missionName                  @  
  45.             "<tIDMULT_CTF_OBJECTIVES>"    @
  46.             "<tIDMULT_CTF_OBJECTIVES_2>"  @
  47.             timeDifference($flagTime,0)   @
  48.             "<tIDMULT_CTF_OBJECTIVES_3>"  @
  49.             "<tIDMULT_CTF_SCORING_1>"     @
  50.             "<tIDMULT_CTF_SCORING_2>"     @
  51.             $flagValue                    @
  52.             "<tIDMULT_CTF_SCORING_3>"     @
  53.             "<tIDMULT_CTF_SCORING_4>"     @
  54.             $carrierValue                 @
  55.             "<tIDMULT_CTF_SCORING_5>"     @
  56.             "<tIDMULT_CTF_SCORING_6>"     @
  57.             $deathPoints                  @
  58.             "<tIDMULT_CTF_SCORING_7>"     @
  59.             "<tIDMULT_CTF_SCORING_8>"     @
  60.             $killPoints                   @
  61.             "<tIDMULT_CTF_SCORING_9>"     @
  62.             "<tIDMULT_CTF_SCORING_10>"    @ 
  63.             $maxFlagCount                 @
  64.             "<tIDMULT_CTF_SCORING_11>"    @
  65.             "<tIDMULT_STD_ITEMS>"         @
  66.             "<tIDMULT_CTF_FLAGS>"         @
  67.             "<tIDMULT_CTF_GLOW>"          @
  68.             "<tIDMULT_STD_HEAL>"          @
  69.             "<tIDMULT_STD_RELOAD_1>"      @
  70.             $PadWaitTime                  @
  71.             "<tIDMULT_STD_RELOAD_2>"      @
  72.             "<tIDMULT_STD_ZEN_1>"         @
  73.             $ZenWaitTime                  @
  74.             "<tIDMULT_STD_ZEN_2>";
  75.    
  76.    setGameInfo(%rules);
  77. }
  78.  
  79. // anything that redefines the rules needs to do this
  80. // get the rules panel up and running
  81. // this has to be called after the definition of setRules
  82. setRules();
  83.  
  84.  
  85. //--------------------------------------------------------------------------------
  86.  
  87. function onMissionStart()
  88. {
  89.     initGlobalVars();
  90. }
  91.  
  92. function player::onAdd(%this)
  93. {
  94.    say(%this, 0, *IDMULT_CTF_WELCOME);
  95. }
  96.  
  97. //--------------------------------------------------------------------------------
  98. function vehicle::onAdd(%this)
  99. {
  100.     %team = getTeam(playerManager::vehicleIdToPlayerNum(%this));
  101.     %color = teamToColor(%team);
  102.     %flagKey = strcat(%color, "FlagCount");
  103.     
  104.        adjTeamCount(%team, 1);
  105.     
  106.     //if the flag isn't at the base, but no one has it, correct situation
  107.     if(dataRetrieve(0, %flagKey) && !dataRetrieve(0, strcat(%color, "FlagCarried")))
  108.     {
  109.         setFlag(%team, true);
  110.     }
  111. }
  112.  
  113. //--------------------------------------------------------------------------------
  114. function vehicle::onDestroyed(%destroyed,%destroyer)
  115. {
  116.    %team = getTeam(%destroyed);
  117.    adjTeamCount(%team, -1);
  118.    %teamCount = getTeamPlayerCount(%team);      
  119.  
  120.    if(%teamCount < 1)
  121.    {
  122.        setFlag(%team, false);                    
  123.    }
  124.  
  125.    %color = dataRetrieve(%destroyed, "hasFlag");
  126.    %flagTeam = colorToTeam(%color);
  127.    
  128.    // if the destroyed vehicle has a flag, it goes back to it's base
  129.    if (%color != "")
  130.    {
  131.       playerDropsFlag(%destroyed);
  132.       
  133.       // let everyone know this guy drops the flag
  134.       %str =
  135.          *IDMULT_CHAT_SURRENDER_FLAG_1 @
  136.          getName( %destroyed )         @
  137.          *IDMULT_CHAT_SURRENDER_FLAG_2 @ 
  138.          %flagTeam                     @
  139.          *IDMULT_CHAT_SURRENDER_FLAG_3;
  140.       
  141.       %soundFile = "";   
  142.       if(%flagTeam == *IDSTR_TEAM_RED)
  143.       {
  144.          %soundFile = "red_flag_sur.wav";
  145.       }
  146.       else if(%flagTeam == *IDSTR_TEAM_BLUE)
  147.       {
  148.          %soundFile = "blue_flag_sur.wav";
  149.       }
  150.       else if(%flagTeam == *IDSTR_TEAM_YELLOW)
  151.       {
  152.          %soundFile = "yel_flag_sur.wav";
  153.       }
  154.       else
  155.       {
  156.          %soundFile = "purp_flag_sur.wav";
  157.       }   
  158.       
  159.       say( 0, 0, %str, %soundFile );
  160.  
  161.             
  162.       if($scoringFreeze == false)
  163.       {     
  164.          // destroyer's team gets credit for killing the carrier
  165.          %destroyerTeam = getTeam(%destroyer);  
  166.       
  167.          // only give points if destroyed recovered his/her own flag
  168.          if(%destroyerTeam == colorToTeam(%color))
  169.          {
  170.             %key = strcat(teamToColor(getTeam(%destroyer)), "CarriersKilled");
  171.             dataStore(0, %key, 1 + dataRetrieve(0, %key));
  172.             
  173.             // player gets credit, too
  174.             %player = playerManager::vehicleIdToPlayerNum(%destroyer);
  175.             if(%player != 0)
  176.             {
  177.                %player.carriersKilled = %player.carriersKilled + 1;
  178.             }
  179.          }
  180.  
  181.          // echo the surrender to the console for logging
  182.          echo(*IDSTR_CONSOLE_CTF_SURRENDER @ " " @ playerManager::vehicleIdToPlayerNum(%destroyed));                        
  183.       }      
  184.    }
  185.    else
  186.    {
  187.       // not a flag carrier ... is it an enemy?
  188.       if($scoringFreeze == false)
  189.       {
  190.          if(getTeam(%destroyed) != getTeam(%destroyer))
  191.          {
  192.             %player = playerManager::vehicleIdToPlayerNum(%destroyer);
  193.             if(%player != 0)
  194.             {
  195.                %player.genericKills = %player.genericKills + 1;
  196.             }
  197.          }
  198.       }
  199.    }
  200.    
  201.    // enforce the rules
  202.    if(
  203.       (getTeam(%destroyed) == getTeam(%destroyer)) &&
  204.       (%destroyed != %destroyer)
  205.    )
  206.    {
  207.       antiTeamKill(%destroyer);
  208.    }
  209.  
  210.    vehicle::onDestroyedLog(%destroyed, %destroyer);
  211.    
  212.    // give the death messages...
  213.    %message = getFancyDeathMessage(getHUDName(%destroyed), getHUDName(%destroyer));
  214.    if(%message != "")
  215.    {
  216.       say( 0, 0, %message);
  217.    }
  218. }
  219.  
  220. //--------------------------------------------------------------------------------
  221. function setFlag(%team, %bool)
  222. {
  223.    %color = teamToColor(%team);
  224.  
  225.     %flagCountKey = strcat(%color, "FlagCount");
  226.     
  227.     // set flag to visible
  228.     if(%bool)
  229.     {
  230.       dataStore(0, %flagCountKey, 0);    
  231.        setShapeVisibility(getObjectId(strcat("MissionGroup\\", %color, "Base\\", %color, "Flag")), true);                
  232.     }
  233.     
  234.     // set flag to non-visible
  235.     else
  236.     {
  237.         dataStore(0, %flagCountKey, 1);
  238.         setShapeVisibility(getObjectId(strcat("MissionGroup\\", %color, "Base\\", %color, "Flag")),false);    
  239.     }
  240. }
  241.  
  242. function playerDropsFlag(%vehicle)
  243. {
  244.     // figure out which color of flag the guy is carrying
  245.    %color = dataRetrieve(%vehicle, "hasFlag");
  246.    %team = colorToTeam(%color);
  247.    // the player is no longer carrying this or any flag
  248.    dataRelease(%vehicle, "hasFlag");
  249.    setVehicleSpecialIdentity(%vehicle, false);
  250.    dataStore(0, strcat(%color, "FlagCarried"), 0);
  251.  
  252.    %teamPlayerCount = getTeamPlayerCount(%team);
  253.    
  254.    if(%teamPlayerCount < 1)
  255.    {
  256.       setFlag(%team, false);    
  257.    }    
  258.    else
  259.    {    
  260.        setFlag(%team, true);   
  261.    }
  262.    
  263.    // reset the timer for this person
  264.    %vehicle.timer = 0;
  265.    
  266.    // turn off the hudtimer
  267.    %player = playerManager::vehicleIdToPlayerNum(%vehicle);
  268.    setHudTimer(0, 0, "", 1, %player);