home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2000 May / maximum-cd-2000-05.iso / Invictus / data1.cab / Game_Files / Assets / Scripts / modules / MPGames.py < prev    next >
Encoding:
Python Source  |  2000-02-25  |  12.8 KB  |  349 lines

  1. # Script file:  MPGames.py
  2. # Purpose:      Adjust the gold and experience point bonuses.
  3. # Detail:       Gets the value from the tag and makes the adjustment and
  4. #          stores it back into the tag.
  5. #
  6. from environ import *
  7. import whrandom
  8. def CTF( NumberOfPlayer, Allies, Start_Locations ) :
  9.     #
  10.     # Capture the flag specific setup, in this version there are 
  11.     #  exactly two teams
  12.     #
  13.     sPythonSay( "MPGame.CTF.py setting up CTF game" )
  14.     # Set up the alliances. Each alliance has an ID number.
  15.     for AnAlliance in Allies :
  16.         # The AllianceID is the PlayerID of the first player 
  17.         #  in the alliance.
  18.         AllianceID = AnAlliance[0]
  19.         sPythonSay( "Processing an alliance" )
  20.         for AAlly in AnAlliance : 
  21.             # Each player is given an A_ID tag that contains the
  22.             #  the AllianceID
  23.             sAddTagDef( AAlly, "A_ID", "%d" % AllianceID )
  24.             for BAlly in AnAlliance : 
  25.                 sSetGoalProperty( "_System", "Likes", 
  26.                     "set", [ AAlly, BAlly ] )
  27.                 sPythonSay(" Likes " + "%d" % AAlly + ",%d" % BAlly )
  28.         # Don't forget, PlayerIDs start at 1, array starts at 0
  29.         AllianceBase = Start_Locations[AllianceID - 1]
  30.         sPythonSay(" AllianceID " + "%d" % AllianceID )
  31.         sPythonSay(" x grid value " + "%d" % AllianceBase[0] )
  32.         sPythonSay(" y grid value " + "%d" % AllianceBase[1] )
  33.         if AllianceBase[0] == -1 :
  34.             sPythonSay("Lead ally had no starting location")
  35.         else :
  36.             # Set up the base
  37.             cl = sCreateUnit( "&V41", 
  38.                 AllianceBase[0], AllianceBase[1], 9, 1, 1, 1 )
  39.             sLinkScriptToUnit( cl, "V" + "%d" % AllianceID, "UOOP" )
  40.             # Set up the flag, it's playerID is that of the alliance
  41.             Flg = sCreateUnit( "&P9" + "%d" % AllianceID, 
  42.                 AllianceBase[0], AllianceBase[1], AllianceID, 1, 1, 1 )
  43.                 # Set up the score flags
  44.             sAddTagDef( 0, "FLG" + "%d" % AllianceID , "0")
  45.     sPythonSay( "MPCTF done" )
  46.  
  47. def CTF2( NumberOfPlayers, Start_Locations ) :
  48.     # Set up the starting location
  49.     PlayerID = 1
  50.     for PlayerStarts in Start_Locations : 
  51.         sPythonSay(" x grid value " + "%d" % PlayerStarts[0] )
  52.         sPythonSay(" y grid value " + "%d" % PlayerStarts[1] )
  53.         if PlayerStarts[0] != -1 :
  54.             # The flag takes it's id from the first member of the alliance.
  55.             # Set up the base
  56.             cl = sCreateUnit( "&V41" + "%d" % PlayerID, 
  57.                 PlayerStarts[0], PlayerStarts[1], 9, 1, 1, 1 )
  58.             sLinkScriptToUnit( cl, "V" + "%d" % PlayerID, "UOOP" )
  59.             # Set up the flag
  60.             Flg = sCreateUnit( "&P9" + "%d" % PlayerID, 
  61.                 PlayerStarts[0], PlayerStarts[1], PlayerID, 1, 1, 1 )
  62.             # Set up the score flags
  63.             sAddTagDef( 0, "FLG" + "%d" % PlayerID, "0")
  64.         PlayerID = PlayerID + 1
  65.     sPythonSay( "MPCTF2 done" )
  66.  
  67. def Tag( BaseID ) :
  68.     # Purpose:      Some one has used a flag  on a pillar.
  69.     #        If it is not the flag of the the pillar's owner, 
  70.     #          then increment the score of the pillar's owner.
  71.     #        BaseID is the PlayerID of the owner of the pillar
  72.     # Trigger:      UOOP
  73.     #
  74.     sPythonSay("Start Tag" )
  75.     # Get the ID of the flag being used
  76.     whichFlag = sTriggerUnit()
  77.     if whichFlag != "&P91" and whichFlag != "&P92" and whichFlag != "&P93" and whichFlag != "&P94":
  78.         return None
  79.     FlagID = eval ( whichFlag[3:] )
  80.     # Get the ID of the player who is doing the tag
  81.     PlayerID = sTriggerUnitPlayerID()
  82.     sPythonSay( "Flag " + whichFlag + " belonging to " + "%d" % PlayerID +
  83.                  " has been captured" )
  84.     if sGetGameType() == "Capture the Flag 2" :
  85.         # Free for all...You must use the flag on your own base
  86.         if PlayerID == BaseID :
  87.             # The object disappears
  88.             sRemoveLastUsedObject()
  89.             # Increment the score
  90.             ScoreTag = "FLG" + "%d" % PlayerID
  91.             Count1 = eval(sTagDefinition( 0, ScoreTag )  )
  92.             sAddTagDef( 0, ScoreTag, "%d" % (Count1 + 1) )
  93.             # The "Score" Voice-Over
  94.             if sTagDefinition( 0, "WhoV" ) == "GVOMHO" :
  95.                 # Homah
  96.                 sPlayVO( "GVOMHO14" )
  97.             else :
  98.                 # Poseidon
  99.                 sPlayVO( "GVOMPO012" )
  100.             # Reset the flag
  101.             Start_Locations = sListUsedStartRegions()
  102.             # Player numbers start at 1, array locations start at 0
  103.             PlayerStarts = Start_Locations[ FlagID - 1 ]
  104.             sPythonSay( "Creating Flag at %d ," % PlayerStarts[0] +
  105.                                 "%d" % PlayerStarts[1] )
  106.             # Set up the flag
  107.             Flg = sCreateUnit( whichFlag,
  108.                 PlayerStarts[0], PlayerStarts[1], FlagID, 1, 1, 1 )
  109.     else :
  110.         # CTF with Allies.
  111.         # Get the AllianceID of the player trying the tag
  112.         Allies =  sListAllies()
  113.         for AnAlliance in Allies :
  114.             sPythonSay( "Processing an alliance" )
  115.             for AAlly in AnAlliance : 
  116.                 sPythonSay( "Processing player %d" % AAlly )
  117.                 if AAlly == PlayerID :
  118.                     AllianceID = AnAlliance[0]
  119.                     sPythonSay( "Setting AllianceID to %d" % AllianceID )
  120.         # Alliances, you can only use the flag on the base of 
  121.         #  your alliance
  122.         if AllianceID == BaseID :
  123.             # The object disappears
  124.             sRemoveLastUsedObject()
  125.             # Increment the score
  126.             ScoreTag = "FLG" + "%d" % AllianceID
  127.             Count1 = eval(sTagDefinition( 0, ScoreTag )  )
  128.             sAddTagDef( 0, ScoreTag, "%d" % (Count1 + 1) )
  129.             # The "Score" Voice-Over
  130.             if sTagDefinition( 0, "WhoV" ) == "GVOMHO" :
  131.                 # Homah
  132.                 sPlayVO( "GVOMHO14" )
  133.             else :
  134.                 # Poseidon
  135.                 sPlayVO( "GVOMPO012" )
  136.             # Reset the flag
  137.             Start_Locations = sListUsedStartRegions()
  138.             # Player numbers start at 1, array locations start at 0
  139.             PlayerStarts = Start_Locations[ FlagID - 1 ]
  140.             sPythonSay( "Creating Flag at %d ," % PlayerStarts[0] +
  141.                                 "%d" % PlayerStarts[1] )
  142.             # Set up the flag
  143.             Flg = sCreateUnit( whichFlag,
  144.                 PlayerStarts[0], PlayerStarts[1], FlagID, 1, 1, 1 )
  145.     sPythonSay("Done Tag" )
  146.  
  147. def MAD( NumberOfPlayers, Start_Locations ) :
  148.     #Difficulty = "Easy"
  149.     Difficulty = sGetDifficulty()
  150.     sPythonSay( "Game is set to " + "%s" % Difficulty )
  151.     if Difficulty == "Easy" :
  152.         NPC_Count = 8
  153.     if Difficulty == "Medium" :
  154.         NPC_Count = 12
  155.     if Difficulty == "Hard" :
  156.         NPC_Count = 15
  157.     # Re do the "Likes matrix"
  158.     # NPCs for Player X are given Player ID X+4 and are friendly to
  159.     #  player X only
  160.     for IFFa in range ( 1, 9 ) :
  161.         for IFFb in range ( 1, 9 ) :
  162.             if ( (IFFa == IFFb) or 
  163.                  (IFFa + 4 == IFFb) or
  164.                  (IFFa == IFFb + 4) ) :
  165.                 sSetGoalProperty( "_System", "Likes", 
  166.                     "set", [ IFFa, IFFb ] )
  167.             else:
  168.                 sSetGoalProperty( "_System", "Likes", 
  169.                     "clear", [ IFFa, IFFb ] )
  170.             
  171.     # Set up the NPCs around the player's starting location
  172.     PlayerID = 1
  173.     for PlayerStarts in Start_Locations : 
  174.         sPythonSay(" x grid value " + "%d" % PlayerStarts[0] )
  175.         sPythonSay(" y grid value " + "%d" % PlayerStarts[1] )
  176.         if PlayerStarts[0] != -1 :
  177.             # The tag to count how many NPCs are left alive
  178.             sAddTagDef( PlayerID, "NPC_", "%d" % NPC_Count )
  179.             # Create the NPCs
  180.             for NPC_Number in range ( 0, NPC_Count ) :
  181.                 if whrandom.random() < 0.5 :
  182.                     # Male
  183.                     Type = "&VI1"
  184.                 else :
  185.                     # Female
  186.                     Type = "&VI2"
  187.                 X_Loc = PlayerStarts[0] + whrandom.randint( -5, 5 )
  188.                 Y_Loc = PlayerStarts[1] + whrandom.randint( -5, 5 )
  189.                 NPC = sCreateUnit( Type, X_Loc, Y_Loc, PlayerID + 4, 1, 1, 1 )
  190.                 sPythonSay( " Creating NPC for Player " + "%d" % PlayerID )
  191.                 sLinkScriptToUnit( NPC, "NPC_DEAD_" + "%d" % PlayerID, "DEAD" )
  192.                 sSetGoalProperty( NPC , "RandomMoves", "bounds", [ PlayerStarts[0] - 5, PlayerStarts[1] - 5, PlayerStarts[0] + 5, PlayerStarts[1] + 5 ] )
  193.                 sSetGoalProperty( NPC , "RandomMoves", "eval", 100 )
  194.                 sSetGoalProperty( NPC , "RetreatFromAttack", "eval", 1000 )
  195.                 sSetGoalProperty( NPC , "RetreatFromEnemy", "radius", 10 )
  196.                 sSetGoalProperty( NPC , "RetreatFromEnemy", "eval", 900 )
  197.                 sRemoveGoal(NPC, "DefendSelf" )
  198.         PlayerID = PlayerID + 1
  199.     sPythonSay( "MPMAD done" )
  200. def BASH( ) :
  201.     # Start the generator.
  202.     # We will put the first call out almost immediately
  203.     sCallScript( "Bash", 1000 )
  204.     # Set up the score flags
  205.     for PlayerID in [ "1", "2", "3", "4" ] :
  206.         sAddTagDef( 0, "FLG" + PlayerID, "0")
  207.     sPythonSay( "BASH done" )
  208. def NPC_DEAD( PlayerID ) :
  209.     if sTagExists( PlayerID, "NPC_" ) :
  210.         Count = eval( sTagDefinition( PlayerID, "NPC_" ) ) - 1
  211.         sPythonSay( "Player " + "%d" % PlayerID + " had " + "%d" % Count + " NPCs" )
  212.         sAddTagDef( PlayerID, "NPC_", "%d" % Count )
  213.         if Count == 0 :
  214.             sLocalEndScenario( PlayerID, 0 )
  215.     else :
  216.         sPythonSay( "NPC for non-existant player died" )
  217. def SetTimeLimit( TimeLimit ) :
  218.     sPythonSay( "Setting time limits" )
  219.     if TimeLimit != 0 :
  220.         # The game has a time limit, so we will start the countdown 30 seconds 
  221.         #  before the game is over. The CountDown script will set up
  222.         #  the call to the GameOver script
  223.         sCallScript( "CountDown", TimeLimit - 30000 )
  224.     sCallScriptParam( "VT", TimeLimit - 5000 , "08" )
  225.     if TimeLimit > 60000 :
  226.         sCallScriptParam( "VT", TimeLimit - 60000 , "07" )
  227.     if TimeLimit > 120000 :
  228.         sCallScriptParam( "VT", TimeLimit - 120000 , "06" )
  229.     if TimeLimit > 180000 :
  230.         sCallScriptParam( "VT", TimeLimit - 180000 , "05" )
  231.     if TimeLimit > 300000 :
  232.         sCallScriptParam( "VT", TimeLimit - 300000 , "04" )
  233.     if TimeLimit > 600000 :
  234.         sCallScriptParam( "VT", TimeLimit - 600000 , "03" )
  235.     if TimeLimit > 900000 :
  236.         sCallScriptParam( "VT", TimeLimit - 900000 , "02" )
  237.     if TimeLimit > 1200000 :
  238.         sCallScriptParam( "VT", TimeLimit - 1200000 , "01" )
  239.  
  240. def Deathmatch( Allies ) :
  241.     #
  242.     # Alliance setup, in this version there are  exactly two teams (?)
  243.     #
  244.     sPythonSay( "MPGame.Deathmatch.py setting up Deathmatch allies" )
  245.     # Set up the alliances.
  246.     for AnAlliance in Allies :
  247.         sPythonSay( "Processing an alliance" )
  248.         for AAlly in AnAlliance : 
  249.             for BAlly in AnAlliance : 
  250.                 sSetGoalProperty( "_System", "Likes", 
  251.                     "set", [ AAlly, BAlly ] )
  252.                 sPythonSay(" Likes " + "%d" % AAlly + ",%d" % BAlly )
  253.     sPythonSay( "Deathmatch done" )
  254.  
  255. def VO( GameType ) :
  256.     # Play "starting instructions" if any.
  257.     if GameType == "Capture the Flag" or GameType == "Capture the Flag 2" :
  258.         choice = "%d" % whrandom.randint(4, 5)
  259.         sPythonSay("Choice " + choice)
  260.         sPlayVO( "MSDHO0" + choice)
  261.     if GameType == "Free for All" :
  262.         choice = "%d" % whrandom.randint(1, 3)
  263.         sPythonSay("Choice " + choice)
  264.         sPlayVO( "MSDHO0" + choice)
  265.     if GameType == "Deathmatch" :
  266.         choice = "%d" % whrandom.randint(1, 2)
  267.         sPythonSay("Choice " + choice)
  268.         sPlayVO( "MSDHO0" + choice)
  269.     if GameType == "Monster Bash" :
  270.         choice = "%d" % whrandom.randint(1, 2)
  271.         sPythonSay("Choice " + choice)
  272.         sPlayVO( "MSDPO0" + choice)
  273.  
  274. def General( ) :
  275.     sPythonSay( "MPGame.General.py " )
  276.     #
  277.     # SCRIPT SETUP
  278.     #
  279.     sAddScript( "V1", "MP_V1.TXT" )
  280.     sAddScript( "V2", "MP_V2.TXT" )
  281.     sAddScript( "V3", "MP_V3.TXT" )
  282.     sAddScript( "V4", "MP_V4.TXT" )
  283.     sAddScript( "End_Scenario", "END_SCENARIO.TXT" )
  284.     sAddScript( "Easy", "MP_EASY.TXT" )
  285.     sAddScript( "Medium", "MP_MEDIUM.TXT" )
  286.     sAddScript( "Hard", "MP_HARD.TXT" )
  287.     sAddScript( "MP_Gold", "MP_GOLD.TXT" )
  288.     sAddScript( "NPC_DEAD_1", "MP_NPC_DEAD_1.TXT" )
  289.     sAddScript( "NPC_DEAD_2", "MP_NPC_DEAD_2.TXT" )
  290.     sAddScript( "NPC_DEAD_3", "MP_NPC_DEAD_3.TXT" )
  291.     sAddScript( "NPC_DEAD_4", "MP_NPC_DEAD_4.TXT" )
  292.     sAddScript( "Bash", "MP_BASH.TXT" )
  293.     sAddScript( "Eaten", "MP_EAT.TXT" )
  294.     sAddScript( "GameOver", "MP_GAMEOVER.TXT" )
  295.     sAddScript( "CountDown", "MP_COUNTDOWN.TXT" )
  296.     sAddScript( "VO", "MP_VO.TXT" )
  297.     sAddScript( "VT", "MP_VT.TXT" )
  298.     #
  299.     # Random number initialization
  300.     whrandom.seed()
  301.     # Get the scenario information.
  302.     NumberOfPlayers = sGetNumPlayers()
  303.     Allies =  sListAllies()
  304.     Start_Locations = sListUsedStartRegions()
  305.     # The system time limit is in minutes, we convert to milliseconds
  306.     TimeLimit = sGetTimeLimit() * 60000
  307.     sPythonSay( "Time Limit is " + "%d" % TimeLimit )
  308.     SetTimeLimit( TimeLimit )
  309.     GameType = sGetGameType()
  310.     sPythonSay( "Game type is " + GameType )
  311.     if whrandom.randint(1, 2) == 1 :
  312.         # Use Homah's voice over for the count down
  313.         sAddTagDef( 0, "WhoV", "GVOMHO" )
  314.     else:
  315.         # Use Poseidon's voice over for the count down
  316.         sAddTagDef( 0, "WhoV", "GVOMPO0" )
  317.     if GameType == "Capture the Flag" :
  318.         CTF( NumberOfPlayers, Allies, Start_Locations ) 
  319.         sCallScriptParam( "VO", 1000, GameType )
  320.     if GameType == "Capture the Flag 2" :
  321.         CTF2( NumberOfPlayers, Start_Locations ) 
  322.         sCallScriptParam( "VO", 1000, GameType )
  323.     if GameType == "MAD" :
  324.         MAD( NumberOfPlayers, Start_Locations ) 
  325.     # Shopping Spree has no special initialization
  326.     # if GameType == "Shopping Spree" :
  327.     if GameType == "Deathmatch" :
  328.         # The only thing we need to do is set up the alliances
  329.         Deathmatch( Allies ) 
  330.         sCallScriptParam( "VO", 1000, GameType )
  331.     if GameType == "Free for All" :
  332.         sCallScriptParam( "VO", 1000, GameType )
  333.     if GameType == "Monster Bash" :
  334.         BASH( ) 
  335.         sCallScriptParam( "VO", 1000, GameType )
  336.     else :
  337.         # All games except Monster Bash generate goodies
  338.         #  (Monsters can't pick up goodies!)
  339.         # Need an API call to get the difficulty level
  340.         Difficulty = sGetDifficulty()
  341.         sPythonSay( "Game is set to " + "%s" % Difficulty )
  342.         if Difficulty == "Easy" :
  343.             Generate_Time = 20000
  344.         if Difficulty == "Medium" :
  345.             Generate_Time = 30000
  346.         if Difficulty == "Hard" :
  347.             Generate_Time = 40000
  348.         sCallScript( Difficulty, Generate_Time )
  349.