CSHARP 203
Dom.gsc Guest on 18th April 2021 07:32:45 PM
  1. #include maps\mp\_utility;
  2. #include maps\mp\gametypes\_hud_util;
  3. /*
  4.     Domination
  5.     Objective:  Capture all the flags by touching them
  6.     Map ends:   When one team captures all the flags, or time limit is reached
  7.     Respawning: No wait / Near teammates
  8.  
  9.     Level requirements
  10.     ------------------
  11.         Spawnpoints:
  12.             classname       mp_tdm_spawn
  13.             All players spawn from these. The spawnpoint chosen is dependent on the current locations of owned flags, teammates and
  14.             enemies at the time of spawn. Players generally spawn behind their teammates relative to the direction of enemies.
  15.             Optionally, give a spawnpoint a script_linkto to specify which flag it "belongs" to (see Flag Descriptors).
  16.  
  17.         Spectator Spawnpoints:
  18.             classname       mp_global_intermission
  19.             Spectators spawn from these and intermission is viewed from these positions.
  20.             Atleast one is required, any more and they are randomly chosen between.
  21.  
  22.         Flags:
  23.             classname       trigger_radius
  24.             targetname      flag_primary or flag_secondary
  25.             Flags that need to be captured to win. Primary flags take time to capture; secondary flags are instant.
  26.        
  27.         Flag Descriptors:
  28.             classname       script_origin
  29.             targetname      flag_descriptor
  30.             Place one flag descriptor close to each flag. Use the script_linkname and script_linkto properties to say which flags
  31.             it can be considered "adjacent" to in the level. For instance, if players have a primary path from flag1 to flag2, and
  32.             from flag2 to flag3, flag2 would have a flag_descriptor with these properties:
  33.             script_linkname flag2
  34.             script_linkto flag1 flag3
  35.            
  36.             Set scr_domdebug to 1 to see flag connections and what spawnpoints are considered connected to each flag.
  37.  
  38.     Level script requirements
  39.     -------------------------
  40.         Team Definitions:
  41.             game["allies"] = "marines";
  42.             game["axis"] = "opfor";
  43.             This sets the nationalities of the teams. Allies can be american, british, or russian. Axis can be german.
  44.  
  45.         If using minefields or exploders:
  46.             maps\mp\_load::main();
  47.  
  48.     Optional level script settings
  49.     ------------------------------
  50.         Soldier Type and Variation:
  51.             game["american_soldiertype"] = "normandy";
  52.             game["german_soldiertype"] = "normandy";
  53.             This sets what character models are used for each nationality on a particular map.
  54.  
  55.             Valid settings:
  56.                 american_soldiertype    normandy
  57.                 british_soldiertype     normandy, africa
  58.                 russian_soldiertype     coats, padded
  59.                 german_soldiertype      normandy, africa, winterlight, winterdark
  60. */
  61.  
  62. /*QUAKED mp_dom_spawn (0.5 0.5 1.0) (-16 -16 0) (16 16 72)
  63. Players spawn near their flags at one of these positions.*/
  64.  
  65. /*QUAKED mp_dom_spawn_axis_start (1.0 0.0 1.0) (-16 -16 0) (16 16 72)
  66. Axis players spawn away from enemies and near their team at one of these positions at the start of a round.*/
  67.  
  68. /*QUAKED mp_dom_spawn_allies_start (0.0 1.0 1.0) (-16 -16 0) (16 16 72)
  69. Allied players spawn away from enemies and near their team at one of these positions at the start of a round.*/
  70.  
  71. main()
  72. {
  73.     if(getdvar("mapname") == "mp_background")
  74.         return;
  75.  
  76.     maps\mp\gametypes\_globallogic::init();
  77.     maps\mp\gametypes\_callbacksetup::SetupCallbacks();
  78.     maps\mp\gametypes\_globallogic::SetupCallbacks();
  79.     if(level.ex_blackscreen) maps\mp\gametypes\_blackscreen::init();
  80.  
  81.     maps\mp\gametypes\_globallogic::registerTimeLimitDvar( "dom", 30, 0, 1440 );
  82.     maps\mp\gametypes\_globallogic::registerScoreLimitDvar( "dom", 300, 0, 1000 );
  83.     maps\mp\gametypes\_globallogic::registerRoundLimitDvar( "dom", 1, 0, 10 );
  84.     maps\mp\gametypes\_globallogic::registerNumLivesDvar( "dom", 0, 0, 10 );
  85.    
  86.     level.teamBased = true;
  87.     level.overrideTeamScore = true;
  88.     level.onStartGameType = ::onStartGameType;
  89.     level.onSpawnPlayer = ::onSpawnPlayer;
  90.     level.onPlayerKilled = ::onPlayerKilled;
  91.     level.onPrecacheGameType = ::onPrecacheGameType;
  92.  
  93.     game["dialog"]["gametype"] = "domination";
  94.     game["dialog"]["offense_obj"] = "capture_objs";
  95.     game["dialog"]["defense_obj"] = "capture_objs";
  96. }
  97.  
  98.  
  99. onPrecacheGameType()
  100. {
  101.     precacheShader( "compass_waypoint_captureneutral" );
  102.     precacheShader( "compass_waypoint_capture" );
  103.     precacheShader( "compass_waypoint_defend" );
  104.     precacheShader( "compass_waypoint_captureneutral_a" );
  105.     precacheShader( "compass_waypoint_capture_a" );
  106.     precacheShader( "compass_waypoint_defend_a" );
  107.     precacheShader( "compass_waypoint_captureneutral_b" );
  108.     precacheShader( "compass_waypoint_capture_b" );
  109.     precacheShader( "compass_waypoint_defend_b" );
  110.     precacheShader( "compass_waypoint_captureneutral_c" );
  111.     precacheShader( "compass_waypoint_capture_c" );
  112.     precacheShader( "compass_waypoint_defend_c" );
  113.     precacheShader( "compass_waypoint_captureneutral_d" );
  114.     precacheShader( "compass_waypoint_capture_d" );
  115.     precacheShader( "compass_waypoint_defend_d" );
  116.     precacheShader( "compass_waypoint_captureneutral_e" );
  117.     precacheShader( "compass_waypoint_capture_e" );
  118.     precacheShader( "compass_waypoint_defend_e" );
  119.  
  120.     precacheShader( "waypoint_captureneutral" );
  121.     precacheShader( "waypoint_capture" );
  122.     precacheShader( "waypoint_defend" );
  123.     precacheShader( "waypoint_captureneutral_a" );
  124.     precacheShader( "waypoint_capture_a" );
  125.     precacheShader( "waypoint_defend_a" );
  126.     precacheShader( "waypoint_captureneutral_b" );
  127.     precacheShader( "waypoint_capture_b" );
  128.     precacheShader( "waypoint_defend_b" );
  129.     precacheShader( "waypoint_captureneutral_c" );
  130.     precacheShader( "waypoint_capture_c" );
  131.     precacheShader( "waypoint_defend_c" );
  132.     precacheShader( "waypoint_captureneutral_d" );
  133.     precacheShader( "waypoint_capture_d" );
  134.     precacheShader( "waypoint_defend_d" );
  135.     precacheShader( "waypoint_captureneutral_e" );
  136.     precacheShader( "waypoint_capture_e" );
  137.     precacheShader( "waypoint_defend_e" );
  138.    
  139.     flagBaseFX = [];
  140.     flagBaseFX["marines"] = "misc/ui_flagbase_silver";
  141.     flagBaseFX["sas"    ] = "misc/ui_flagbase_black";
  142.     flagBaseFX["russian"] = "misc/ui_flagbase_red";
  143.     flagBaseFX["opfor"  ] = "misc/ui_flagbase_gold";
  144.    
  145.     level.flagBaseFXid[ "allies" ] = loadfx( flagBaseFX[ game[ "allies" ] ] );
  146.     level.flagBaseFXid[ "axis"   ] = loadfx( flagBaseFX[ game[ "axis"   ] ] );
  147. }
  148.  
  149.  
  150. onStartGameType()
  151. {  
  152.     maps\mp\gametypes\_globallogic::setObjectiveText( "allies", &"OBJECTIVES_DOM" );
  153.     maps\mp\gametypes\_globallogic::setObjectiveText( "axis", &"OBJECTIVES_DOM" );
  154.  
  155.     if ( level.splitscreen )
  156.     {
  157.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "allies", &"OBJECTIVES_DOM" );
  158.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "axis", &"OBJECTIVES_DOM" );
  159.     }
  160.     else
  161.     {
  162.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "allies", &"OBJECTIVES_DOM_SCORE" );
  163.         maps\mp\gametypes\_globallogic::setObjectiveScoreText( "axis", &"OBJECTIVES_DOM_SCORE" );
  164.     }
  165.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "allies", &"OBJECTIVES_DOM_HINT" );
  166.     maps\mp\gametypes\_globallogic::setObjectiveHintText( "axis", &"OBJECTIVES_DOM_HINT" );
  167.  
  168.     setClientNameMode("auto_change");
  169.  
  170.     level.spawnMins = ( 0, 0, 0 );
  171.     level.spawnMaxs = ( 0, 0, 0 );
  172.     maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_dom_spawn_allies_start" );
  173.     maps\mp\gametypes\_spawnlogic::placeSpawnPoints( "mp_dom_spawn_axis_start" );
  174.     maps\mp\gametypes\_spawnlogic::addSpawnPoints( "allies", "mp_dom_spawn" );
  175.     maps\mp\gametypes\_spawnlogic::addSpawnPoints( "axis", "mp_dom_spawn" );
  176.    
  177.     level.mapCenter = maps\mp\gametypes\_spawnlogic::findBoxCenter( level.spawnMins, level.spawnMaxs );
  178.     setMapCenter( level.mapCenter );
  179.    
  180.     level.spawn_all = getentarray( "mp_dom_spawn", "classname" );
  181.     level.spawn_axis_start = getentarray("mp_dom_spawn_axis_start", "classname" );
  182.     level.spawn_allies_start = getentarray("mp_dom_spawn_allies_start", "classname" );
  183.    
  184.     level.startPos["allies"] = level.spawn_allies_start[0].origin;
  185.     level.startPos["axis"] = level.spawn_axis_start[0].origin;
  186.    
  187.     allowed[0] = "dom";
  188. //  allowed[1] = "hardpoint";
  189.     maps\mp\gametypes\_gameobjects::main(allowed);
  190.  
  191.     maps\mp\gametypes\_rank::registerScoreInfo( "kill", 5 );
  192.     maps\mp\gametypes\_rank::registerScoreInfo( "headshot", 5 );
  193.     maps\mp\gametypes\_rank::registerScoreInfo( "assist", 1 );
  194.  
  195.     maps\mp\gametypes\_rank::registerScoreInfo( "capture", 15 );
  196.  
  197.     maps\mp\gametypes\_rank::registerScoreInfo( "defend", 5 );
  198.     maps\mp\gametypes\_rank::registerScoreInfo( "defend_assist", 1 );
  199.  
  200.     maps\mp\gametypes\_rank::registerScoreInfo( "assault", 5 );
  201.     maps\mp\gametypes\_rank::registerScoreInfo( "assault_assist", 1 );
  202.    
  203.     thread domFlags();
  204.     thread updateDomScores();  
  205. }
  206.  
  207.  
  208. onSpawnPlayer()
  209. {
  210.     spawnpoint = undefined;
  211.    
  212.     if ( !level.useStartSpawns )
  213.     {
  214.         flagsOwned = 0;
  215.         enemyFlagsOwned = 0;
  216.         myTeam = self.pers["team"];
  217.         enemyTeam = getOtherTeam( myTeam );
  218.         for ( i = 0; i < level.flags.size; i++ )
  219.         {
  220.             team = level.flags[i] getFlagTeam();
  221.             if ( team == myTeam )
  222.                 flagsOwned++;
  223.             else if ( team == enemyTeam )
  224.                 enemyFlagsOwned++;
  225.         }
  226.        
  227.         if ( flagsOwned == level.flags.size )
  228.         {
  229.             // own all flags! pretend we don't own the last one we got, so enemies can spawn there
  230.             enemyBestSpawnFlag = level.bestSpawnFlag[ getOtherTeam( self.pers["team"] ) ];
  231.            
  232.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all, getSpawnsBoundingFlag( enemyBestSpawnFlag ) );
  233.         }
  234.         else if ( flagsOwned > 0 )
  235.         {
  236.             // spawn near any flag we own that's nearish something we can capture
  237.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all, getBoundaryFlagSpawns( myTeam ) );
  238.         }
  239.         else
  240.         {
  241.             // own no flags!
  242.             bestFlag = undefined;
  243.             if ( enemyFlagsOwned > 0 && enemyFlagsOwned < level.flags.size )
  244.             {
  245.                 // there should be an unowned one to use
  246.                 bestFlag = getUnownedFlagNearestStart( myTeam );
  247.             }
  248.             if ( !isdefined( bestFlag ) )
  249.             {
  250.                 // pretend we still own the last one we lost
  251.                 bestFlag = level.bestSpawnFlag[ self.pers["team"] ];
  252.             }
  253.             level.bestSpawnFlag[ self.pers["team"] ] = bestFlag;
  254.            
  255.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all, bestFlag.nearbyspawns );
  256.         }
  257.     }
  258.    
  259.     if ( !isdefined( spawnpoint ) )
  260.     {
  261.         if (self.pers["team"] == "axis")
  262.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(level.spawn_axis_start);
  263.         else
  264.             spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_Random(level.spawn_allies_start);
  265.     }
  266.    
  267.     //spawnpoint = maps\mp\gametypes\_spawnlogic::getSpawnpoint_NearTeam( level.spawn_all );
  268.    
  269.     assert( isDefined(spawnpoint) );
  270.    
  271.     self spawn(spawnpoint.origin, spawnpoint.angles);
  272. }
  273.  
  274.  
  275. domFlags()
  276. {
  277.     level.lastStatus["allies"] = 0;
  278.     level.lastStatus["axis"] = 0;
  279.    
  280.     game["flagmodels"] = [];
  281.     game["flagmodels"]["neutral"] = "prop_flag_neutral";
  282.  
  283.     if ( game["allies"] == "marines" )
  284.         game["flagmodels"]["allies"] = "prop_flag_american";
  285.     else
  286.         game["flagmodels"]["allies"] = "prop_flag_brit";
  287.    
  288.     if ( game["axis"] == "russian" )
  289.         game["flagmodels"]["axis"] = "prop_flag_russian";
  290.     else
  291.         game["flagmodels"]["axis"] = "prop_flag_opfor";
  292.    
  293.     precacheModel( game["flagmodels"]["neutral"] );
  294.     precacheModel( game["flagmodels"]["allies"] );
  295.     precacheModel( game["flagmodels"]["axis"] );
  296.    
  297.     primaryFlags = getEntArray( "flag_primary", "targetname" );
  298.     secondaryFlags = getEntArray( "flag_secondary", "targetname" );
  299.    
  300.     if ( (primaryFlags.size + secondaryFlags.size) < 2 )
  301.     {
  302.         printLn( "^1Not enough domination flags found in level!" );
  303.         maps\mp\gametypes\_callbacksetup::AbortLevel();
  304.         return;
  305.     }
  306.    
  307.     level.flags = [];
  308.     for ( index = 0; index < primaryFlags.size; index++ )
  309.         level.flags[level.flags.size] = primaryFlags[index];
  310.    
  311.     for ( index = 0; index < secondaryFlags.size; index++ )
  312.         level.flags[level.flags.size] = secondaryFlags[index];
  313.    
  314.     level.domFlags = [];
  315.     for ( index = 0; index < level.flags.size; index++ )
  316.     {
  317.         trigger = level.flags[index];
  318.         if ( isDefined( trigger.target ) )
  319.         {
  320.             visuals[0] = getEnt( trigger.target, "targetname" );
  321.         }
  322.         else
  323.         {
  324.             visuals[0] = spawn( "script_model", trigger.origin );
  325.             visuals[0].angles = trigger.angles;
  326.         }
  327.  
  328.         visuals[0] setModel( game["flagmodels"]["neutral"] );
  329.  
  330.         domFlag = maps\mp\gametypes\_gameobjects::createUseObject( "neutral", trigger, visuals, (0,0,100) );
  331.         domFlag maps\mp\gametypes\_gameobjects::allowUse( "enemy" );
  332.         domFlag maps\mp\gametypes\_gameobjects::setUseTime( 10.0 * level.fps_multiplier );
  333.         domFlag maps\mp\gametypes\_gameobjects::setUseText( &"MP_CAPTURING_FLAG" );
  334.         label = domFlag maps\mp\gametypes\_gameobjects::getLabel();
  335.         domFlag.label = label;
  336.         domFlag maps\mp\gametypes\_gameobjects::set2DIcon( "friendly", "compass_waypoint_defend" + label );
  337.         domFlag maps\mp\gametypes\_gameobjects::set3DIcon( "friendly", "waypoint_defend" + label );
  338.         domFlag maps\mp\gametypes\_gameobjects::set2DIcon( "enemy", "compass_waypoint_captureneutral" + label );
  339.         domFlag maps\mp\gametypes\_gameobjects::set3DIcon( "enemy", "waypoint_captureneutral" + label );
  340.         domFlag maps\mp\gametypes\_gameobjects::setVisibleTeam( "any" );
  341.         domFlag.onUse = ::onUse;
  342.         domFlag.onBeginUse = ::onBeginUse;
  343.         domFlag.onUseUpdate = ::onUseUpdate;
  344.         domFlag.onEndUse = ::onEndUse;
  345.        
  346.        
  347.         traceStart = visuals[0].origin + (0,0,32);
  348.         traceEnd = visuals[0].origin + (0,0,-32);
  349.         trace = bulletTrace( traceStart, traceEnd, false, undefined );
  350.    
  351.         upangles = vectorToAngles( trace["normal"] );
  352.         domFlag.baseeffectforward = anglesToForward( upangles );
  353.         domFlag.baseeffectright = anglesToRight( upangles );
  354.        
  355.         domFlag.baseeffectpos = trace["position"];
  356.        
  357. //      makeDvarServerInfo( "scr_obj" + label, "neutral" );
  358. //      makeDvarServerInfo( "scr_obj" + label + "_flash", 0 );
  359. //      setDvar( "scr_obj" + label, "neutral" );
  360. //      setDvar( "scr_obj" + label + "_flash", 0 );
  361.  
  362.         // legacy spawn code support
  363.         level.flags[index].useObj = domFlag;
  364.         level.flags[index].adjflags = [];
  365.         level.flags[index].nearbyspawns = [];
  366.        
  367.         domFlag.levelFlag = level.flags[index];
  368.        
  369.         level.domFlags[level.domFlags.size] = domFlag;
  370.     }
  371.    
  372.     // level.bestSpawnFlag is used as a last resort when the enemy holds all flags.
  373.     level.bestSpawnFlag = [];
  374.     level.bestSpawnFlag[ "allies" ] = getUnownedFlagNearestStart( "allies", undefined );
  375.     level.bestSpawnFlag[ "axis" ] = getUnownedFlagNearestStart( "axis", level.bestSpawnFlag[ "allies" ] );
  376.    
  377.     flagSetup();
  378.    
  379. //  setDvar( level.scoreLimitDvar, level.domFlags.size );
  380.  
  381.     /#
  382.     thread domDebug();
  383.     #/
  384. }
  385.  
  386. getUnownedFlagNearestStart( team, excludeFlag )
  387. {
  388.     best = undefined;
  389.     bestdistsq = undefined;
  390.     for ( i = 0; i < level.flags.size; i++ )
  391.     {
  392.         flag = level.flags[i];
  393.        
  394.         if ( flag getFlagTeam() != "neutral" )
  395.             continue;
  396.        
  397.         distsq = distanceSquared( flag.origin, level.startPos[team] );
  398.         if ( (!isDefined( excludeFlag ) || flag != excludeFlag) && (!isdefined( best ) || distsq < bestdistsq) )
  399.         {
  400.             bestdistsq = distsq;
  401.             best = flag;
  402.         }
  403.     }
  404.     return best;
  405. }
  406.  
  407. /#
  408. domDebug()
  409. {
  410.     while(1)
  411.     {
  412.         if (getdvar("scr_domdebug") != "1") {
  413.             wait (2 * level.fps_multiplier );
  414.             continue;
  415.         }
  416.        
  417.         while(1)
  418.         {
  419.             if (getdvar("scr_domdebug") != "1")
  420.                 break;
  421.             // show flag connections and each flag's spawnpoints
  422.             for (i = 0; i < level.flags.size; i++) {
  423.                 for (j = 0; j < level.flags[i].adjflags.size; j++) {
  424.                     line(level.flags[i].origin, level.flags[i].adjflags[j].origin, (1,1,1));
  425.                 }
  426.                
  427.                 for (j = 0; j < level.flags[i].nearbyspawns.size; j++) {
  428.                     line(level.flags[i].origin, level.flags[i].nearbyspawns[j].origin, (.2,.2,.6));
  429.                 }
  430.                
  431.                 if ( level.flags[i] == level.bestSpawnFlag["allies"] )
  432.                     print3d( level.flags[i].origin, "allies best spawn flag" );
  433.                 if ( level.flags[i] == level.bestSpawnFlag["axis"] )
  434.                     print3d( level.flags[i].origin, "axis best spawn flag" );
  435.             }
  436.             wait (.05 * level.fps_multiplier );
  437.         }
  438.     }
  439. }
  440. #/
  441.  
  442. onBeginUse( player )
  443. {
  444.     ownerTeam = self maps\mp\gametypes\_gameobjects::getOwnerTeam();
  445.     setDvar( "scr_obj" + self maps\mp\gametypes\_gameobjects::getLabel() + "_flash", 1 );  
  446.     self.didStatusNotify = false;
  447.  
  448.     if ( ownerTeam == "neutral" )
  449.     {
  450.         statusDialog( "securing"+self.label, player.pers["team"] );
  451.         self.objPoints[player.pers["team"]] thread maps\mp\gametypes\_objpoints::startFlashing();
  452.         return;
  453.     }
  454.        
  455.     if ( ownerTeam == "allies" )
  456.         otherTeam = "axis";
  457.     else
  458.         otherTeam = "allies";
  459.  
  460.     self.objPoints["allies"] thread maps\mp\gametypes\_objpoints::startFlashing();
  461.     self.objPoints["axis"] thread maps\mp\gametypes\_objpoints::startFlashing();
  462. }
  463.  
  464.  
  465. onUseUpdate( team, progress, change )
  466. {
  467.     if ( progress > 0.05 && change && !self.didStatusNotify )
  468.     {
  469.         ownerTeam = self maps\mp\gametypes\_gameobjects::getOwnerTeam();
  470.         if ( ownerTeam == "neutral" )
  471.         {
  472.             statusDialog( "securing"+self.label, team );
  473.         }
  474.         else
  475.         {
  476.             statusDialog( "losing"+self.label, ownerTeam );
  477.             statusDialog( "securing"+self.label, team );
  478.         }
  479.  
  480.         self.didStatusNotify = true;
  481.     }
  482. }
  483.  
  484.  
  485. statusDialog( dialog, team )
  486. {
  487.     time = getTime();
  488.     if ( getTime() < level.lastStatus[team] + 6000 )
  489.         return;
  490.        
  491.     thread delayedLeaderDialog( dialog, team );
  492.     level.lastStatus[team] = getTime();
  493. }
  494.  
  495.  
  496. onEndUse( team, player, success )
  497. {
  498.     setDvar( "scr_obj" + self maps\mp\gametypes\_gameobjects::getLabel() + "_flash", 0 );
  499.  
  500.     self.objPoints["allies"] thread maps\mp\gametypes\_objpoints::stopFlashing();
  501.     self.objPoints["axis"] thread maps\mp\gametypes\_objpoints::stopFlashing();
  502. }
  503.  
  504.  
  505. resetFlagBaseEffect()
  506. {
  507.     if ( isdefined( self.baseeffect ) )
  508.         self.baseeffect delete();
  509.    
  510.     team = self maps\mp\gametypes\_gameobjects::getOwnerTeam();
  511.    
  512.     if ( team != "axis" && team != "allies" )
  513.         return;
  514.    
  515.     fxid = level.flagBaseFXid[ team ];
  516.  
  517.     self.baseeffect = spawnFx( fxid, self.baseeffectpos, self.baseeffectforward, self.baseeffectright );
  518.     triggerFx( self.baseeffect );
  519. }
  520.  
  521. onUse( player )
  522. {
  523.     team = player.pers["team"];
  524.     oldTeam = self maps\mp\gametypes\_gameobjects::getOwnerTeam();
  525.     label = self maps\mp\gametypes\_gameobjects::getLabel();
  526.    
  527.     player logString( "flag captured: " + self.label );
  528.    
  529.     self maps\mp\gametypes\_gameobjects::setOwnerTeam( team );
  530.     self maps\mp\gametypes\_gameobjects::set2DIcon( "enemy", "compass_waypoint_capture" + label );
  531.     self maps\mp\gametypes\_gameobjects::set3DIcon( "enemy", "waypoint_capture" + label );
  532.     self.visuals[0] setModel( game["flagmodels"][team] );
  533.     setDvar( "scr_obj" + self maps\mp\gametypes\_gameobjects::getLabel(), team );  
  534.    
  535.     self resetFlagBaseEffect();
  536.    
  537.     level.useStartSpawns = false;
  538.    
  539.     assert( team != "neutral" );
  540.    
  541.     if ( oldTeam == "neutral" )
  542.     {
  543.         otherTeam = getOtherTeam( team );
  544.         thread printAndSoundOnEveryone( team, otherTeam, &"MP_NEUTRAL_FLAG_CAPTURED_BY", &"MP_NEUTRAL_FLAG_CAPTURED_BY", "mp_war_objective_taken", undefined, player );
  545.        
  546.         statusDialog( "secured"+self.label, team );
  547.         statusDialog( "enemy_has"+self.label, otherTeam );
  548.     }
  549.     else
  550.     {
  551.         thread printAndSoundOnEveryone( team, oldTeam, &"MP_ENEMY_FLAG_CAPTURED_BY", &"MP_FRIENDLY_FLAG_CAPTURED_BY", "mp_war_objective_taken", "mp_war_objective_lost", player );
  552.        
  553. //      thread delayedLeaderDialogBothTeams( "obj_lost", oldTeam, "obj_taken", team );
  554.  
  555.         if ( getTeamFlagCount( team ) == level.flags.size )
  556.         {
  557.             statusDialog( "secure_all", team );
  558.             statusDialog( "lost_all", oldTeam );
  559.         }
  560.         else
  561.         {  
  562.             statusDialog( "secured"+self.label, team );
  563.             statusDialog( "lost"+self.label, oldTeam );
  564.         }
  565.        
  566.         level.bestSpawnFlag[ oldTeam ] = self.levelFlag;
  567.     }
  568.  
  569.     thread giveFlagCaptureXP( self.touchList[team] );
  570. }
  571.  
  572. giveFlagCaptureXP( touchList )
  573. {
  574.     wait (.05 * level.fps_multiplier );
  575.     maps\mp\gametypes\_globallogic::WaitTillSlowProcessAllowed();
  576.    
  577.     players = getArrayKeys( touchList );
  578.     for ( index = 0; index < players.size; index++ )
  579.     {
  580.         touchList[players[index]].player thread [[level.onXPEvent]]( "capture" );
  581.         maps\mp\gametypes\_globallogic::givePlayerScore( "capture", touchList[players[index]].player );
  582.     }
  583. }
  584.  
  585. delayedLeaderDialog( sound, team )
  586. {
  587.     wait (.1 * level.fps_multiplier );
  588.     maps\mp\gametypes\_globallogic::WaitTillSlowProcessAllowed();
  589.    
  590.     maps\mp\gametypes\_globallogic::leaderDialog( sound, team );
  591. }
  592. delayedLeaderDialogBothTeams( sound1, team1, sound2, team2 )
  593. {
  594.     wait (.1 * level.fps_multiplier );
  595.     maps\mp\gametypes\_globallogic::WaitTillSlowProcessAllowed();
  596.    
  597.     maps\mp\gametypes\_globallogic::leaderDialogBothTeams( sound1, team1, sound2, team2 );
  598. }
  599.  
  600.  
  601. updateDomScores()
  602. {
  603.     // disable score limit check to allow both axis and allies score to be processed
  604.     level.endGameOnScoreLimit = false;
  605.  
  606.     while ( !level.gameEnded )
  607.     {
  608.  
  609.         numFlags = getTeamFlagCount( "allies" );
  610.         if ( numFlags )
  611.             [[level._setTeamScore]]( "allies", [[level._getTeamScore]]( "allies" ) + numFlags );
  612.  
  613.         numFlags = getTeamFlagCount( "axis" );
  614.         if ( numFlags )
  615.             [[level._setTeamScore]]( "axis", [[level._getTeamScore]]( "axis" ) + numFlags );
  616.  
  617.         level.endGameOnScoreLimit = true;
  618.         maps\mp\gametypes\_globallogic::checkScoreLimit();
  619.         level.endGameOnScoreLimit = false;
  620.         wait ( 5.0 * level.fps_multiplier );
  621.     }
  622. }
  623.  
  624.  
  625. onPlayerKilled( eInflictor, attacker, iDamage, sMeansOfDeath, sWeapon, vDir, sHitLoc, psOffsetTime, deathAnimDuration )
  626. {
  627.     if ( self.touchTriggers.size && isPlayer( attacker ) && attacker.pers["team"] != self.pers["team"] )
  628.     {
  629.         triggerIds = getArrayKeys( self.touchTriggers );
  630.         ownerTeam = self.touchTriggers[triggerIds[0]].useObj.ownerTeam;
  631.         team = self.pers["team"];
  632.        
  633.         if ( team == ownerTeam )
  634.         {
  635.             attacker thread [[level.onXPEvent]]( "assault" );
  636.             maps\mp\gametypes\_globallogic::givePlayerScore( "assault", attacker );
  637.         }
  638.         else
  639.         {
  640.             attacker thread [[level.onXPEvent]]( "defend" );
  641.             maps\mp\gametypes\_globallogic::givePlayerScore( "defend", attacker );
  642.         }
  643.     }
  644. }
  645.  
  646.  
  647.  
  648. getTeamFlagCount( team )
  649. {
  650.     score = 0;
  651.     for (i = 0; i < level.flags.size; i++)
  652.     {
  653.         if ( level.domFlags[i] maps\mp\gametypes\_gameobjects::getOwnerTeam() == team )
  654.             score++;
  655.     }  
  656.     return score;
  657. }
  658.  
  659. getFlagTeam()
  660. {
  661.     return self.useObj maps\mp\gametypes\_gameobjects::getOwnerTeam();
  662. }
  663.  
  664. getBoundaryFlags()
  665. {
  666.     // get all flags which are adjacent to flags that aren't owned by the same team
  667.     bflags = [];
  668.     for (i = 0; i < level.flags.size; i++)
  669.     {
  670.         for (j = 0; j < level.flags[i].adjflags.size; j++)
  671.         {
  672.             if (level.flags[i].useObj maps\mp\gametypes\_gameobjects::getOwnerTeam() != level.flags[i].adjflags[j].useObj maps\mp\gametypes\_gameobjects::getOwnerTeam() )
  673.             {
  674.                 bflags[bflags.size] = level.flags[i];
  675.                 break;
  676.             }
  677.         }
  678.     }
  679.    
  680.     return bflags;
  681. }
  682.  
  683. getBoundaryFlagSpawns(team)
  684. {
  685.     spawns = [];
  686.    
  687.     bflags = getBoundaryFlags();
  688.     for (i = 0; i < bflags.size; i++)
  689.     {
  690.         if (isdefined(team) && bflags[i] getFlagTeam() != team)
  691.             continue;
  692.        
  693.         for (j = 0; j < bflags[i].nearbyspawns.size; j++)
  694.             spawns[spawns.size] = bflags[i].nearbyspawns[j];
  695.     }
  696.    
  697.     return spawns;
  698. }
  699.  
  700. getSpawnsBoundingFlag( avoidflag )
  701. {
  702.     spawns = [];
  703.  
  704.     for (i = 0; i < level.flags.size; i++)
  705.     {
  706.         flag = level.flags[i];
  707.         if ( flag == avoidflag )
  708.             continue;
  709.        
  710.         isbounding = false;
  711.         for (j = 0; j < flag.adjflags.size; j++)
  712.         {
  713.             if ( flag.adjflags[j] == avoidflag )
  714.             {
  715.                 isbounding = true;
  716.                 break;
  717.             }
  718.         }
  719.        
  720.         if ( !isbounding )
  721.             continue;
  722.        
  723.         for (j = 0; j < flag.nearbyspawns.size; j++)
  724.             spawns[spawns.size] = flag.nearbyspawns[j];
  725.     }
  726.    
  727.     return spawns;
  728. }
  729.  
  730. // gets an array of all spawnpoints which are near flags that are
  731. // owned by the given team, or that are adjacent to flags owned by the given team.
  732. getOwnedAndBoundingFlagSpawns(team)
  733. {
  734.     spawns = [];
  735.  
  736.     for (i = 0; i < level.flags.size; i++)
  737.     {
  738.         if ( level.flags[i] getFlagTeam() == team )
  739.         {
  740.             // add spawns near this flag
  741.             for (s = 0; s < level.flags[i].nearbyspawns.size; s++)
  742.                 spawns[spawns.size] = level.flags[i].nearbyspawns[s];
  743.         }
  744.         else
  745.         {
  746.             for (j = 0; j < level.flags[i].adjflags.size; j++)
  747.             {
  748.                 if ( level.flags[i].adjflags[j] getFlagTeam() == team )
  749.                 {
  750.                     // add spawns near this flag
  751.                     for (s = 0; s < level.flags[i].nearbyspawns.size; s++)
  752.                         spawns[spawns.size] = level.flags[i].nearbyspawns[s];
  753.                     break;
  754.                 }
  755.             }
  756.         }
  757.     }
  758.    
  759.     return spawns;
  760. }
  761.  
  762. // gets an array of all spawnpoints which are near flags that are
  763. // owned by the given team
  764. getOwnedFlagSpawns(team)
  765. {
  766.     spawns = [];
  767.  
  768.     for (i = 0; i < level.flags.size; i++)
  769.     {
  770.         if ( level.flags[i] getFlagTeam() == team )
  771.         {
  772.             // add spawns near this flag
  773.             for (s = 0; s < level.flags[i].nearbyspawns.size; s++)
  774.                 spawns[spawns.size] = level.flags[i].nearbyspawns[s];
  775.         }
  776.     }
  777.    
  778.     return spawns;
  779. }
  780.  
  781. flagSetup()
  782. {
  783.     maperrors = [];
  784.     descriptorsByLinkname = [];
  785.  
  786.     // (find each flag_descriptor object)
  787.     descriptors = getentarray("flag_descriptor", "targetname");
  788.    
  789.     flags = level.flags;
  790.    
  791.     for (i = 0; i < level.domFlags.size; i++)
  792.     {
  793.         closestdist = undefined;
  794.         closestdesc = undefined;
  795.         for (j = 0; j < descriptors.size; j++)
  796.         {
  797.             dist = distance(flags[i].origin, descriptors[j].origin);
  798.             if (!isdefined(closestdist) || dist < closestdist) {
  799.                 closestdist = dist;
  800.                 closestdesc = descriptors[j];
  801.             }
  802.         }
  803.        
  804.         if (!isdefined(closestdesc)) {
  805.             maperrors[maperrors.size] = "there is no flag_descriptor in the map! see explanation in dom.gsc";
  806.             break;
  807.         }
  808.         if (isdefined(closestdesc.flag)) {
  809.             maperrors[maperrors.size] = "flag_descriptor with script_linkname \"" + closestdesc.script_linkname + "\" is nearby more than one flag; is there a unique descriptor near each flag?";
  810.             continue;
  811.         }
  812.         flags[i].descriptor = closestdesc;
  813.         closestdesc.flag = flags[i];
  814.         descriptorsByLinkname[closestdesc.script_linkname] = closestdesc;
  815.     }
  816.    
  817.     if (maperrors.size == 0)
  818.     {
  819.         // find adjacent flags
  820.         for (i = 0; i < flags.size; i++)
  821.         {
  822.             if (isdefined(flags[i].descriptor.script_linkto))
  823.                 adjdescs = strtok(flags[i].descriptor.script_linkto, " ");
  824.             else
  825.                 adjdescs = [];
  826.             for (j = 0; j < adjdescs.size; j++)
  827.             {
  828.                 otherdesc = descriptorsByLinkname[adjdescs[j]];
  829.                 if (!isdefined(otherdesc) || otherdesc.targetname != "flag_descriptor") {
  830.                     maperrors[maperrors.size] = "flag_descriptor with script_linkname \"" + flags[i].descriptor.script_linkname + "\" linked to \"" + adjdescs[j] + "\" which does not exist as a script_linkname of any other entity with a targetname of flag_descriptor (or, if it does, that flag_descriptor has not been assigned to a flag)";
  831.                     continue;
  832.                 }
  833.                 adjflag = otherdesc.flag;
  834.                 if (adjflag == flags[i]) {
  835.                     maperrors[maperrors.size] = "flag_descriptor with script_linkname \"" + flags[i].descriptor.script_linkname + "\" linked to itself";
  836.                     continue;
  837.                 }
  838.                 flags[i].adjflags[flags[i].adjflags.size] = adjflag;
  839.             }
  840.         }
  841.     }
  842.    
  843.     // assign each spawnpoint to nearest flag
  844.     spawnpoints = getentarray("mp_dom_spawn", "classname");
  845.     for (i = 0; i < spawnpoints.size; i++)
  846.     {
  847.         if (isdefined(spawnpoints[i].script_linkto)) {
  848.             desc = descriptorsByLinkname[spawnpoints[i].script_linkto];
  849.             if (!isdefined(desc) || desc.targetname != "flag_descriptor") {
  850.                 maperrors[maperrors.size] = "Spawnpoint at " + spawnpoints[i].origin + "\" linked to \"" + spawnpoints[i].script_linkto + "\" which does not exist as a script_linkname of any entity with a targetname of flag_descriptor (or, if it does, that flag_descriptor has not been assigned to a flag)";
  851.                 continue;
  852.             }
  853.             nearestflag = desc.flag;
  854.         }
  855.         else {
  856.             nearestflag = undefined;
  857.             nearestdist = undefined;
  858.             for (j = 0; j < flags.size; j++)
  859.             {
  860.                 dist = distancesquared(flags[j].origin, spawnpoints[i].origin);
  861.                 if (!isdefined(nearestflag) || dist < nearestdist)
  862.                 {
  863.                     nearestflag = flags[j];
  864.                     nearestdist = dist;
  865.                 }
  866.             }
  867.         }
  868.         nearestflag.nearbyspawns[nearestflag.nearbyspawns.size] = spawnpoints[i];
  869.     }
  870.    
  871.     if (maperrors.size > 0)
  872.     {
  873.         println("^1------------ Map Errors ------------");
  874.         for(i = 0; i < maperrors.size; i++)
  875.             println(maperrors[i]);
  876.         println("^1------------------------------------");
  877.        
  878.         maps\mp\_utility::error("Map errors. See above");
  879.         maps\mp\gametypes\_callbacksetup::AbortLevel();
  880.        
  881.         return;
  882.     }
  883. }

Paste-bin is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.