home *** CD-ROM | disk | FTP | other *** search
- # Script file: MPGames.py
- # Purpose: Adjust the gold and experience point bonuses.
- # Detail: Gets the value from the tag and makes the adjustment and
- # stores it back into the tag.
- #
- from environ import *
- import whrandom
- def CTF( NumberOfPlayer, Allies, Start_Locations ) :
- #
- # Capture the flag specific setup, in this version there are
- # exactly two teams
- #
- sPythonSay( "MPGame.CTF.py setting up CTF game" )
- # Set up the alliances. Each alliance has an ID number.
- for AnAlliance in Allies :
- # The AllianceID is the PlayerID of the first player
- # in the alliance.
- AllianceID = AnAlliance[0]
- sPythonSay( "Processing an alliance" )
- for AAlly in AnAlliance :
- # Each player is given an A_ID tag that contains the
- # the AllianceID
- sAddTagDef( AAlly, "A_ID", "%d" % AllianceID )
- for BAlly in AnAlliance :
- sSetGoalProperty( "_System", "Likes",
- "set", [ AAlly, BAlly ] )
- sPythonSay(" Likes " + "%d" % AAlly + ",%d" % BAlly )
- # Don't forget, PlayerIDs start at 1, array starts at 0
- AllianceBase = Start_Locations[AllianceID - 1]
- sPythonSay(" AllianceID " + "%d" % AllianceID )
- sPythonSay(" x grid value " + "%d" % AllianceBase[0] )
- sPythonSay(" y grid value " + "%d" % AllianceBase[1] )
- if AllianceBase[0] == -1 :
- sPythonSay("Lead ally had no starting location")
- else :
- # Set up the base
- cl = sCreateUnit( "&V41",
- AllianceBase[0], AllianceBase[1], 9, 1, 1, 1 )
- sLinkScriptToUnit( cl, "V" + "%d" % AllianceID, "UOOP" )
- # Set up the flag, it's playerID is that of the alliance
- Flg = sCreateUnit( "&P9" + "%d" % AllianceID,
- AllianceBase[0], AllianceBase[1], AllianceID, 1, 1, 1 )
- # Set up the score flags
- sAddTagDef( 0, "FLG" + "%d" % AllianceID , "0")
- sPythonSay( "MPCTF done" )
-
- def CTF2( NumberOfPlayers, Start_Locations ) :
- # Set up the starting location
- PlayerID = 1
- for PlayerStarts in Start_Locations :
- sPythonSay(" x grid value " + "%d" % PlayerStarts[0] )
- sPythonSay(" y grid value " + "%d" % PlayerStarts[1] )
- if PlayerStarts[0] != -1 :
- # The flag takes it's id from the first member of the alliance.
- # Set up the base
- cl = sCreateUnit( "&V41" + "%d" % PlayerID,
- PlayerStarts[0], PlayerStarts[1], 9, 1, 1, 1 )
- sLinkScriptToUnit( cl, "V" + "%d" % PlayerID, "UOOP" )
- # Set up the flag
- Flg = sCreateUnit( "&P9" + "%d" % PlayerID,
- PlayerStarts[0], PlayerStarts[1], PlayerID, 1, 1, 1 )
- # Set up the score flags
- sAddTagDef( 0, "FLG" + "%d" % PlayerID, "0")
- PlayerID = PlayerID + 1
- sPythonSay( "MPCTF2 done" )
-
- def Tag( BaseID ) :
- # Purpose: Some one has used a flag on a pillar.
- # If it is not the flag of the the pillar's owner,
- # then increment the score of the pillar's owner.
- # BaseID is the PlayerID of the owner of the pillar
- # Trigger: UOOP
- #
- sPythonSay("Start Tag" )
- # Get the ID of the flag being used
- whichFlag = sTriggerUnit()
- if whichFlag != "&P91" and whichFlag != "&P92" and whichFlag != "&P93" and whichFlag != "&P94":
- return None
- FlagID = eval ( whichFlag[3:] )
- # Get the ID of the player who is doing the tag
- PlayerID = sTriggerUnitPlayerID()
- sPythonSay( "Flag " + whichFlag + " belonging to " + "%d" % PlayerID +
- " has been captured" )
- if sGetGameType() == "Capture the Flag 2" :
- # Free for all...You must use the flag on your own base
- if PlayerID == BaseID :
- # The object disappears
- sRemoveLastUsedObject()
- # Increment the score
- ScoreTag = "FLG" + "%d" % PlayerID
- Count1 = eval(sTagDefinition( 0, ScoreTag ) )
- sAddTagDef( 0, ScoreTag, "%d" % (Count1 + 1) )
- # The "Score" Voice-Over
- if sTagDefinition( 0, "WhoV" ) == "GVOMHO" :
- # Homah
- sPlayVO( "GVOMHO14" )
- else :
- # Poseidon
- sPlayVO( "GVOMPO012" )
- # Reset the flag
- Start_Locations = sListUsedStartRegions()
- # Player numbers start at 1, array locations start at 0
- PlayerStarts = Start_Locations[ FlagID - 1 ]
- sPythonSay( "Creating Flag at %d ," % PlayerStarts[0] +
- "%d" % PlayerStarts[1] )
- # Set up the flag
- Flg = sCreateUnit( whichFlag,
- PlayerStarts[0], PlayerStarts[1], FlagID, 1, 1, 1 )
- else :
- # CTF with Allies.
- # Get the AllianceID of the player trying the tag
- Allies = sListAllies()
- for AnAlliance in Allies :
- sPythonSay( "Processing an alliance" )
- for AAlly in AnAlliance :
- sPythonSay( "Processing player %d" % AAlly )
- if AAlly == PlayerID :
- AllianceID = AnAlliance[0]
- sPythonSay( "Setting AllianceID to %d" % AllianceID )
- # Alliances, you can only use the flag on the base of
- # your alliance
- if AllianceID == BaseID :
- # The object disappears
- sRemoveLastUsedObject()
- # Increment the score
- ScoreTag = "FLG" + "%d" % AllianceID
- Count1 = eval(sTagDefinition( 0, ScoreTag ) )
- sAddTagDef( 0, ScoreTag, "%d" % (Count1 + 1) )
- # The "Score" Voice-Over
- if sTagDefinition( 0, "WhoV" ) == "GVOMHO" :
- # Homah
- sPlayVO( "GVOMHO14" )
- else :
- # Poseidon
- sPlayVO( "GVOMPO012" )
- # Reset the flag
- Start_Locations = sListUsedStartRegions()
- # Player numbers start at 1, array locations start at 0
- PlayerStarts = Start_Locations[ FlagID - 1 ]
- sPythonSay( "Creating Flag at %d ," % PlayerStarts[0] +
- "%d" % PlayerStarts[1] )
- # Set up the flag
- Flg = sCreateUnit( whichFlag,
- PlayerStarts[0], PlayerStarts[1], FlagID, 1, 1, 1 )
- sPythonSay("Done Tag" )
-
- def MAD( NumberOfPlayers, Start_Locations ) :
- #Difficulty = "Easy"
- Difficulty = sGetDifficulty()
- sPythonSay( "Game is set to " + "%s" % Difficulty )
- if Difficulty == "Easy" :
- NPC_Count = 8
- if Difficulty == "Medium" :
- NPC_Count = 12
- if Difficulty == "Hard" :
- NPC_Count = 15
- # Re do the "Likes matrix"
- # NPCs for Player X are given Player ID X+4 and are friendly to
- # player X only
- for IFFa in range ( 1, 9 ) :
- for IFFb in range ( 1, 9 ) :
- if ( (IFFa == IFFb) or
- (IFFa + 4 == IFFb) or
- (IFFa == IFFb + 4) ) :
- sSetGoalProperty( "_System", "Likes",
- "set", [ IFFa, IFFb ] )
- else:
- sSetGoalProperty( "_System", "Likes",
- "clear", [ IFFa, IFFb ] )
-
- # Set up the NPCs around the player's starting location
- PlayerID = 1
- for PlayerStarts in Start_Locations :
- sPythonSay(" x grid value " + "%d" % PlayerStarts[0] )
- sPythonSay(" y grid value " + "%d" % PlayerStarts[1] )
- if PlayerStarts[0] != -1 :
- # The tag to count how many NPCs are left alive
- sAddTagDef( PlayerID, "NPC_", "%d" % NPC_Count )
- # Create the NPCs
- for NPC_Number in range ( 0, NPC_Count ) :
- if whrandom.random() < 0.5 :
- # Male
- Type = "&VI1"
- else :
- # Female
- Type = "&VI2"
- X_Loc = PlayerStarts[0] + whrandom.randint( -5, 5 )
- Y_Loc = PlayerStarts[1] + whrandom.randint( -5, 5 )
- NPC = sCreateUnit( Type, X_Loc, Y_Loc, PlayerID + 4, 1, 1, 1 )
- sPythonSay( " Creating NPC for Player " + "%d" % PlayerID )
- sLinkScriptToUnit( NPC, "NPC_DEAD_" + "%d" % PlayerID, "DEAD" )
- sSetGoalProperty( NPC , "RandomMoves", "bounds", [ PlayerStarts[0] - 5, PlayerStarts[1] - 5, PlayerStarts[0] + 5, PlayerStarts[1] + 5 ] )
- sSetGoalProperty( NPC , "RandomMoves", "eval", 100 )
- sSetGoalProperty( NPC , "RetreatFromAttack", "eval", 1000 )
- sSetGoalProperty( NPC , "RetreatFromEnemy", "radius", 10 )
- sSetGoalProperty( NPC , "RetreatFromEnemy", "eval", 900 )
- sRemoveGoal(NPC, "DefendSelf" )
- PlayerID = PlayerID + 1
- sPythonSay( "MPMAD done" )
- def BASH( ) :
- # Start the generator.
- # We will put the first call out almost immediately
- sCallScript( "Bash", 1000 )
- # Set up the score flags
- for PlayerID in [ "1", "2", "3", "4" ] :
- sAddTagDef( 0, "FLG" + PlayerID, "0")
- sPythonSay( "BASH done" )
- def NPC_DEAD( PlayerID ) :
- if sTagExists( PlayerID, "NPC_" ) :
- Count = eval( sTagDefinition( PlayerID, "NPC_" ) ) - 1
- sPythonSay( "Player " + "%d" % PlayerID + " had " + "%d" % Count + " NPCs" )
- sAddTagDef( PlayerID, "NPC_", "%d" % Count )
- if Count == 0 :
- sLocalEndScenario( PlayerID, 0 )
- else :
- sPythonSay( "NPC for non-existant player died" )
- def SetTimeLimit( TimeLimit ) :
- sPythonSay( "Setting time limits" )
- if TimeLimit != 0 :
- # The game has a time limit, so we will start the countdown 30 seconds
- # before the game is over. The CountDown script will set up
- # the call to the GameOver script
- sCallScript( "CountDown", TimeLimit - 30000 )
- sCallScriptParam( "VT", TimeLimit - 5000 , "08" )
- if TimeLimit > 60000 :
- sCallScriptParam( "VT", TimeLimit - 60000 , "07" )
- if TimeLimit > 120000 :
- sCallScriptParam( "VT", TimeLimit - 120000 , "06" )
- if TimeLimit > 180000 :
- sCallScriptParam( "VT", TimeLimit - 180000 , "05" )
- if TimeLimit > 300000 :
- sCallScriptParam( "VT", TimeLimit - 300000 , "04" )
- if TimeLimit > 600000 :
- sCallScriptParam( "VT", TimeLimit - 600000 , "03" )
- if TimeLimit > 900000 :
- sCallScriptParam( "VT", TimeLimit - 900000 , "02" )
- if TimeLimit > 1200000 :
- sCallScriptParam( "VT", TimeLimit - 1200000 , "01" )
-
- def Deathmatch( Allies ) :
- #
- # Alliance setup, in this version there are exactly two teams (?)
- #
- sPythonSay( "MPGame.Deathmatch.py setting up Deathmatch allies" )
- # Set up the alliances.
- for AnAlliance in Allies :
- sPythonSay( "Processing an alliance" )
- for AAlly in AnAlliance :
- for BAlly in AnAlliance :
- sSetGoalProperty( "_System", "Likes",
- "set", [ AAlly, BAlly ] )
- sPythonSay(" Likes " + "%d" % AAlly + ",%d" % BAlly )
- sPythonSay( "Deathmatch done" )
-
- def VO( GameType ) :
- # Play "starting instructions" if any.
- if GameType == "Capture the Flag" or GameType == "Capture the Flag 2" :
- choice = "%d" % whrandom.randint(4, 5)
- sPythonSay("Choice " + choice)
- sPlayVO( "MSDHO0" + choice)
- if GameType == "Free for All" :
- choice = "%d" % whrandom.randint(1, 3)
- sPythonSay("Choice " + choice)
- sPlayVO( "MSDHO0" + choice)
- if GameType == "Deathmatch" :
- choice = "%d" % whrandom.randint(1, 2)
- sPythonSay("Choice " + choice)
- sPlayVO( "MSDHO0" + choice)
- if GameType == "Monster Bash" :
- choice = "%d" % whrandom.randint(1, 2)
- sPythonSay("Choice " + choice)
- sPlayVO( "MSDPO0" + choice)
-
- def General( ) :
- sPythonSay( "MPGame.General.py " )
- #
- # SCRIPT SETUP
- #
- sAddScript( "V1", "MP_V1.TXT" )
- sAddScript( "V2", "MP_V2.TXT" )
- sAddScript( "V3", "MP_V3.TXT" )
- sAddScript( "V4", "MP_V4.TXT" )
- sAddScript( "End_Scenario", "END_SCENARIO.TXT" )
- sAddScript( "Easy", "MP_EASY.TXT" )
- sAddScript( "Medium", "MP_MEDIUM.TXT" )
- sAddScript( "Hard", "MP_HARD.TXT" )
- sAddScript( "MP_Gold", "MP_GOLD.TXT" )
- sAddScript( "NPC_DEAD_1", "MP_NPC_DEAD_1.TXT" )
- sAddScript( "NPC_DEAD_2", "MP_NPC_DEAD_2.TXT" )
- sAddScript( "NPC_DEAD_3", "MP_NPC_DEAD_3.TXT" )
- sAddScript( "NPC_DEAD_4", "MP_NPC_DEAD_4.TXT" )
- sAddScript( "Bash", "MP_BASH.TXT" )
- sAddScript( "Eaten", "MP_EAT.TXT" )
- sAddScript( "GameOver", "MP_GAMEOVER.TXT" )
- sAddScript( "CountDown", "MP_COUNTDOWN.TXT" )
- sAddScript( "VO", "MP_VO.TXT" )
- sAddScript( "VT", "MP_VT.TXT" )
- #
- # Random number initialization
- whrandom.seed()
- # Get the scenario information.
- NumberOfPlayers = sGetNumPlayers()
- Allies = sListAllies()
- Start_Locations = sListUsedStartRegions()
- # The system time limit is in minutes, we convert to milliseconds
- TimeLimit = sGetTimeLimit() * 60000
- sPythonSay( "Time Limit is " + "%d" % TimeLimit )
- SetTimeLimit( TimeLimit )
- GameType = sGetGameType()
- sPythonSay( "Game type is " + GameType )
- if whrandom.randint(1, 2) == 1 :
- # Use Homah's voice over for the count down
- sAddTagDef( 0, "WhoV", "GVOMHO" )
- else:
- # Use Poseidon's voice over for the count down
- sAddTagDef( 0, "WhoV", "GVOMPO0" )
- if GameType == "Capture the Flag" :
- CTF( NumberOfPlayers, Allies, Start_Locations )
- sCallScriptParam( "VO", 1000, GameType )
- if GameType == "Capture the Flag 2" :
- CTF2( NumberOfPlayers, Start_Locations )
- sCallScriptParam( "VO", 1000, GameType )
- if GameType == "MAD" :
- MAD( NumberOfPlayers, Start_Locations )
- # Shopping Spree has no special initialization
- # if GameType == "Shopping Spree" :
- if GameType == "Deathmatch" :
- # The only thing we need to do is set up the alliances
- Deathmatch( Allies )
- sCallScriptParam( "VO", 1000, GameType )
- if GameType == "Free for All" :
- sCallScriptParam( "VO", 1000, GameType )
- if GameType == "Monster Bash" :
- BASH( )
- sCallScriptParam( "VO", 1000, GameType )
- else :
- # All games except Monster Bash generate goodies
- # (Monsters can't pick up goodies!)
- # Need an API call to get the difficulty level
- Difficulty = sGetDifficulty()
- sPythonSay( "Game is set to " + "%s" % Difficulty )
- if Difficulty == "Easy" :
- Generate_Time = 20000
- if Difficulty == "Medium" :
- Generate_Time = 30000
- if Difficulty == "Hard" :
- Generate_Time = 40000
- sCallScript( Difficulty, Generate_Time )
-