Advertisement
Guest User

Nit TDM

a guest
Feb 20th, 2016
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.17 KB | None | 0 0
  1. //N!tmod TDM Source Code - Sep. 5th 2010
  2.  
  3. //This file contains main modifications that need to be done in Wolfenstein:Enemy Territory source code in order to implement N!tmod's TeamDeathMatch gametype.
  4. //Modifications such as adding cvars, sending TDM Score to clients or rendering the score on clients screen are not provided.
  5. //Credits go to N!tmod Dev Team. www.nitmod.com
  6.  
  7. /*
  8. ***************************
  9. *       bg_public.h       *
  10. ***************************
  11. */
  12. //  Add to gametype_t :
  13.         GT_WOLF_TDM,
  14.  
  15.  
  16. /*
  17. ***************************
  18. *    g_script_actions.c   *
  19. ***************************
  20. */
  21.  
  22. // G_ScriptAction_EndRound() - N!tmod gives 100 bonus points if the final objective is completed (remember that the map will not end as long as the score is not reached)
  23. //  Add :
  24.  
  25.     if( g_gametype.integer == GT_WOLF_TDM ) {
  26.         trap_GetConfigstring( CS_MULTI_MAPWINNER, cs, sizeof(cs) );
  27.         winner = atoi( Info_ValueForKey( cs, "w" ) );
  28.         if(winner == 1) {
  29.             level.teamScores[TEAM_ALLIES] += 100;
  30.         } else if(winner == 0) {
  31.             level.teamScores[TEAM_AXIS] += 100;
  32.         } return qtrue;
  33.     }
  34.  
  35.  
  36. /*
  37. ***************************
  38. *        g_main.c         *
  39. ***************************
  40. */
  41.  
  42. // CheckExitRules() - Check if a team has reached g_TDMScore.
  43. //  Add :
  44.  
  45.     if ( g_gametype.integer == GT_WOLF_TDM ) {
  46.         //Check team scores. The 1st team to reach the required score wins
  47.         if ( level.teamScores[TEAM_AXIS] >= g_TDMScore.integer ) {
  48.                 trap_GetConfigstring( CS_MULTI_MAPWINNER, cs, sizeof(cs) );
  49.                 Info_SetValueForKey( cs, "w", "0" );
  50.                 trap_SetConfigstring( CS_MULTI_MAPWINNER, cs );
  51.                 LogExit( "TDM : Axis win this round\n" );
  52.                 trap_SendServerCommand( -1, "print \"^3TDM ^7: ^_Axis ^7win this round.\n\"");
  53.                 return;
  54.         } else if (level.teamScores[TEAM_ALLIES] >= g_TDMScore.integer ) {
  55.                 trap_GetConfigstring( CS_MULTI_MAPWINNER, cs, sizeof(cs) );
  56.                 Info_SetValueForKey( cs, "w", "1" );
  57.                 trap_SetConfigstring( CS_MULTI_MAPWINNER, cs );
  58.                 LogExit( "TDM : Allies win this round\n" );
  59.                 trap_SendServerCommand( -1, "print \"^3TDM ^7: ^4Allies ^7win this round.\n\"");
  60.                 return;
  61.         }
  62.     }
  63.  
  64. // Ignore Timelimit.
  65. //  Modify :
  66.  
  67.             if ( level.gameManager && g_gametype.integer != GT_WOLF_TDM ) {
  68.                 G_Script_ScriptEvent( level.gameManager, "trigger", "timelimit_hit" );
  69.             }
  70.  
  71.             if ( g_gametype.integer != GT_WOLF_TDM ){
  72.                 trap_SendServerCommand( -1, "print \"Timelimit hit.\n\"");
  73.                 LogExit( "Timelimit hit." );
  74.             }
  75.  
  76. //Send TeamScores to all the connected clients (except bots)
  77. void SendTeamScoreToAllClient( void )
  78. {
  79.     int i;
  80.  
  81.     for(i=0; i<level.numConnectedClients;i++){
  82.         gentity_t *ent = &g_entities[level.sortedClients[i]];
  83.         if(!(ent->r.svFlags & SVF_BOT) && (ent->client->pers.connected == CON_CONNECTED)){
  84.             G_SendTeamScore(ent);
  85.         }
  86.     }
  87. }
  88.  
  89.  
  90. /*
  91. ***************************
  92. *        g_cmds.c         *
  93. ***************************
  94. */
  95.  
  96. //Send a small string that contains team scores for TDM.
  97. //This is sent to all clients as soon as a player dies during TDM, we are using this method instead of the stock ET method (where full scores are sent) to reduce BW usage and avoid lags on large servers.
  98. void G_SendTeamScore(gentity_t *ent)
  99. {
  100.     trap_SendServerCommand(ent-g_entities, va( "tsc %d %d", level.teamScores[TEAM_AXIS], level.teamScores[TEAM_ALLIES]));
  101. }
  102.  
  103.  
  104. /*
  105. ***************************
  106. *     cg_servercmds.c     *
  107. ***************************
  108. */
  109.  
  110. // CG_ServerCommand()
  111. //  Add :
  112.  
  113.     if (!strcmp( cmd, "tsc" ) ) {
  114.         CG_ParseTeamScore();
  115.         return;
  116.     }
  117.  
  118. /*
  119. Parse Team Scores (used to be done by CG_ParseScore but in TDM gametype, we're sending a smaller string to clients)
  120. */
  121. void CG_ParseTeamScore( void )
  122. {
  123.     cg.teamScores[0] = atoi( CG_Argv( 1 ) );
  124.     cg.teamScores[1] = atoi( CG_Argv( 2 ) );
  125. }
  126.  
  127. /*
  128. ***************************
  129. *        g_combat.c       *
  130. ***************************
  131. */
  132.  
  133. // player_die() - Send updated teamscore to all clients during TDM as soon as a player dies.
  134. //  Add :
  135.  
  136.     if(g_gametype.integer == GT_WOLF_TDM){
  137.         SendTeamScoreToAllClient();
  138.     }
  139.  
  140. /*
  141. ***************************
  142. *      cg_loadpanel.c     *
  143. ***************************
  144. */
  145.  
  146. // CG_LoadPanel_GameTypeName()
  147. //  Add :
  148.             case GT_WOLF_TDM:
  149.             return "Team Death Match";
  150.  
  151.  
  152. // CG_LoadPanel_RenderCampaignPins()
  153. //  Modify:
  154.             if( cgs.gametype == GT_WOLF_STOPWATCH || cgs.gametype == GT_WOLF_LMS || cgs.gametype == GT_WOLF || cgs.gametype == GT_WOLF_MAPVOTE || cg_gameType.integer == GT_WOLF_TDM || cg_gameType.integer == GT_WOLF_DM ) {
  155.  
  156.  
  157. /*
  158. ***************************
  159. *     cg_debriefing.c     *
  160. ***************************
  161. */
  162.  
  163. // CG_TeamDebriefing_CalcXP()
  164. //  Modify:
  165.  
  166.     } else if( cg_gameType.integer == GT_WOLF ||
  167.                 cg_gameType.integer == GT_WOLF_STOPWATCH ||
  168.                 cg_gameType.integer == GT_WOLF_MAPVOTE ||
  169.                 cg_gameType.integer == GT_WOLF_TDM ) {
  170.         for( j = 0; j < SK_NUM_SKILLS; j++ ) {
  171.             if( skillindex != -1 && j != skillindex ) {
  172.                 continue;
  173.             }
  174.             cnt += team == TEAM_AXIS ? cgs.tdbAxisMapsXP[ j ][ 0 ] : cgs.tdbAlliedMapsXP[ j ][ 0 ];
  175.         }
  176.     }
  177.  
  178. // CG_Debriefing_FindWinningTeamForPos()
  179. //  Modify:
  180.  
  181.         } else if( cg_gameType.integer == GT_WOLF || cg_gameType.integer == GT_WOLF_LMS ||
  182.                 cg_gameType.integer == GT_WOLF_MAPVOTE || cg_gameType.integer == GT_WOLF_TDM ||cg_gameType.integer == GT_WOLF_DM ) {
  183.         const char* s = CG_ConfigString( CS_MULTI_MAPWINNER );
  184.         const char* buf = Info_ValueForKey( s, "w" );
  185.  
  186.         if( atoi( buf ) == -1 ) {
  187.         } else if( atoi( buf ) ) {
  188.             return TEAM_ALLIES;
  189.         } else {
  190.             return TEAM_AXIS;
  191.         }
  192.     }
  193.  
  194.  
  195. /*
  196. ***************************
  197. *         cg_draw.c       *
  198. ***************************
  199. */
  200.  
  201. /*
  202. Print Team Scores AND Final TDM Score (Top Center of the screen)
  203. I know, this function sucks and needs to be reworked/rewritten...
  204. */
  205. void Nit_TDMScore_C( void ) {
  206.     char *axis, *allies, *score;
  207.     int a, b, c;
  208.  
  209.     if ( !CG_DrawScoreboard() ){
  210.     axis = va("^_Axis ^7%d", cg.teamScores[0]);
  211.     allies = va("%d ^4Allies", cg.teamScores[1]);
  212.     a = CG_Text_Width_Ext(axis, 0.20f, 0, &cgs.media.limboFont2 );
  213.     b = CG_Text_Width_Ext("|", 0.20f, 0, &cgs.media.limboFont2 );
  214.     score = va("%i", cgs.tdmScore);
  215.     c = CG_Text_Width_Ext(score, 0.20f, 0, &cgs.media.limboFont2 );
  216.     CG_Text_Paint_Ext( SCREEN_WIDTH*.5 - a, 38, 0.20f, 0.20f, colorWhite, axis, 0, 0, ITEM_TEXTSTYLE_SHADOWED, &cgs.media.limboFont2 );
  217.     CG_Text_Paint_Ext( SCREEN_WIDTH*.5, 38, 0.20f, 0.20f, colorWhite, "|", 0, 0, ITEM_TEXTSTYLE_SHADOWED, &cgs.media.limboFont2 );
  218.     CG_Text_Paint_Ext( SCREEN_WIDTH*.5 + b, 38, 0.20f, 0.20f, colorWhite, allies, 0, 0, ITEM_TEXTSTYLE_SHADOWED, &cgs.media.limboFont2 );
  219.     CG_Text_Paint_Ext( SCREEN_WIDTH*.5-15, 39, 0.20f, 0.20f, colorWhite, "______", 0, 0, ITEM_TEXTSTYLE_SHADOWED, &cgs.media.limboFont2 );
  220.     CG_Text_Paint_Ext( SCREEN_WIDTH*.5-(c/2)+3, 49, 0.20f, 0.20f, colorWhite, score, 0, 0, ITEM_TEXTSTYLE_SHADOWED, &cgs.media.limboFont2 );
  221.     }
  222. }
  223.  
  224. /*
  225. Print Team Scores WITHOUT Final TDM Score (Right side of the screen, near lagometer etc...).
  226. */
  227. float Nit_TDMScore_R( float y, qboolean draw ){
  228.     char *axis, *allies;
  229.     int w, w2;
  230.  
  231.     if (draw)
  232.     {
  233.         axis = va("^_Axis ^7%d", cg.teamScores[0]);
  234.         allies = va("^4Allies ^7%d", cg.teamScores[1]);
  235.    
  236.         w = CG_Text_Width_Ext( axis, 0.19f, 0, &cgs.media.limboFont1 );
  237.         w2 = CG_Text_Width_Ext( allies, 0.19f, 0, &cgs.media.limboFont1 );
  238.  
  239.         CG_FillRect( UPPERRIGHT_X - w - 2, y, w + 5, 12 + 2,                HUD_Background );
  240.         CG_DrawRect_FixedBorder( UPPERRIGHT_X - w - 2, y, w + 5, 12 + 2, 1, HUD_Border );
  241.  
  242.         CG_Text_Paint_Ext( UPPERRIGHT_X - w, y + 11, 0.19f, 0.19f, HUD_Text, axis, 0, 0, 0, &cgs.media.limboFont1 );
  243.  
  244.         CG_FillRect( UPPERRIGHT_X - w2 - 2, y + 16, w2 + 5, 12 + 2,             HUD_Background );
  245.         CG_DrawRect_FixedBorder( UPPERRIGHT_X - w2 - 2, y + 16, w2 + 5, 12 + 2, 1, HUD_Border );
  246.  
  247.         CG_Text_Paint_Ext( UPPERRIGHT_X - w2, y + 27, 0.19f, 0.19f, HUD_Text, allies, 0, 0, 0, &cgs.media.limboFont1 );
  248.     }
  249.  
  250.     return y + 28 + 4;
  251. }
  252.  
  253. // CG_DrawUpperRight()
  254. //  Add:
  255.  
  256.     if(cgs.gametype == GT_WOLF_TDM){
  257.         if(cg_TDMScorePos.integer == 1){
  258.             y = Nit_TDMScore_R(y, qtrue);
  259.         } else {
  260.             Nit_TDMScore_C();
  261.         }
  262.     }
  263.  
  264.  
  265. /*
  266. ***************************
  267. *    cg_consolecmds.c     *
  268. ***************************
  269. */
  270.  
  271. /*
  272. /tdminfo client command.
  273. Prints useful informations about TeamDeathMatch Gametype.
  274. */
  275. void Nit_TDMInfo( void )
  276. {
  277.     if(cgs.gametype == GT_WOLF_TDM){
  278.         CG_Printf("^5> ^3Final TDM Score: ^7%d\n", cgs.tdmScore);
  279.         CG_Printf("^5> ^3TDM Rules:\n");
  280.         CG_Printf("- To win the match, your team has to reach the score. This score can be dynamic on some servers. The map will ^1NOT ^7end as long as the score is not reached.\n");
  281.         CG_Printf("- Timelimit: If the timelimit is over, the map will ^1NOT ^7end.\n");
  282.         CG_Printf("- Objective: If the final objective is completed, the map will ^1NOT ^7end. BUT the team will get ^2100 ^7Bonus Points!\n");
  283.         CG_Printf("- XP: Every XP point counts in the score. XP will be saved if XPSave is configured on the server.\n");
  284.         return;
  285.     } else {
  286.         CG_Printf("^5>> ^7N^1!^7tmod: ^1This server is NOT running Team Death Match gametype.\n");
  287.         return;
  288.     }
  289. }
  290.  
  291. // static consoleCommand_t  commands[]
  292. //  Add:
  293.  
  294.     { "tdminfo",            Nit_TDMInfo },
  295.  
  296. //Don't forget to call bani_clearmapxp() and bani_storemapxp() for this gametype aswell.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement