Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames

UTDom.xDoubleDom


00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
/**
 * Base class of Double Domination Gametypes.
 * Based of the UT2004 xGame.xDoubleDom gametype. Added support for 4 team play.
 * 
 * Writen by Brian 'Snake' Alexander. Copyright(c) 2007-2010 All Rights Reserved.
 */
class xDoubleDom extends UTDomGame
   abstract;
`include(UTDom.uci)

/** Should not be used. If False and playing on a map with no TeamPlayerStart actors (e.g. most DOM maps) players will not beable to spawn.
 * True=players can spawn at any playerstarts, False=players spawn in marked team playerstarts. */
var() config bool bNoTeamPlayerStart;
/** When true, in 3 team games, the duration both points must be controlled to score is only 85% of TimeToScore.
 *  In 4 team games, the duration both points must be controlled to score is only 75% of TimeToScore. No change for 2 team games */
var() config bool bUseAltMultiTeamTimeToScore;
/** duration both points must be controlled for to score a point. */
var() config int TimeToScore;
/** duration both points are disabled for after a point is scored. */
var() config int TimeDisabled;
var const int MaxTimeToScore, MaxTimeDisabled;
/** Internal flags so Announcements do not keep repeating. */
var transient bool bPlayedDisabledMsg, bPlayedTeamDominating;
/** tracks the count down until a point is scored. */
var transient int ScoreCountDown; 
/** count down until points are re-enabled after a point is scored. */
var transient int DisabledCountDown; 
var class<UTLocalMessage> CountdownAnnouncerMessageClass;

event InitGame(string Options, out string ErrorMessage)
{
   local string InOpt;

   Super.InitGame(Options, ErrorMessage);

   InOpt = ParseOption( Options, "TimeToScore");
   if (InOpt != "")
   {
      TimeToScore = Clamp(GetIntOption(Options, "TimeToScore", TimeToScore),1,MaxTimeToScore);
      ScoreCountDown = TimeToScore;
   }

   InOpt = ParseOption( Options, "TimeDisabled");
   if (InOpt != "")
   {
      TimeDisabled = Clamp(GetIntOption(Options, "TimeDisabled", TimeDisabled),1,MaxTimeDisabled);
   }

   if ( !WorldInfo.IsConsoleBuild() )
   {
      InOpt = ParseOption(Options, "bNoTeamPlayerStart");
      if (InOpt != "")
      {
         bNoTeamPlayerStart = bool(InOpt);
         if ( !bNoTeamPlayerStart )
         {
            bSpawnInTeamArea = True;
         }
      }

      InOpt = ParseOption(Options, "bUseAltMultiTeamTimeToScore");
      if (InOpt != "")
      {
         bUseAltMultiTeamTimeToScore = bool(InOpt);
      }

      if ( bUseAltMultiTeamTimeToScore && NumTeams > 3)
      {
         if (NumTeams == 3)
         {
            TimeToScore = TimeToScore * 0.85;
         }
         else if (NumTeams == 4)
         {
            TimeToScore = TimeToScore * 0.75;
         }
         ScoreCountDown = TimeToScore;
      }
   }
}

function SetupControlPointClass()
{
   local int i, n;
   local byte outFound;
   local ControlPointFactory FactoryPointA, FactoryPointB;

   // if using maplist, use the 1st two ControlPoint entries for that map.
   if (bUseMapList)
   {
      if (IsMapOnMapList(outFound))
      {
         if (outFound >= 0)
         {
            n = CPF.Length;
            for (i=0; i< n; i++)
            {
               if (IsControlPointOnMapList(CPF[i], outFound))
               {
                  if ( FactoryPointA == none )
                     FactoryPointA = CPF[i];
                  else if ( FactoryPointB == none )
                     FactoryPointB = CPF[i];
               }
            }
         }
      }
   }

   // Search for any pre-defined ControlPointFactory.ControlPointClass that matches
   // ControlPointType[0] or ControlPointType[1]
   if (FactoryPointA == none || FactoryPointB == none)
   {
      for (i=0; i< CPF.Length; i++)
      {
         if (FactoryPointA == none && CPF[i].ControlPointClass == ControlPointType[0])
            FactoryPointA = CPF[i];
         else if (FactoryPointB == none && CPF[i].ControlPointClass == ControlPointType[1])
            FactoryPointB = CPF[i];
      }
   }

   // if have not found both xDomPointA and xDomPointB by now, then just use the 1st two
   // ControlPointFactory's of the map and use them.
   if (FactoryPointA == none || FactoryPointB == none)
   {
      for (i=0; i< CPF.Length; i++)
      {
         if (FactoryPointA == none)
            FactoryPointA = CPF[i];
         else if (FactoryPointB == none)
            FactoryPointB = CPF[i];
      }
   }

   // Setup xDomPointA
   if (FactoryPointA != none)
      FactoryPointA.ControlPointClass = ControlPointType[0];

   // Setup xDomPointB
   if (FactoryPointB != none)
      FactoryPointB.ControlPointClass = ControlPointType[1];

   // Remove unused factories
   n = CPF.Length;
   for (i=0; i<n; i++)
   {
      if (CPF.Length == 2)
      {
         break;
      }
      else if ((FactoryPointA == CPF[i] && CPF[i].ControlPointClass == ControlPointType[0])
       || (FactoryPointB == CPF[i] && CPF[i].ControlPointClass == ControlPointType[1]))
      {
         `Log(" Found ControlPointFactory CPF["$i$"]="$CPF[i].Name,bDebug,'SetupControlPointClass');
      }
      else if (CPF.Length > 2)
      {
         CPF[i].ControlPointClass = none;
         CPF.Remove(i,1);
      }
   }
}

