The first whole event
From WiCWiki
Contents |
The not at all famous last words and probably not even the last
This chapter is pretty boring, really, because it is mostly code. In this chapter we have everything you will need to get the first primary objective event and the first secondary objective event from the europeTest map up and running. This is the summary of all the ‘Appendix’ sub chapters from the tutorial so if you followed everything you probably won’t need this. If you are one of the dudes that reads the last chapter first you hopefully will get an idea of what chapters you will need to take a look at to understand. Hopefully we have covered the most important things so you will be able to continue on your own.
We once had a fantasy that we would do like this for the whole test map, but seriously, we have a life…sometimes…perhaps…STFU. J
The changed files in this chapter are:
Every file!
The whole server.py file
from serverimports import * import mapvars, allunits def OnGameStarted(): if IsSinglePlayer(): DebugMessage( "OnGameStarted:: Singel" ) # Disable multiplayer game modes theGame.PauseGameMode( ) # Hides all DropZone markers ClientCommand( 'HideAllDropZones' ) # Show the players DropZone marker EnableDropzone( True ) # Show Enemy Teams Dropships ShowAllDropships( True ) # Fade in to the game. theGame.FadeIn( 1.0 ) # Check if its a loaded game. if IsLoadedGame(): # Restores the GUI and starts the reaction manager after a game has been loaded. RestoreAfterLoad() else: # Setup the GUI. # We only want the mini map to be visible at the beginning, so we turn it on and let the # reinforcement and ta menu to be hidden. #theGame.ShowGUIChunk( 'reinforcements' ) #theGame.ShowGUIChunk( 'support' ) theGame.ShowGUIChunk( 'minimap' ) # Create all command points and hide them. CreateCommandPoints( ) # Start the mission. Intro( ) return 1 def Intro( ): DebugMessage( "Intro::" ) # Add deployment Zones to use later on. AddDeploymentZone( 'DZ_Village' ) # Set the players camera start position and the point it should look at. cameraStartPos = GetPosition( 'areaCamStartPos' ) cameraStartPos.myY = 170 cameraStartLookAt = GetPosition( 'areaPlayerStartPos' ) thePlayers[ PLAYER_HUMAN ].SetCameraPosition( cameraStartPos, cameraStartLookAt )
# Create the player starting units allunits.Player( ) # Setup all Events. VillageSetup( True ) RescueArtySetup( ) ##--------------------------------------------------------------- #--------------------------- Village --------------------------- def VillageSetup( aKickStart = False ): DebugMessage( "VillageSetup::" ) # create the Village objective object. mapvars.objVillage = Objective( 'Village', 'CP_Village', 'primary' ) # Setup the start reaction for the event. RE_OnCustomEvent( 'IntroEnd', Action( VillageCam ) ) RE_OnCustomEvent( 'VillageCamEnd', Action( VillageStart ) ) if aKickStart: DebugMessage( "VillageSetup::KickStart" ) PostEvent( 'IntroEnd' ) def VillageCam( ): DebugMessage( "VillageCam::" ) # Create the units that are defending the village. allunits.Village( ) # Start the objective camera for the village objective. We want the command point to be visible # in the camera so we set it to active and then shows a message box. queVillageCam = ActionQueue( 'queVillageCam' ) queVillageCam.AddFunction( SetCommandPointActive, 'CP_Village', True ) queVillageCam.AddFunction( StartClientCamera, 'ObjCamVillage', False ) queVillageCam.AddMessageBox( 'e1_1', 101 ) queVillageCam.Execute( ) # Setup reactions for what to do if/when the player click esc or the cam is done. RE_OnCustomEvent( 'END_OF_CUTSCENE', Action( PostEvent, 'VillageCamEnd' ) ) RE_OnCustomEvent( 'SKIP_CUTSCENE', Action( PostEvent, 'END_OF_CUTSCENE' ) ) def VillageStart( ): DebugMessage( "VillageStart::" ) # Now its time to add the objective and after that the event string disappears we post an event # to start the secondary rescue arty objective. queVillageStart = ActionQueue( 'queVillageStart' ) queVillageStart.AddObjective( mapvars.objVillage ) queVillageStart.AddFunction( PostEvent, 'RescueArtyStart' ) queVillageStart.Execute( ) # If the players lose all his units, fails the objective and show the mission fail screen. queVillageFail = ActionQueue( 'queVillageFail' ) queVillageFail.AddObjectiveFailed( mapvars.objVillage ) queVillageFail.AddFunction( wicg.EndGame, TEAM_USSR ) mapvars.reactVillagePlayerDead = RE_OnEmptyPlatoon( mapvars.pltPlayer, Action( queVillageFail.Execute ) ) # This queue controls what to do when the objective is completed, if the cp is control by NATO # or when the NATO takes it. We start with showing a message box before the objective is # completed. Now that we are done with the cp we can remove it and because the player was so # good we will give him/her a reward, be able to use the reinforcement menu. Starting by adding # a deployment zone to NATO, showing the menu and then add an event string. queVillageComplete = ActionQueue( 'queVillageComplete' ) queVillageComplete.AddMessageBox( 'e1_2', 102 ) queVillageComplete.AddObjectiveCompleted( mapvars.objVillage ) queVillageComplete.AddFunction( SetCommandPointActive, 'CP_Village', False ) queVillageComplete.AddFunction( AddDeploymentZoneToTeam, 'DZ_Village', TEAM_NATO ) queVillageComplete.AddFunction( theGame.ShowGUIChunk, 'reinforcements' ) queVillageComplete.AddEventString( 'myReinforcementMenu' ) queVillageComplete.AddFunction( VillageEnd ) # setup a reaction for when Nato takes the CP and then run the complete queue. And remove the fail reaction. # Use the complex reaction so we can test if NATO already owns the command point. RE_OnCommandPointTakenEx( [ 'CP_Village' ], TEAM_NATO, [ Action( RemoveReaction, mapvars.reactVillagePlayerDead ) ,Action( queVillageComplete.Execute ) ], True ) # Show a messagebox when we get in the first fight. RE_OnPlayerInCombatWithPlatoon( PLAYER_HUMAN, mapvars.pltVillage, Action( ShowMessageBox, 'e1_3', 103 ) ) def VillageEnd(): DebugMessage( 'VillageEnd::' ) # Post that the village event is done and we want to start the next one. PostEvent( 'VillageEnd' ) ##--------------------------------------------------------------- #------------------------- RescueArty ------------------------- def RescueArtySetup( aKickStart = False ): DebugMessage( 'RescueArtySetup::' ) allunits.RescueArty( ) mapvars.objRescueArty = Objective( 'RescueArty', 'areaArtySpawn', 'secondary' ) RE_OnCustomEvent( 'RescueArtyStart', Action( RescueArtyStart ) ) if aKickStart: PostEvent( 'RescueArtyStart' ) def RescueArtyStart( ): DebugMessage( 'RescueArtyStart::' ) # Make the reaction for complete and fail condition. mapvars.reactRescueArtyComplete = RE_OnEmptyGroup( mapvars.grpRescueArtyRu1, Action( PostEvent, 'RescueArtyRuDead' ) ) mapvars.reactRescueArtyFail = RE_OnEmptyGroup( mapvars.grpRescueArty, Action( PostEvent, 'RescueArtyDead' ) ) # Give the objective but wait 30 secunds before the units that are attacking the arty is created. queRescueArtyStart = ActionQueue( 'queRescueArtyStart' ) queRescueArtyStart.AddMessageBox( 'e1_4', 104 ) queRescueArtyStart.AddObjective( mapvars.objRescueArty ) queRescueArtyStart.AddFunction( Delay, 30, Action( allunits.RescueArtyAttack ) ) queRescueArtyStart.AddFunction( Delay, 30, Action( PostGroupSize, mapvars.grpRescueArtyRu1 ) ) queRescueArtyStart.Execute( ) # If the russian attacker has been killed, complete the objective and give the arty to the player as a reward. # Also remove the fail reaction. queRescueArtyComplete = ActionQueue( 'queRescueArtyComplete' ) queRescueArtyComplete.AddMessageBox( 'e1_5', 105 ) queRescueArtyComplete.AddObjectiveCompleted( mapvars.objRescueArty ) queRescueArtyComplete.AddFunction( allunits.RescueArtyGetUnit ) queRescueArtyComplete.AddEventString( 'myUnitReward' ) RE_OnCustomEvent( 'RescueArtyRuDead', [ Action( RemoveReaction, mapvars.reactRescueArtyFail ), Action( queRescueArtyComplete.Execute ) ] ) # If the arty is destroyed, fail the objective. # Also remove the complete reaction. queRescueArtyFail = ActionQueue( 'queRescueArtyFail' ) queRescueArtyFail.AddMessageBox( 'e1_6', 106 ) queRescueArtyFail.AddObjectiveFailed( mapvars.objRescueArty ) RE_OnCustomEvent( 'RescueArtyDead', [ Action( RemoveReaction, mapvars.reactRescueArtyComplete ), Action( queRescueArtyFail.Execute ) ] ) # Show a messagebox when the arty is under fire. RE_OnGroupInCombat( mapvars.grpRescueArty, Action( ShowMessageBoxQueue, 'e1_7', 107 ) ) def PostGroupSize( aGroup ): # Post the size of a group, PostEvent( 'GroupSize', aGroup, aGroup.Size( True ) ) def CreateCommandPoints( ): # Create a command point that are neutral. wicg.CreateCommandPointEx("CP_Village", 0, 0 ) # add a perimeter point to the command point. wicg.CreatePerimeterPointEx("PP_Village", "CP_Village") # Hide the command point and its perimeter point. SetCommandPointActive( "CP_Village", False )
The whole allunits.py file.
from serverimports import * from wicgame.ai import * import mapvars ##--------------------------------------------------------------- #--------------------------- Player ---------------------------- def Player( ): DebugMessage( 'allunits.Player::' ) # Create a group own by the player that has on heavy NATO tank. mapvars.grpPlayer1 = CreateGroup( 'grpPlayer1', [ NATO_LEOPARD2 ], 'areaPlayerStartPos', PLAYER_HUMAN, TEAM_NATO ) # set how many reinforcements point to get when the unit dies SetUnitCreditValue( mapvars.grpPlayer1.myUnits[ 0 ].myUnitId, GetUnitCost( 'NATO_Tank_Leopard2' ) ) # set with player that will get the point mapvars.grpPlayer1.SetGroupApOwner( PLAYER_HUMAN ) # Create one more group, this one own by the script player so that we can do stuff with it before we give it to the player. mapvars.grpPlayer2 = CreateGroup( 'grpPlayer2', [ NATO_LEOPARD2 ], 'areaPlayerSpawnPos', PLAYER_SCRIPT, TEAM_NATO ) SetUnitCreditValue( mapvars.grpPlayer2.myUnits[ 0 ].myUnitId, GetUnitCost( 'NATO_Tank_Leopard2' ) ) mapvars.grpPlayer2.SetGroupApOwner( PLAYER_HUMAN ) # Now lets post some command on the group, we want it to move to a position and make it look # at the CP before we gives it to the player. mapvars.grpPlayer2.PostCommand( CMD_RegroupAt( 'areaPlayerStartPos2', 'CP_Village' ) ) mapvars.grpPlayer2.PostCommand( CMD_SetOwner( PLAYER_HUMAN ) ) # Set the max and current reinforcement points that we want the player to have. Because we have # given the player some starting units we decrease there cost form the max value. thePlayers[ PLAYER_HUMAN ].myMaxAP = 6000 thePlayers[ PLAYER_HUMAN ].myCurrentAP = ( thePlayers[ PLAYER_HUMAN ].myMaxAP - GetUnitCost( [ 'NATO_Tank_Leopard2', 'NATO_Tank_Leopard2' ] ) ) # Set Tactical aid point cap. thePlayers[PLAYER_HUMAN].myMaxTacticalAid = 40 # Add units to the reinforcements meny AddToSPReinforcement( 'NATO_LandRover' ) AddToSPReinforcement( 'NATO_Warrior_APC' ) AddToSPReinforcement( 'NATO_AMX30' ) AddToSPReinforcement( 'NATO_Chieftain_MkV' ) AddToSPReinforcement( 'NATO_Tank_Leopard2' ) # Create a platoon and add the player groups. We are using the platoon to check if all of the players unit has been killed. mapvars.pltPlayer = Platoon( [mapvars.grpPlayer1, mapvars.grpPlayer2] ) ##--------------------------------------------------------------- #--------------------------- Village --------------------------- def Village( ): DebugMessage( 'allunits.Village::' ) # Create a USSR group that are own by the script player and add an attack and base behaviour. mapvars.grpVillageRu1 = CreateGroup( 'grpVillageRu1', [ USSR_BMP_3 ], 'areaVillageSpawn1', PLAYER_SCRIPT, TEAM_USSR ) mapvars.grpVillageRu1.SetAttackBehavior( BHA_StandFast( ) ) mapvars.grpVillageRu1.SetBaseBehavior( BHB_IdleUnits( 'areaVillageRuMove1' ) ) # Creates a USSR group that has two transport units, trucks. Then create two infantry squads that we # enter in to the trucks. We make the group a transporters group; it makes that only vehicles in the # group will move other wise the infantry will exit the transport when the group gets a move order. mapvars.grpVillageRu2 = CreateGroup( 'grpVillageRu2', [ USSR_TRUCK, USSR_TRUCK ], 'areaVillageSpawn2', PLAYER_SCRIPT, TEAM_USSR ) mapvars.grpVillageRu2.CreateSquad( [ USSR_MARINE, USSR_MARINE, USSR_MACHINE_GUNNER, USSR_ANTITANK ], 'areaVillageSpawn2' ) mapvars.grpVillageRu2.CreateSquad( [ USSR_MARINE, USSR_MARINE, USSR_MACHINE_GUNNER, USSR_ANTITANK ], 'areaVillageSpawn2' ) mapvars.grpVillageRu2.EnterGroup( None, True ) mapvars.grpVillageRu2.SetTransporterGroup( True ) # Move the group 50 units away from the Village CP then unload the infantry and set the attack and base behaviour. mapvars.grpVillageRu2.PostCommand( CMD_MoveGroup( 'CP_Village', 50 ) ) mapvars.grpVillageRu2.PostCommand( CMD_UnloadAll( ) ) mapvars.grpVillageRu2.PostCommand( CMD_SetAttackBehavior( BHA_Aggressive( ) ) ) mapvars.grpVillageRu2.PostCommand( CMD_SetBaseBehavior( BHB_IdleUnits( 'CP_Village' ) ) ) # Create a group that we sets to use cover formation on, that they will try to find position that are some what in cover. mapvars.grpVillageRu3 = CreateGroup( 'grpVillageRu3', [ USSR_MARINE, USSR_MARINE, USSR_AA_INFANTRY, USSR_MACHINE_GUNNER, USSR_ANTITANK ], 'areaVillageSpawn3', PLAYER_SCRIPT, TEAM_USSR ) mapvars.grpVillageRu3.SetFormation( FORMATION_COVER ) mapvars.grpVillageRu3.SetAttackBehavior( BHA_Defensive( ) ) mapvars.grpVillageRu3.SetBaseBehavior( BHB_IdleInfantryCover( 'areaVillageRuMove1' ) ) # Create a group that has three squads that we enter in to three buildings. mapvars.grpVillageBuilding = CreateGroup( 'grpVillageBuilding', [ ], None, PLAYER_SCRIPT, TEAM_USSR ) mapvars.grpVillageBuilding.CreateSquad( [ USSR_MARINE, USSR_ANTITANK ], 'areaVillageSpawn1' ) mapvars.grpVillageBuilding.CreateSquad( [ USSR_MARINE, USSR_ANTITANK ], 'areaVillageSpawn1' ) mapvars.grpVillageBuilding.CreateSquad( [ USSR_MARINE, USSR_ANTITANK ], 'areaVillageSpawn1' ) mapvars.grpVillageBuilding.EnterBuilding( [ 'CountryHouse_03__3', 'CountryHouse_01__2', 'CountryHouse_03__2' ], True ) # Add all the groups in to a non combat platoon, all groups attack behaviour won’t trigger if one of the groups gets in combat. mapvars.pltVillage = Platoon( [ mapvars.grpVillageRu1, mapvars.grpVillageRu2, mapvars.grpVillageRu3, mapvars.grpVillageBuilding ] ) mapvars.pltVillage.SetCombatPlatoon( False ) ##--------------------------------------------------------------- #------------------------- RescueArty ------------------------- def RescueArty( ): DebugMessage( 'allunits.RescueArty::' ) mapvars.grpRescueArty = CreateGroup( 'grpRescueArty', [ NATO_LARS_SF_2 ], 'areaArtySpawn', PLAYER_SCRIPT, TEAM_NATO ) mapvars.grpRescueArty.SetInvulnerable( True ) mapvars.grpRescueArty.RegroupAt( 'areaArtySpawn', 'areaAASpawn1' ) mapvars.grpRescueArty.SetBaseBehavior( BHB_AreaArtillery( [ Area( 'areaKillArtyFire1', 40 ), Area( 'areaKillArtyFire2', 40 ), Area( 'areaKillArtyFire3', 40 ) ], 15 ) ) mapvars.grpRescueArtyRu1 = CreateGroup( 'grpRescueArtyRu1', [ ], , PLAYER_SCRIPT, TEAM_USSR ) def RescueArtyAttack( ): DebugMessage( 'allunits.RescueArtyAttack::' ) mapvars.grpRescueArty.SetInvulnerable( False ) mapvars.grpRescueArtyRu1.CreateUnitsAtPosition( [ USSR_BMP_R, USSR_BMP_R ], 'areaKillArtyRuSpawn' ) mapvars.grpRescueArtyRu1.SetSpeed( 7 ) mapvars.grpRescueArtyRu1.SetAttackBehavior( BHA_Defensive( 40 ) ) mapvars.grpRescueArtyRu1.PostCommand( CMD_RegroupAt( 'areaKillArtyRuMove1', 'areaArtySpawn' ) ) mapvars.grpRescueArtyRu1.PostCommand( CMD_SetBaseBehavior( BHB_HoldPosition( 'areaKillArtyRuMove1' ) ) ) def RescueArtyGetUnit( ): DebugMessage( 'allunits.RescueArtyGetUnit::' ) # Remove all behavior from the group mapvars.grpRescueArty.Purge( ) # Give the unit to the player mapvars.grpRescueArty.SetOwner( PLAYER_HUMAN )
The whole mapvars.py file
##--------------------------------------------------------------- #--------------------------- Player ---------------------------- taAmbiance = None grpPlayer1 = None grpPlayer2 = None pltPlayer = None ##--------------------------------------------------------------- #--------------------------- Village --------------------------- objVillage = None reactVillagePlayerDead = None grpVillageRu1 = None grpVillageRu2 = None grpVillageRu3 = None grpVillageBuilding = None pltVillage = None ##--------------------------------------------------------------- #------------------------- RescueArty ------------------------- objRescueArty = None grpRescueArty = None grpRescueArtyRu1 = None reactRescueArtyComplete = None reactRescueArtyFail = None
The whole client.py file.
from clientimports import * ##--------------------------------------------------------------- #--------------------------- Village --------------------------- def ObjCamVillage( aIsBrowserCamera = True ): ObjCam0 = ObjectiveCameraEx( 'ObjCamVillage', aIsBrowserCamera ) p = ObjCam0.AddPoint( Position(994.983, 137.251, 1088.856), Position(988.932, 115.749, 1038.000), 2.000, 10.000 ) ObjCam0.SetEndDelayTime( 3.000 ) ObjCam0.SetCameraMaxSpeed( 120.000 ) ObjCam0.SetCameraMaxAcceleration( 100.000 ) ObjCam0.AddCommandPoints( [ "CP_Village" ] ) ObjCam0.Play( ) return ObjCam0 ##--------------------------------------------------------------- #------------------------- RescueArty ------------------------- def ObjCamRescueArty( aIsBrowserCamera = True ): ObjCam2 = ObjectiveCameraEx( 'ObjCamRescueArty', aIsBrowserCamera ) p = ObjCam2.AddPoint( Position(734.680, 137.148, 768.070), Position(711.929, 127.262, 735.337), 2.000, 10.000 ) ObjCam2.SetEndDelayTime( 3.000 ) ObjCam2.SetCameraMaxSpeed( 120.000 ) ObjCam2.SetCameraMaxAcceleration( 100.000 ) ObjCam2.UseEndGrab( False ) ObjCam2.Play() return ObjCam2
The whole europeTest.juice file
[more variables here] myMissionStats { myName do_Ruins mySPName "Script tutorial" myMapListName do_Ruins myDescription "Where a proud medieval castle once stood overlooking the ocean, NATO and Soviet forces now trade the first blows of World War III." mySPDescription "Where a proud medieval castle once stood overlooking the ocean, we have created the tutorial map." [more variables here] myAllowedTeam1 USSR myAllowedTeam2 NATO myAllowedTeam1SinglePlayer NATO myAllowedTeam2SinglePlayer USSR [more variables here]
The whole europeTest_singleplayerdata.juice file.
[More code is here] mySinglePlayerDeploymentAreaMask { FILE DZ_Village maps/europeTest/deploymentareamasks/DZ_Start.tga } myPrimaryObjectives { Objective Village { myDescription "Take the commandpoint." myLongDescription "Take the commandpoint to complete the objective." myOptionalImage <empty> myDontShowInPOLFlag 0 myOnClickPythonClientFunction ObjCamVillage myOnClickPythonServerFunction <empty> myVisualisationText "Take the commandpoint." } } mySecondaryObjectives { Objective RescueArty { myDescription "Keep the Nato artillery alive." myLongDescription "Keep the Nato artillery alive.\n\nTo complete this objective you must destroy the Russian attacker on the artillery.\\You will fail the mission if the Russians manage to destroy the artillery." myOptionalImage <empty> myDontShowInPOLFlag 0 myOnClickPythonClientFunction ObjCamRescueArty myOnClickPythonServerFunction <empty> myVisualisationText "Keep the Nato artillery alive." } } [More code is here] myMessageBoxList { MessageBoxData e1_1 { myType MB_TIMED myText "Take the commandpoint to complete the objective" mySoundFile <empty> myVideoPortraitFile messagebox_characters/wic/Sawyer.bik myPortraitText SAWYER myTimeToShow 6.0 } MessageBoxData e1_2 { myType MB_TIMED myText "Good job!" mySoundFile <empty> myVideoPortraitFile messagebox_characters/wic/Sawyer.bik myPortraitText SAWYER myTimeToShow 6.0 } MessageBoxData e1_3 { myType MB_TIMED myText "We have enemy contact." mySoundFile <empty> myVideoPortraitFile maps/europeTest/myPictures/tankDude.bik myPortraitText TANKDUDE myTimeToShow 6.0 } MessageBoxData e1_4 { myType MB_TIMED myText "I just got a call from our mortar detachment! They're under attack near the ruins. Aid them if possible." mySoundFile <empty> myVideoPortraitFile messagebox_characters/wic/Sawyer.bik myPortraitText SAWYER myTimeToShow 6.0 } MessageBoxData e1_5 { myType MB_TIMED myText "Well done. I'm giving you command of the mortars. Provide what support you can." mySoundFile <empty> myVideoPortraitFile messagebox_characters/wic/Sawyer.bik myPortraitText SAWYER myTimeToShow 6.0 } MessageBoxData e1_6 { myType MB_TIMED myText "I just lost contact with our mortar detachment. That's some good men we just lost." mySoundFile <empty> myVideoPortraitFile messagebox_characters/wic/Sawyer.bik myPortraitText SAWYER myTimeToShow 6.0 } MessageBoxData e1_7 { myType MB_TIMED myText "The artillery are taking hits, they need assistant now!" mySoundFile <empty> myVideoPortraitFile messagebox_characters/wic/Sawyer.bik myPortraitText SAWYER myTimeToShow 6.0 } }
Chapter 18: How we set us up the bomb < > Extra Chapter 1: Our Python files and Event Structure |