if ( Mapgm == null ) { // Store it neatly under a global table. global Mapgm = table(); global MapGoals = table(); global MapScript = table(); global MapTestScript = table(); /////////////////////////////////////////////////////////////////////////////// // The function will take an expression of goals and output a trigger function in gm // script Mapgm.MakeGoalDef = function( GoalExp, Prefix ) { GoalTable = table(); GetGoals( GoalTable, 0, GoalExp ); ExpLength = GoalExp.Length() - 1; AddToName = ""; if ( Prefix ) { AddToName = Prefix; } foreach ( index and Goal in GoalTable ) { GoalName = Goal.GetName(); NewName = AddToName + GoalName.RightAt( ExpLength ); Util.AddToTable( MapScript, "\t" + NewName + " = \"" + GoalName + "\"," ); Util.AddToTable( MapTestScript, "\t" + NewName + " = \"" + GoalName + "\"," ); } }; /////////////////////////////////////////////////////////////////////////////// // The function will take a description and an expression of goals and output a goal // comments gm script Mapgm.MakeGoalTableComment = function( GoalDesc, GoalExp ) { AxisGoals = table(); AlliesGoals = table(); GoalTable = table(); GetGoals( GoalTable, 0, GoalExp ); foreach ( index and Goal in GoalTable ) { if ( Goal.IsAvailable( TEAM.AXIS ) ) { Util.AddToTable( AxisGoals, Goal.GetName() ); } if ( Goal.IsAvailable( TEAM.ALLIES ) ) { Util.AddToTable( AlliesGoals, Goal.GetName() ); } } if ( tableCount( AxisGoals ) ) { Util.AddToTable( MapGoals, "\/\/ Axis " + GoalDesc ); foreach ( index and GoalName in AxisGoals ) { Util.AddToTable( MapGoals, "\t" + GoalName ); } } if ( tableCount( AlliesGoals ) ) { Util.AddToTable( MapGoals, "\/\/ Allies " + GoalDesc ); foreach ( index and GoalName in AlliesGoals ) { Util.AddToTable( MapGoals, "\t" + GoalName ); } } }; /////////////////////////////////////////////////////////////////////////////// // The function will take an expression of goals and output a trigger function in gm // script Mapgm.MakeOnTriggerFunctions = function( GoalExp, Suffix ) { GoalTable = table(); GetGoals( GoalTable, 0, GoalExp ); ExpLength = GoalExp.Length() - 1; AddToName = ""; if ( Suffix ) { AddToName = Suffix; } foreach ( index and Goal in GoalTable ) { GoalName = Goal.GetName(); NewName = GoalName.RightAt( ExpLength ); NewName += AddToName; Util.AddToTable( MapScript, "\t" + NewName + " = function( trigger )" ); Util.AddToTable( MapScript, "\t{" ); Util.AddToTable( MapScript, "\t\tif ( TestMap )" ); Util.AddToTable( MapScript, "\t\t\t{ return; }" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapScript, "\t\tprint( \"" + NewName + "\" );" ); Util.AddToTable( MapScript, "\t}," ); Util.AddToTable( MapScript, "" ); } }; /////////////////////////////////////////////////////////////////////////////// // The function will take an expression of goals and output a trigger call in gm // script Mapgm.MakeOnTriggerCalls = function( GoalExp, Suffix ) { GoalTable = table(); GetGoals( GoalTable, 0, GoalExp ); ExpLength = GoalExp.Length() - 1; AddToName = ""; if ( Suffix ) { AddToName = Suffix; } foreach ( index and Goal in GoalTable ) { GoalName = Goal.GetName(); NewName = GoalName.RightAt( ExpLength ); NewName += AddToName; Util.AddToTable( MapScript, "\tOnTrigger( \"MISSING_STRING\", " + "Map." + NewName + " );" ); Util.AddToTable( MapTestScript, "\t\tOnTrigger( \"MISSING_STRING\", " + "Map." + NewName + " );" ); } }; /////////////////////////////////////////////////////////////////////////////// // The function will take an expression of goals and output a runtest call in gm // script Mapgm.MakeRunTestCalls = function( GoalExp, Prefix ) { GoalTable = table(); GetGoals( GoalTable, 0, GoalExp ); ExpLength = GoalExp.Length() - 1; AddToName = ""; if ( Prefix ) { AddToName = Prefix; } foreach ( index and Goal in GoalTable ) { GoalName = Goal.GetName(); NewName = AddToName + GoalName.RightAt( ExpLength ); if ( Goal.IsAvailable( TEAM.ALLIES ) ) { Util.AddToTable( MapTestScript, "\t\tTestMap.RunTest( TEAM.ALLIES, CLASS.ENGINEER, " + "Map." + NewName + ", 120, true );" ); } if ( Goal.IsAvailable( TEAM.AXIS ) ) { Util.AddToTable( MapTestScript, "\t\tTestMap.RunTest( TEAM.AXIS, CLASS.ENGINEER, " + "Map." + NewName + ", 120, true );" ); } } }; /////////////////////////////////////////////////////////////////////////////// // The function will create a map script template in gm script Mapgm.MakeMapgm = function() { Util.ProcessMovers(); MapName = GetMapName(); gmName = MapName + ".gm"; goalsName = MapName + "_goals.txt"; testName = MapName + "_test.gm"; Mapgm.MakeGoalTableComment( "Ammo Goals", "AMMO_.*" ); Mapgm.MakeGoalTableComment( "Attack Goals", "ATTACK_.*" ); Mapgm.MakeGoalTableComment( "Checkpoint Goals", "CHECKPOINT_.*" ); Mapgm.MakeGoalTableComment( "Defend Goals", "DEFEND_.*" ); Mapgm.MakeGoalTableComment( "Health Goals", "HEALTH_.*" ); Mapgm.MakeGoalTableComment( "Artyspot Goals", "MAP_ARTYSPOT_.*" ); Mapgm.MakeGoalTableComment( "Artytarget Goals", "MAP_ARTYTARGET_.*" ); Mapgm.MakeGoalTableComment( "Cappoint Goals", "MAP_CAPPOINT_.*" ); Mapgm.MakeGoalTableComment( "Construction Goals", "MAP_CONSTRUCTION_.*" ); Mapgm.MakeGoalTableComment( "Dynamite Target Goals", "MAP_DYNAMITE_TARGET_.*" ); Mapgm.MakeGoalTableComment( "Flag Goals", "MAP_FLAG_.*" ); Mapgm.MakeGoalTableComment( "Mobile MG42 Goals", "MAP_MOBILE_MG42_SPOT_.*" ); Mapgm.MakeGoalTableComment( "Mountable MG42 Goals", "MAP_MOUNTABLE_MG42_.*" ); Mapgm.MakeGoalTableComment( "Repair MG42 Goals", "MAP_REPAIR_MG42_.*" ); Mapgm.MakeGoalTableComment( "Sniper Spot Goals", "MAP_SNIPER_SPOT_.*" ); Mapgm.MakeGoalTableComment( "Mover Goals", "MAP_MOVER_.*" ); Mapgm.MakeGoalTableComment( "Plant Mine Goals", "PLANT_MINE_GOAL_.*" ); Util.AddToTable( MapScript, "global Map =" ); Util.AddToTable( MapScript, "{" ); Util.AddToTable( MapTestScript, "global Map =" ); Util.AddToTable( MapTestScript, "{" ); Mapgm.MakeGoalDef( "AMMO_CABINET.*", "Ammo_Cabinet_" ); Mapgm.MakeGoalDef( "CHECKPOINT.*", "Checkpoint_" ); Mapgm.MakeGoalDef( "HEALTH_CABINET.*", "Health_Cabinet_" ); Mapgm.MakeGoalDef( "MAP_CONSTRUCTION.*", "Build_" ); Mapgm.MakeGoalDef( "MAP_DYNAMITE_TARGET.*", "Destroy_" ); Mapgm.MakeGoalDef( "MAP_MOUNTABLE_MG42.*", "Mount_" ); Mapgm.MakeGoalDef( "MAP_REPAIR_MG42.*", "Repair_" ); Mapgm.MakeGoalDef( "MAP_MOVER.*", "Mover_" ); Mapgm.MakeGoalDef( "MAP_FLAG.*", "Flag_" ); Mapgm.MakeGoalDef( "MAP_CAPPOINT.*", "Cappoint_" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapTestScript, "" ); Mapgm.MakeOnTriggerFunctions( "MAP_CONSTRUCTION.*", "_Built" ); Mapgm.MakeOnTriggerFunctions( "MAP_DYNAMITE_TARGET.*", "_Destroyed" ); Util.AddToTable( MapScript, "\/\/~ \tAllies_Capture_Flag = function( trigger )" ); Util.AddToTable( MapScript, "\/\/~ \t{" ); Util.AddToTable( MapScript, "\/\/~ \t\tif ( TestMapOn )" ); Util.AddToTable( MapScript, "\/\/~ \t\t\t{ ETUtil.AutoTestMap(); }" ); Util.AddToTable( MapScript, "\/\/~ " ); Util.AddToTable( MapScript, "\/\/~ \t\tprint( \"Allies_Capture_Flag\" );" ); Util.AddToTable( MapScript, "\/\/~ \t}," ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapScript, "\/\/~ \tAxis_Capture_Flag = function( trigger )" ); Util.AddToTable( MapScript, "\/\/~ \t{" ); Util.AddToTable( MapScript, "\/\/~ \t\tif ( TestMapOn )" ); Util.AddToTable( MapScript, "\/\/~ \t\t\t{ ETUtil.AutoTestMap(); }" ); Util.AddToTable( MapScript, "\/\/~ " ); Util.AddToTable( MapScript, "\/\/~ \t\tprint( \"Axis_Capture_Flag\" );" ); Util.AddToTable( MapScript, "\/\/~ \t}," ); Util.AddToTable( MapScript, "};" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapScript, "global OnMapLoad = function()" ); Util.AddToTable( MapScript, "{" ); Util.AddToTable( MapScript, "\tif ( TestMapOn )" ); Util.AddToTable( MapScript, "\t\t{ ETUtil.AutoTestMap(); }" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapTestScript, "\tTests = function()" ); Util.AddToTable( MapTestScript, "\t{" ); Mapgm.MakeOnTriggerCalls( "MAP_CONSTRUCTION.*", "_Built" ); Mapgm.MakeOnTriggerCalls( "MAP_DYNAMITE_TARGET.*", "_Destroyed" ); Util.AddToTable( MapScript, "\/\/~ \tOnTrigger( \"MISSING_STRING\", Map.Allies_Capture_Flag );" ); Util.AddToTable( MapScript, "\/\/~ \tOnTrigger( \"MISSING_STRING\", Map.Axis_Capture_Flag );" ); Util.AddToTable( MapTestScript, "\/\/~ \t\tOnTrigger( \"MISSING_STRING\", Map.Allies_Capture_Flag );" ); Util.AddToTable( MapTestScript, "\/\/~ \t\tOnTrigger( \"MISSING_STRING\", Map.Axis_Capture_Flag );" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapTestScript, "" ); Util.AddToTable( MapScript, "\t\/\/~SetAvailableMapGoals( TEAM.ALLIES, false, \".*\" );" ); Util.AddToTable( MapScript, "\t\/\/~SetAvailableMapGoals( TEAM.AXIS, false, \".*\" );" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapScript, "\tprint( \"OnMapLoad\" );" ); Util.AddToTable( MapTestScript, "\t\tSetAvailableMapGoals( TEAM.ALLIES, false, \".*\" );" ); Util.AddToTable( MapTestScript, "\t\tSetAvailableMapGoals( TEAM.AXIS, false, \".*\" );" ); Util.AddToTable( MapTestScript, "" ); Mapgm.MakeRunTestCalls( "AMMO_CABINET.*", "Ammo_Cabinet_" ); Mapgm.MakeRunTestCalls( "HEALTH_CABINET.*", "Health_Cabinet_" ); Mapgm.MakeRunTestCalls( "MAP_CONSTRUCTION.*", "Build_" ); Mapgm.MakeRunTestCalls( "MAP_DYNAMITE_TARGET.*", "Destroy_" ); Mapgm.MakeRunTestCalls( "MAP_MOUNTABLE_MG42.*", "Mount_" ); Mapgm.MakeRunTestCalls( "MAP_MOVER.*", "Mover_" ); Mapgm.MakeRunTestCalls( "MAP_FLAG.*", "Flag_" ); Mapgm.MakeRunTestCalls( "MAP_CAPPOINT.*", "Cappoint_" ); Util.AddToTable( MapTestScript, "" ); Util.AddToTable( MapTestScript, "\t\tTestMap.Output( \"Tests Completed\" );" ); Util.AddToTable( MapScript, "};" ); Util.AddToTable( MapTestScript, "\t}," ); Util.AddToTable( MapTestScript, "};" ); Util.AddToTable( MapTestScript, "" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapScript, "\/\/ Uncomment for shootable breakables" ); Util.AddToTable( MapScript, "" ); Util.AddToTable( MapScript, "global OnBotJoin = function( bot )" ); Util.AddToTable( MapScript, "{" ); Util.AddToTable( MapScript, "\t\/\/~ bot.TargetBreakableDist = 300.0;" ); Util.AddToTable( MapScript, "};" ); Util.AddToTable( MapTestScript, "global OnBotJoin = function( bot )" ); Util.AddToTable( MapTestScript, "{" ); Util.AddToTable( MapTestScript, "\t\/\/~ bot.TargetBreakableDist = 300.0;" ); Util.AddToTable( MapTestScript, "};" ); gmfile = File(); assert( gmfile.Open( gmName, "text", false ) ); foreach( index and record in MapScript ) { if ( record == "" ) { assert( gmfile.Write( System.NewLine() ) ); continue; } assert( gmfile.Write( record, System.NewLine() ) ); } gmfile.Close(); goalsfile = File(); assert( goalsfile.Open( goalsName, "text", false ) ); foreach( index and record in MapGoals ) { if ( record == "" ) { assert( goalsfile.Write( System.NewLine() ) ); continue; } assert( goalsfile.Write( record, System.NewLine() ) ); } goalsfile.Close(); testfile = File(); assert( testfile.Open( testName, "text", false ) ); foreach( index and record in MapTestScript ) { if ( record == "" ) { assert( testfile.Write( System.NewLine() ) ); continue; } assert( testfile.Write( record, System.NewLine() ) ); } testfile.Close(); }; }