home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Classic Fond 54
/
ClassicFond54.iso
/
games
/
stars.rar
/
multiplayer
/
CTFstdLib.cs
< prev
next >
Wrap
Text File
|
1999-02-19
|
23KB
|
829 lines
//
// ctfStdLib.cs
//
// Simple capture the flag routines
//
// variables set by mission scripts
// $flagValue: how many points gained for capturing a flag
// $carrierValue: how many points gained for killing flag carrier
// $killPoints: how many points gained for killing non-flag carrier
// $deathPoints: how many points lost for getting killed
// $maxFlagCount: how many flags must be captured to win
// $flagTime: how much time does carrier have to return flag
// internal globals
// $teamFlagPoints: how many points does a team get for capturing a flag
// $scoringFreeze: if true, no more points can be scored
// $<color>flagCarried: if true, flag has been grabbed
// $<color>flagCount: if 1, flag is at home
// $<color>carriersKilled: scorekeeping
// $<color>flagsCollected: scorekeeping
// $<color>navPoint: object id of each base's nav marker (if any)
// stuff that has to be in the mission
// four simGroups, one for each color:
// MissionGroup\\<color>Base, containing:
// a staticShape called <color>Flag
// an ESNavmarker called NavPoint (optional)
//--------------------------------------------------------------------------------
// default values
$teamFlagPoints = 1;
function setRules()
{
// compose a big "rich text" string of the rules to be displayed in the
// game info panel
%rules = "<tIDMULT_CTF_GAMETYPE>" @
"<tIDMULT_CTF_MAPNAME>" @
$missionName @
"<tIDMULT_CTF_OBJECTIVES>" @
"<tIDMULT_CTF_OBJECTIVES_2>" @
timeDifference($flagTime,0) @
"<tIDMULT_CTF_OBJECTIVES_3>" @
"<tIDMULT_CTF_SCORING_1>" @
"<tIDMULT_CTF_SCORING_2>" @
$flagValue @
"<tIDMULT_CTF_SCORING_3>" @
"<tIDMULT_CTF_SCORING_4>" @
$carrierValue @
"<tIDMULT_CTF_SCORING_5>" @
"<tIDMULT_CTF_SCORING_6>" @
$deathPoints @
"<tIDMULT_CTF_SCORING_7>" @
"<tIDMULT_CTF_SCORING_8>" @
$killPoints @
"<tIDMULT_CTF_SCORING_9>" @
"<tIDMULT_CTF_SCORING_10>" @
$maxFlagCount @
"<tIDMULT_CTF_SCORING_11>" @
"<tIDMULT_STD_ITEMS>" @
"<tIDMULT_CTF_FLAGS>" @
"<tIDMULT_CTF_GLOW>" @
"<tIDMULT_STD_HEAL>" @
"<tIDMULT_STD_RELOAD_1>" @
$PadWaitTime @
"<tIDMULT_STD_RELOAD_2>" @
"<tIDMULT_STD_ZEN_1>" @
$ZenWaitTime @
"<tIDMULT_STD_ZEN_2>";
setGameInfo(%rules);
}
// anything that redefines the rules needs to do this
// get the rules panel up and running
// this has to be called after the definition of setRules
setRules();
//--------------------------------------------------------------------------------
function onMissionStart()
{
initGlobalVars();
}
function player::onAdd(%this)
{
say(%this, 0, *IDMULT_CTF_WELCOME);
}
//--------------------------------------------------------------------------------
function vehicle::onAdd(%this)
{
%team = getTeam(playerManager::vehicleIdToPlayerNum(%this));
%color = teamToColor(%team);
%flagKey = strcat(%color, "FlagCount");
adjTeamCount(%team, 1);
//if the flag isn't at the base, but no one has it, correct situation
if(dataRetrieve(0, %flagKey) && !dataRetrieve(0, strcat(%color, "FlagCarried")))
{
setFlag(%team, true);
}
}
//--------------------------------------------------------------------------------
function vehicle::onDestroyed(%destroyed,%destroyer)
{
%team = getTeam(%destroyed);
adjTeamCount(%team, -1);
%teamCount = getTeamPlayerCount(%team);
if(%teamCount < 1)
{
setFlag(%team, false);
}
%color = dataRetrieve(%destroyed, "hasFlag");
%flagTeam = colorToTeam(%color);
// if the destroyed vehicle has a flag, it goes back to it's base
if (%color != "")
{
playerDropsFlag(%destroyed);
// let everyone know this guy drops the flag
%str =
*IDMULT_CHAT_SURRENDER_FLAG_1 @
getName( %destroyed ) @
*IDMULT_CHAT_SURRENDER_FLAG_2 @
%flagTeam @
*IDMULT_CHAT_SURRENDER_FLAG_3;
%soundFile = "";
if(%flagTeam == *IDSTR_TEAM_RED)
{
%soundFile = "red_flag_sur.wav";
}
else if(%flagTeam == *IDSTR_TEAM_BLUE)
{
%soundFile = "blue_flag_sur.wav";
}
else if(%flagTeam == *IDSTR_TEAM_YELLOW)
{
%soundFile = "yel_flag_sur.wav";
}
else
{
%soundFile = "purp_flag_sur.wav";
}
say( 0, 0, %str, %soundFile );
if($scoringFreeze == false)
{
// destroyer's team gets credit for killing the carrier
%destroyerTeam = getTeam(%destroyer);
// only give points if destroyed recovered his/her own flag
if(%destroyerTeam == colorToTeam(%color))
{
%key = strcat(teamToColor(getTeam(%destroyer)), "CarriersKilled");
dataStore(0, %key, 1 + dataRetrieve(0, %key));
// player gets credit, too
%player = playerManager::vehicleIdToPlayerNum(%destroyer);
if(%player != 0)
{
%player.carriersKilled = %player.carriersKilled + 1;
}
}
// echo the surrender to the console for logging
echo(*IDSTR_CONSOLE_CTF_SURRENDER @ " " @ playerManager::vehicleIdToPlayerNum(%destroyed));
}
}
else
{
// not a flag carrier ... is it an enemy?
if($scoringFreeze == false)
{
if(getTeam(%destroyed) != getTeam(%destroyer))
{
%player = playerManager::vehicleIdToPlayerNum(%destroyer);
if(%player != 0)
{
%player.genericKills = %player.genericKills + 1;
}
}
}
}
// enforce the rules
if(
(getTeam(%destroyed) == getTeam(%destroyer)) &&
(%destroyed != %destroyer)
)
{
antiTeamKill(%destroyer);
}
vehicle::onDestroyedLog(%destroyed, %destroyer);
// give the death messages...
%message = getFancyDeathMessage(getHUDName(%destroyed), getHUDName(%destroyer));
if(%message != "")
{
say( 0, 0, %message);
}
}
//--------------------------------------------------------------------------------
function setFlag(%team, %bool)
{
%color = teamToColor(%team);
%flagCountKey = strcat(%color, "FlagCount");
// set flag to visible
if(%bool)
{
dataStore(0, %flagCountKey, 0);
setShapeVisibility(getObjectId(strcat("MissionGroup\\", %color, "Base\\", %color, "Flag")), true);
}
// set flag to non-visible
else
{
dataStore(0, %flagCountKey, 1);
setShapeVisibility(getObjectId(strcat("MissionGroup\\", %color, "Base\\", %color, "Flag")),false);
}
}
function playerDropsFlag(%vehicle)
{
// figure out which color of flag the guy is carrying
%color = dataRetrieve(%vehicle, "hasFlag");
%team = colorToTeam(%color);
// the player is no longer carrying this or any flag
dataRelease(%vehicle, "hasFlag");
setVehicleSpecialIdentity(%vehicle, false);
dataStore(0, strcat(%color, "FlagCarried"), 0);
%teamPlayerCount = getTeamPlayerCount(%team);
if(%teamPlayerCount < 1)
{
setFlag(%team, false);
}
else
{
setFlag(%team, true);
}
// reset the timer for this person
%vehicle.timer = 0;
// turn off the hudtimer
%player = playerManager::vehicleIdToPlayerNum(%vehicle);
setHudTimer(0, 0, "", 1, %player);