2016-12-04 14:04:30 +00:00
|
|
|
/*
|
2018-06-14 10:05:23 +00:00
|
|
|
Copyright 2016-2018 Marco "eukara" Hladik
|
|
|
|
|
|
|
|
MIT LICENSE
|
2016-12-04 14:04:30 +00:00
|
|
|
|
2018-06-14 10:05:23 +00:00
|
|
|
Permission is hereby granted, free of charge, to any person
|
|
|
|
obtaining a copy of this software and associated documentation
|
|
|
|
files (the "Software"), to deal in the Software without
|
|
|
|
restriction, including without limitation the rights to use,
|
|
|
|
copy, modify, merge, publish, distribute, sublicense, and/or
|
|
|
|
sell copies of the Software, and to permit persons to whom the
|
|
|
|
Software is furnished to do so, subject to the following conditions:
|
2016-12-04 14:04:30 +00:00
|
|
|
|
2018-06-14 10:05:23 +00:00
|
|
|
The above copyright notice and this permission notice shall be
|
|
|
|
included in all copies or substantial portions of the Software.
|
2016-12-04 14:04:30 +00:00
|
|
|
|
2018-06-14 10:05:23 +00:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
2016-12-04 14:04:30 +00:00
|
|
|
*/
|
|
|
|
|
2016-12-07 00:05:06 +00:00
|
|
|
enum {
|
|
|
|
BUY_BOTH,
|
|
|
|
BUY_CT,
|
|
|
|
BUY_T,
|
|
|
|
BUY_NEITHER
|
|
|
|
};
|
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Rules_BuyingPossible
|
|
|
|
|
|
|
|
Checks if it is possible for players to buy anything
|
|
|
|
=================
|
|
|
|
*/
|
2016-12-05 00:22:52 +00:00
|
|
|
float Rules_BuyingPossible( void ) {
|
2017-01-10 15:45:41 +00:00
|
|
|
if ( self.health <= 0 ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-12-05 00:22:52 +00:00
|
|
|
if ( fGameState == GAME_ACTIVE ) {
|
2016-12-18 09:09:01 +00:00
|
|
|
if ( ( ( autocvar_mp_roundtime * 60 ) - fGameTime ) > autocvar_mp_buytime ) {
|
|
|
|
centerprint( self, sprintf( "%d seconds have passed...\nYou can't buy anything now!", autocvar_mp_buytime ) );
|
2016-12-05 00:22:52 +00:00
|
|
|
self.fAttackFinished = time + 1.0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 23:03:13 +00:00
|
|
|
if ( self.team == TEAM_VIP ) {
|
|
|
|
centerprint( self, "You are the VIP...\nYou can't buy anything!\n" );
|
|
|
|
self.fAttackFinished = time + 1.0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-12-07 00:05:06 +00:00
|
|
|
if ( iBuyRestriction == BUY_NEITHER ) {
|
2016-12-09 23:03:13 +00:00
|
|
|
centerprint( self, "Sorry, you aren't meant\nto be buying anything.\n" );
|
2016-12-07 00:05:06 +00:00
|
|
|
self.fAttackFinished = time + 1.0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( iBuyRestriction != BUY_BOTH ) {
|
|
|
|
if ( iBuyRestriction == BUY_CT && self.team == TEAM_T ) {
|
2016-12-09 23:03:13 +00:00
|
|
|
centerprint( self, "Terrorists aren't allowed to\nbuy anything on this map!\n" );
|
2016-12-07 00:05:06 +00:00
|
|
|
self.fAttackFinished = time + 1.0;
|
|
|
|
return FALSE;
|
|
|
|
} else if ( iBuyRestriction == BUY_T && self.team == TEAM_CT ) {
|
2016-12-09 23:03:13 +00:00
|
|
|
centerprint( self, "CTs aren't allowed to buy\nanything on this map!\n" );
|
2016-12-07 00:05:06 +00:00
|
|
|
self.fAttackFinished = time + 1.0;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-10 20:24:14 +00:00
|
|
|
if ( self.fInBuyZone == FALSE ) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-12-05 00:22:52 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2017-11-18 06:30:20 +00:00
|
|
|
void Rules_MakeBomber( void ) {
|
|
|
|
Weapon_AddItem( WEAPON_C4BOMB );
|
|
|
|
centerprint( self, "You have the bomb!\nFind the target zone or DROP\nthe bomb for another Terrorist." );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rules_MakeVIP( void ) {
|
|
|
|
self.team = TEAM_VIP;
|
|
|
|
Spawn_RespawnClient( self.team );
|
|
|
|
centerprint( self, "You are the VIP\nMake your way to the safety zones!" );
|
|
|
|
forceinfokey( self, "*dead", "2" );
|
|
|
|
}
|
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Rules_Restart
|
|
|
|
|
|
|
|
Loop through all ents and handle them
|
|
|
|
=================
|
|
|
|
*/
|
2018-01-29 18:14:30 +00:00
|
|
|
void Rules_Restart( int iWipe ) {
|
2016-12-09 23:03:13 +00:00
|
|
|
iHostagesRescued = 0;
|
|
|
|
|
2016-12-07 23:09:50 +00:00
|
|
|
entity eOld = self;
|
2016-12-04 14:04:30 +00:00
|
|
|
|
2017-01-10 15:45:41 +00:00
|
|
|
// Spawn/Respawn everyone at their team position and give them $$$
|
2016-12-10 14:39:54 +00:00
|
|
|
for ( entity eFind = world; ( eFind = find( eFind, classname, "player" ) ); ) {
|
2016-12-04 14:04:30 +00:00
|
|
|
self = eFind;
|
|
|
|
|
2018-01-29 18:14:30 +00:00
|
|
|
if ( self.health > 0 && iWipe == FALSE ) {
|
2016-12-04 14:04:30 +00:00
|
|
|
Spawn_RespawnClient( self.team );
|
|
|
|
} else {
|
2018-01-29 18:14:30 +00:00
|
|
|
Spawn_MakeSpectator();
|
2016-12-05 00:22:52 +00:00
|
|
|
Spawn_CreateClient( self.fCharModel );
|
2016-12-04 14:04:30 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 18:14:30 +00:00
|
|
|
if ( iWipe == FALSE ) {
|
|
|
|
Money_GiveTeamReward();
|
|
|
|
} else {
|
|
|
|
self.fMoney = autocvar_mp_startmoney;
|
|
|
|
}
|
2016-12-04 14:04:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-11 23:31:19 +00:00
|
|
|
// Clear the corpses/items
|
|
|
|
for ( entity eFind = world; ( eFind = find( eFind, classname, "remove_me" ) ); ) {
|
2017-01-10 15:45:41 +00:00
|
|
|
remove( eFind );
|
|
|
|
}
|
|
|
|
|
2017-11-12 19:57:23 +00:00
|
|
|
// Find the bombs. Destory them!
|
|
|
|
for ( entity eFind = world; ( eFind = find( eFind, classname, "c4bomb" ) ); ) {
|
|
|
|
remove( eFind );
|
|
|
|
}
|
|
|
|
|
2017-01-10 15:45:41 +00:00
|
|
|
// Select a random Terrorist for the bomb, if needed
|
2016-12-07 00:57:17 +00:00
|
|
|
if ( iBombZones > 0 ) {
|
2016-12-10 14:25:16 +00:00
|
|
|
int iRandomT = floor( random( 1, (float)iAlivePlayers_T + 1 ) );
|
2016-12-08 20:24:09 +00:00
|
|
|
int iPickT = 0;
|
2016-12-07 00:57:17 +00:00
|
|
|
|
2016-12-10 14:39:54 +00:00
|
|
|
for ( entity eFind = world; ( eFind = find( eFind, classname, "player" ) ); ) {
|
2016-12-10 14:25:16 +00:00
|
|
|
if ( eFind.team == TEAM_T ) {
|
2016-12-08 20:24:09 +00:00
|
|
|
iPickT++;
|
2016-12-07 00:57:17 +00:00
|
|
|
|
2016-12-08 20:24:09 +00:00
|
|
|
if ( iPickT == iRandomT ) {
|
2016-12-07 00:57:17 +00:00
|
|
|
self = eFind;
|
2017-11-18 06:30:20 +00:00
|
|
|
Rules_MakeBomber();
|
2016-12-07 00:57:17 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-08 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is a VIP, select a random CT to be it
|
|
|
|
if ( iVIPZones > 0 ) {
|
2016-12-10 14:25:16 +00:00
|
|
|
int iRandomCT = floor( random( 1, (float)iAlivePlayers_CT + 1 ) );
|
2016-12-08 20:24:09 +00:00
|
|
|
int iPickCT = 0;
|
|
|
|
|
2016-12-10 14:39:54 +00:00
|
|
|
for ( entity eFind = world; ( eFind = find( eFind, classname, "player" ) ); ) {
|
2016-12-10 14:25:16 +00:00
|
|
|
if ( eFind.team == TEAM_CT ) {
|
2016-12-08 20:24:09 +00:00
|
|
|
iPickCT++;
|
|
|
|
if ( iPickCT == iRandomCT ) {
|
|
|
|
self = eFind;
|
2017-11-18 06:30:20 +00:00
|
|
|
Rules_MakeVIP();
|
2016-12-08 20:24:09 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-07 00:57:17 +00:00
|
|
|
}
|
2016-12-10 14:25:16 +00:00
|
|
|
|
2016-12-07 00:57:17 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 19:38:26 +00:00
|
|
|
// Respawn all the entities
|
2016-12-10 14:39:54 +00:00
|
|
|
for ( entity eFind = world; ( eFind = findfloat( eFind, fRespawns, TRUE ) ); ) {
|
2016-12-07 19:38:26 +00:00
|
|
|
self = eFind;
|
|
|
|
Entities_Respawn();
|
|
|
|
}
|
2016-12-10 14:25:16 +00:00
|
|
|
|
2016-12-07 23:09:50 +00:00
|
|
|
self = eOld;
|
2016-12-07 19:38:26 +00:00
|
|
|
|
2016-12-18 09:09:01 +00:00
|
|
|
Timer_Begin( autocvar_mp_freezetime, GAME_FREEZE );
|
2016-12-09 23:03:13 +00:00
|
|
|
Money_ResetTeamReward();
|
2016-12-04 14:04:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Rules_RoundOver
|
|
|
|
|
|
|
|
This happens whenever an objective is complete or time is up
|
|
|
|
=================
|
|
|
|
*/
|
2016-12-11 10:10:03 +00:00
|
|
|
void Rules_RoundOver( int iTeamWon, int iMoneyReward, float fSilent ) {
|
2016-12-07 02:35:01 +00:00
|
|
|
|
|
|
|
if ( fGameState != GAME_ACTIVE ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-04 14:04:30 +00:00
|
|
|
if ( iTeamWon == TEAM_T ) {
|
2016-12-17 12:55:18 +00:00
|
|
|
if ( fSilent == FALSE ) {
|
2016-12-11 10:10:03 +00:00
|
|
|
Radio_BroadcastMessage( RADIO_TERWIN );
|
|
|
|
}
|
2016-12-04 14:04:30 +00:00
|
|
|
iWon_T++;
|
2017-11-16 22:53:02 +00:00
|
|
|
|
|
|
|
// FIXME: Calculate the proper loss values
|
|
|
|
Money_QueTeamReward( TEAM_CT, 1400 );
|
2016-12-04 14:04:30 +00:00
|
|
|
} else if ( iTeamWon == TEAM_CT ) {
|
2016-12-17 12:55:18 +00:00
|
|
|
if ( fSilent == FALSE ) {
|
2016-12-11 10:10:03 +00:00
|
|
|
Radio_BroadcastMessage( RADIO_CTWIN );
|
|
|
|
}
|
2016-12-04 14:04:30 +00:00
|
|
|
iWon_CT++;
|
2017-11-16 22:53:02 +00:00
|
|
|
// FIXME: Calculate the proper loss values
|
|
|
|
Money_QueTeamReward( TEAM_T, 1400 );
|
2016-12-04 14:04:30 +00:00
|
|
|
} else {
|
2016-12-17 12:55:18 +00:00
|
|
|
if ( fSilent == FALSE ) {
|
2016-12-11 10:10:03 +00:00
|
|
|
Radio_BroadcastMessage( RADIO_ROUNDDRAW );
|
|
|
|
}
|
2016-12-04 14:04:30 +00:00
|
|
|
}
|
2018-01-29 18:14:30 +00:00
|
|
|
|
2016-12-09 23:03:13 +00:00
|
|
|
Money_QueTeamReward( iTeamWon, iMoneyReward );
|
2016-12-04 14:04:30 +00:00
|
|
|
Timer_Begin( 5, GAME_END); // Round is over, 5 seconds til a new round starts
|
2017-11-16 02:25:20 +00:00
|
|
|
|
|
|
|
iBombPlanted = 0;
|
2018-01-29 18:14:30 +00:00
|
|
|
iRounds++;
|
2016-12-04 14:04:30 +00:00
|
|
|
}
|
|
|
|
|
2017-01-10 18:24:45 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Rules_TimeOver
|
|
|
|
|
|
|
|
Whenever mp_roundtime was being counted down to 0
|
|
|
|
=================
|
|
|
|
*/
|
2016-12-04 14:04:30 +00:00
|
|
|
void Rules_TimeOver( void ) {
|
2016-12-08 20:24:09 +00:00
|
|
|
if ( iVIPZones > 0 ) {
|
2016-12-11 10:10:03 +00:00
|
|
|
Rules_RoundOver( TEAM_T, 3250, FALSE );
|
2016-12-08 20:24:09 +00:00
|
|
|
} else if ( iBombZones > 0 ) {
|
2016-12-11 10:10:03 +00:00
|
|
|
Rules_RoundOver( TEAM_CT, 3250, FALSE );
|
2016-12-04 14:04:30 +00:00
|
|
|
} else if ( iHostagesMax > 0 ) {
|
2016-12-05 18:06:24 +00:00
|
|
|
// TODO: Broadcast_Print: Hostages have not been rescued!
|
2016-12-11 10:10:03 +00:00
|
|
|
Rules_RoundOver( TEAM_T, 3250, FALSE );
|
2016-12-04 14:04:30 +00:00
|
|
|
} else {
|
2016-12-11 10:10:03 +00:00
|
|
|
Rules_RoundOver( 0, 0, FALSE );
|
2016-12-04 14:04:30 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-07 00:05:06 +00:00
|
|
|
|
2018-01-29 18:14:30 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
Rules_SwitchTeams
|
|
|
|
|
|
|
|
Happens rarely
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
void Rules_SwitchTeams( void ) {
|
|
|
|
int iCTW, iTW;
|
|
|
|
|
|
|
|
for ( entity eFind = world; ( eFind = find( eFind, classname, "player" ) ); ) {
|
|
|
|
if ( eFind.team == TEAM_CT ) {
|
|
|
|
eFind.team = TEAM_T;
|
|
|
|
eFind.fCharModel -= 4;
|
|
|
|
} else if ( eFind.team == TEAM_T ) {
|
|
|
|
eFind.team = TEAM_CT;
|
|
|
|
eFind.fCharModel += 4;
|
|
|
|
}
|
|
|
|
forceinfokey( eFind, "*team", ftos( eFind.team ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
iCTW = iWon_CT;
|
|
|
|
iTW = iWon_T;
|
|
|
|
|
|
|
|
iWon_T = iCTW;
|
|
|
|
iWon_CT = iTW;
|
|
|
|
|
|
|
|
iCTW = iAlivePlayers_CT;
|
|
|
|
iTW = iAlivePlayers_T;
|
|
|
|
|
|
|
|
iAlivePlayers_CT = iTW;
|
|
|
|
iAlivePlayers_T = iCTW;
|
|
|
|
}
|
|
|
|
|
2018-12-05 14:05:56 +00:00
|
|
|
void Rules_CountPlayers(void)
|
|
|
|
{
|
|
|
|
iAlivePlayers_T = 0;
|
|
|
|
iAlivePlayers_CT = 0;
|
|
|
|
|
|
|
|
for (entity eFind = world; (eFind = find(eFind, classname, "player")); ) {
|
|
|
|
if (eFind.health > 0) {
|
|
|
|
if ( eFind.team == TEAM_T) {
|
|
|
|
iAlivePlayers_T++;
|
|
|
|
} else if (eFind.team == TEAM_CT) {
|
|
|
|
iAlivePlayers_CT++;
|
|
|
|
} else if (eFind.team == TEAM_VIP) {
|
|
|
|
iAlivePlayers_CT++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Rules_DeathCheck(void)
|
|
|
|
{
|
|
|
|
if ( ( iAlivePlayers_T == 0 ) && ( iAlivePlayers_CT == 0 ) ) {
|
|
|
|
if ( iBombPlanted == TRUE ) {
|
|
|
|
Rules_RoundOver( TEAM_T, 3600, FALSE );
|
|
|
|
} else {
|
|
|
|
Rules_RoundOver( FALSE, 0, FALSE );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if ( ( self.team == TEAM_T ) && ( iAlivePlayers_T == 0 ) ) {
|
|
|
|
if ( iBombPlanted == FALSE ) {
|
|
|
|
Rules_RoundOver( TEAM_CT, 3600, FALSE );
|
|
|
|
}
|
|
|
|
} else if ( ( self.team == TEAM_CT ) && ( iAlivePlayers_CT == 0 ) ) {
|
|
|
|
Rules_RoundOver( TEAM_T, 3600, FALSE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-07 00:05:06 +00:00
|
|
|
/*
|
|
|
|
=================
|
|
|
|
SPAWN: info_map_parameters
|
|
|
|
|
|
|
|
Let's map authors decide who can buy stuff and who CAN'T.
|
|
|
|
Also allows people to set the bomb placing radius incase you want to use info_bomb_target.
|
|
|
|
=================
|
|
|
|
*/
|
|
|
|
.float buying;
|
2017-01-10 15:45:41 +00:00
|
|
|
.float bombradius;
|
|
|
|
void info_map_parameters( void ) {
|
|
|
|
if ( self.bombradius ) {
|
|
|
|
iBombRadius = self.bombradius;
|
|
|
|
}
|
|
|
|
if ( self.buying ) {
|
2016-12-07 00:57:17 +00:00
|
|
|
iBuyRestriction = self.buying;
|
|
|
|
}
|
2016-12-07 00:05:06 +00:00
|
|
|
}
|