/**
 * locates and then sets up all the right type of xDomPoint for each ControlPointFactory
 * It is very important that the xDomPointA is Registered first! This is so that
 * CDomPoints[0] = A and CDomPoints[1] = B
 */
function FindAllxDomPoints()
{
   local ControlPoint xCP[2];
   local int i;

   for (i=0; i<CPF.Length; i++)
   {
      if ( CPF[i].myControlPoint != none )
      {
         if (CPF[i].myControlPoint.IsA('xDomPointA'))
            xCP[0] = CPF[i].myControlPoint;
         else if (CPF[i].myControlPoint.IsA('xDomPointB'))
            xCP[1] = CPF[i].myControlPoint;
      }

      if (xCP[0] != none && xCP[1] != none)
      {
         break;
      }
   }

   for (i=0; i<2; i++)
   {
      RegisterControlPoint(xCP[i]);
   }
}

function WriteStartUpLogMessage()
{
   super.WriteStartUpLogMessage();
   LogInternal("[  TimeToScore="$TimeToScore);
   LogInternal("[  TimeDisabled="$TimeDisabled);
   LogInternal("[  bNoTeamPlayerStart="$string(bNoTeamPlayerStart));
   LogInternal("[  bUseAltMultiTeamTimeToScore="$string(bUseAltMultiTeamTimeToScore));
   LogInternal("============================================================================");
}

function bool RegisterControlPoint(ControlPoint CP)
{
   local bool bResult;

   bResult = super.RegisterControlPoint(CP);
   if (bResult)
   {
      if (xDomPoint(CDomPoints[CDomPoints.length-1]) != none)
      {
         xDomPoint(CDomPoints[CDomPoints.length-1]).ResetCount = ResetCount;
         return true;
      }
   }
   return bResult;
}

function PostBeginPlay()
{
   Super.PostBeginPlay();
   `Warn(" ######   ERROR: Not enough xDomPoint's   ###### ",(CDomPoints[0] == None || CDomPoints[1] == none ));
}

State MatchInProgress
{
   event Timer()
   {
      local int i;

      super.Timer();
      if (bGameEnded || CDomPoints[0] == none || CDomPoints[1] == none)
      {
         return;
      }

      // both points currently disabled?
      if (DisabledCountDown > 0)
      {
         // Play the "New Round In" announcement
         if ( !bPlayedDisabledMsg && DisabledCountDown < 7 )
         {
            BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, 22);
            bPlayedDisabledMsg = True;
         }

         DisabledCountDown--;
         if (DisabledCountDown == 0)
         {
            CDomPoints[0].ResetPoint(true);
            CDomPoints[1].ResetPoint(true);
            bPlayedDisabledMsg = False;
         }
         else if (DisabledCountDown < 4) // Play the Count down announcements
         {
            BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, DisabledCountDown);
         }
      }

      // nothing more to do unless the same team controls both points
      if ( (CDomPoints[0].ControllingTeam == None) || (CDomPoints[0].ControllingTeam != CDomPoints[1].ControllingTeam) )
      {
         ScoreCountDown = TimeToScore;
         bPlayedTeamDominating = False;
         return;
      }

      if (ScoreCountDown > 0)
      {
         // Play the "x Team is Dominating" announcement
         if ( !bPlayedTeamDominating )
         {
            if (CDomPoints[0].ControllingTeam.TeamIndex == 0)
               BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, 18);
            else if (CDomPoints[0].ControllingTeam.TeamIndex == 1)
               BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, 19);

            PlayMusicEvent(CDomPoints[0].ControllingTeam.TeamIndex, 2);
            bPlayedTeamDominating = True;
         }
         else if (ScoreCountDown < 8) // Play the Count down announcements
         {
            BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, ScoreCountDown);
         }

         // decrement the time remaining until a point is scored
         ScoreCountDown--;
         return;
      }

      // controlling team has scored!
      AnnounceScore(CDomPoints[0].ControllingTeam.TeamIndex);
      CDomPoints[0].ControllingTeam.Score += 1.0;
      CDomPoints[0].ControllingTeam.bForceNetUpdate = True;
      // play the scored music
      BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, 30);
      PlayMusicEvent(CDomPoints[0].ControllingTeam.TeamIndex, 1);
      // Award points to the players
      for (i=0; i < 2; i++)
      {
         if (CDomPoints[i].HolderPRI != none)
         {
            CDomPoints[i].HolderPRI.Score += 5.0;
            CDomPoints[i].HolderPRI.bForceNetUpdate = true;
            // check if the game is over because either team has achieved the goal limit
            CheckScore(CDomPoints[i].HolderPRI);
         }
      }

      // check if the game is over because either team has achieved the goal limit
      if ( bOverTime )
         EndGame(none,"timelimit");

      if ( !bGameEnded )
      {
         bPlayedTeamDominating = False;
         // reset count
         ScoreCountDown = TimeToScore;
         // make all control points be untouchable for a short period
         DisabledCountDown = TimeDisabled;
         // reset both domination points and disable them
         CDomPoints[0].ResetPoint(false);
         CDomPoints[1].ResetPoint(false);
      }
   }
}

function ScoreTeam(int i, float c);

/**
 * Plays music events for all players
 * 
 * @param TeamID   The TeamIndex who triggered this
 * @param MusicType   Which set of music to play
 */
function PlayMusicEvent(int TeamID, int MusicType)
{
   local PlayerController PC;
   local int x,z;

   if (MusicType == 1)
   {
      x = 14; //score increase lead
      z = 13; //score behind
   }
   else if (MusicType == 2)
   {
      x = 7; //took flag
      z = 4; //enemy took flag (from base)
   }

   ForEach LocalPlayerControllers(class'PlayerController', PC)
   {
      if (PC.PlayerReplicationInfo != none && UTPlayerController(PC) != none)
      {
         if (PC.PlayerReplicationInfo.GetTeamNum() == TeamID)
            UTPlayerController(PC).ClientMusicEvent(x);
         else if (PC.PlayerReplicationInfo.GetTeamNum() != TeamID)
            UTPlayerController(PC).ClientMusicEvent(z);
      }
   }
}

function ClearControl(Controller Other)
{
   local UTPlayerController Player;
   local PlayerController PC;
   local Pawn Pick;

   if ( (UTPlayerController(Other) == None) || (Other.PlayerReplicationInfo.GetTeamNum() == 255) )
      return;

   if ( (CDomPoints[0].ControllingPawn != Other) && (CDomPoints[1].ControllingPawn != Other) )
      return;

   // find a suitable teammate
   ForEach LocalPlayerControllers(class'PlayerController', PC)
   {
      Player = UTPlayerController(PC);
      if ( (Player != None) && (Player != Other) && (Player.PlayerReplicationInfo.Team == Other.PlayerReplicationInfo.Team) )
      {
         Pick = Player.Pawn;
         break;
      }
   }

   // update both control points with the new controlling pawn, since the other one is leaving (if no other suitable
   // teammate was found, then the point will return to neutral)
   if (CDomPoints[0].ControllingPawn == Other)
   {
      CDomPoints[0].ControllingPawn = Pick;
      CDomPoints[0].UpdateStatus();
   }

   if (CDomPoints[1].ControllingPawn == Other)
   {
      CDomPoints[1].ControllingPawn = Pick;
      CDomPoints[1].UpdateStatus();
   }
}

/**
 * play 'averted' or 'last second save' announcement if within one second of a score 
 */
function ResetCount()
{
   local int i;

   if ( ScoreCountDown < TimeToScore )
   {
      if (TimeToScore - ScoreCountDown > (TimeToScore/2))
      {
         if (TimeToScore - ScoreCountDown >= (TimeToScore-1))
         {
            i = rand(2);
            if (i == 2)
               BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, 20);
            else
               BroadcastLocalizedMessage(CountdownAnnouncerMessageClass, 21);
         }
      }
   }

   bPlayedTeamDominating = False;
   bPlayedDisabledMsg = False;
   ScoreCountDown = TimeToScore;
}

/**
 * Announce score for only red and blue teams 
 */
function AnnounceScore(int ScoringTeam)
{
   local UTPlayerController PC;

   if ( TeamScoreMessageClass == None || ScoringTeam > 1 )
      return;

   foreach WorldInfo.AllControllers(class'UTPlayerController', PC)
   {
      PC.ReceiveLocalizedMessage(TeamScoreMessageClass, ScoringTeam);
   }
}

/**
 * In DOM, critical players are anyone within 1024 units of the dom point
 * who have los to it.
 */
function bool CriticalPlayer(Controller Other)
{
   if ( (vsize(Other.Pawn.Location - CDomPoints[0].HomeBase.Location) <=1024) ||
      (vsize(Other.Pawn.Location - CDomPoints[1].HomeBase.Location) <=1024) )
      return true;
}

function ShowPathTo(PlayerController P, int TeamNum)
{
   if (CDomPoints[TeamNum].HomeBase != None && P.FindPathToward(CDomPoints[TeamNum].HomeBase, false) != None)
      Spawn(class'UTWillowWhisp', P,, P.Pawn.Location);
}

event Destroyed()
{
   local int i;

   for ( i = 0; i < 2; i++ )
   {
      if ( xDomPoint(CDomPoints[i]) != None )
         xDomPoint(CDomPoints[i]).ResetCount = None;
   }
   Super.Destroyed();
}

function Actor GetAutoObjectiveFor(UTPlayerController PC)
{
   if ( vsize(PC.Location - CDomPoints[0].HomeBase.Location) < vsize(PC.Location - CDomPoints[1].HomeBase.Location) )
      return CDomPoints[1].HomeBase;
   else if ( vsize(PC.Location - CDomPoints[0].HomeBase.Location) > vsize(PC.Location - CDomPoints[1].HomeBase.Location) )
      return CDomPoints[0].HomeBase;
}

DefaultProperties
{
   bExportMenuData=False
   bUnlimitedTranslocator=False
   bUseHoverboard=False
   bSpawnInTeamArea=False
   bNoTeamPlayerStart=True
   bDDOMGame=True
`if(`isdefined(PLATFORM_PS3))
   GameName="Double Domination"
   Description="Battle for control over 2 ControlPoints: A,B Your team must hold both ControlPoints for 10 seconds to score."
`else
   bUseAltMultiTeamTimeToScore=True
`endif
   GoalScore=3
   ScoreCountDown=10
   TimeToScore=10
   TimeDisabled=10
   MaxTimeToScore=30
   MaxTimeDisabled=30
   TimeLimit=20
   MaxControlPoints=2
   MaxControlPointsAllowed=2
   CountdownAnnouncerMessageClass=class'UTDom.xDomTimerMessage'
   HUDType=class'UTDom.xDOMHUD'
   MultiTeamAIType(0)=class'UTDom.xDOMTeamAI'
   MultiTeamAIType(1)=class'UTDom.xDOMTeamAI'
   MultiTeamAIType(2)=class'UTDom.xDOMTeamAI'
   MultiTeamAIType(3)=class'UTDom.xDOMTeamAI'
   ControlPointType[0]=class'UTDom.xDomPointA'
   ControlPointType[1]=class'UTDom.xDomPointB'
}

Overview Package Class Source Class tree Glossary
previous class      next class frames      no frames
Class file time: Wed 8/12/2010 21:28:46.000 - Creation time: Fri 23/12/2011 20:31:26.753 - Created with UnCodeX