Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 0.52.0/sync
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed May 11, 2020
2 parents 3d1f035 + 63c17d3 commit 84cd6a1
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 10 deletions.
22 changes: 22 additions & 0 deletions src/cgame/cg_key_name.cpp
Expand Up @@ -23,6 +23,7 @@ along with Unvanquished. If not, see <http://www.gnu.org/licenses/>.

#include "cg_key_name.h"

#include "common/Log.h"
#include "common/String.h"
#include "engine/client/cg_api.h"

Expand All @@ -47,3 +48,24 @@ std::string CG_KeyDisplayName(Key key) {
return "???";
}
}

static int bindTeam;

void CG_SetBindTeam(team_t team) {
switch (team) {
case TEAM_NONE:
bindTeam = 3; // BIND_TEAM_SPECTATORS
break;
case TEAM_HUMANS:
case TEAM_ALIENS:
bindTeam = static_cast<int>(team);
break;
default:
Log::Warn("Invalid team %d", team);
}
}

// Get the current team according to the Keyboard::BindTeam type in the engine
int CG_CurrentBindTeam() {
return bindTeam;
}
5 changes: 5 additions & 0 deletions src/cgame/cg_key_name.h
Expand Up @@ -25,7 +25,12 @@ along with Unvanquished. If not, see <http://www.gnu.org/licenses/>.
#define CG_KEY_NAME_H_

#include "common/KeyIdentification.h"
#include "shared/bg_public.h"

std::string CG_KeyDisplayName(Keyboard::Key key);

void CG_SetBindTeam(team_t team);

int CG_CurrentBindTeam();

#endif // CG_KEY_NAME_H_
3 changes: 3 additions & 0 deletions src/cgame/cg_main.cpp
Expand Up @@ -27,6 +27,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// cg_main.c -- initialization for cgame

#include "cg_local.h"
#include "cg_key_name.h"

cg_t cg;
cgs_t cgs;
Expand Down Expand Up @@ -611,6 +612,8 @@ void CG_NotifyHooks()
{
trap_notify_onTeamChange( ps->persistant[ PERS_TEAM ] );

CG_SetBindTeam( static_cast<team_t>( ps->persistant[ PERS_TEAM ] ) );

/* execute team-specific config files */
trap_Cvar_VariableStringBuffer( va( "cg_%sConfig", BG_TeamName( ps->persistant[ PERS_TEAM ] ) ), config, sizeof( config ) );
if ( config[ 0 ] )
Expand Down
6 changes: 4 additions & 2 deletions src/cgame/cg_rocket_draw.cpp
Expand Up @@ -33,6 +33,7 @@ Maryland 20850 USA.
*/

#include "cg_local.h"
#include "cg_key_name.h"
#include "rocket/rocket.h"
#include <Rocket/Core/Element.h>
#include <Rocket/Core/ElementInstancer.h>
Expand Down Expand Up @@ -3318,8 +3319,9 @@ static void CG_Rocket_DrawVote_internal( team_t team )
sec = 0;
}

std::string yeskey = CG_EscapeHTMLText( CG_KeyBinding( va( "%svote yes", team == TEAM_NONE ? "" : "team" ), team ) );
std::string nokey = CG_EscapeHTMLText( CG_KeyBinding( va( "%svote no", team == TEAM_NONE ? "" : "team" ), team ) );
int bindTeam = CG_CurrentBindTeam();
std::string yeskey = CG_EscapeHTMLText( CG_KeyBinding( va( "%svote yes", team == TEAM_NONE ? "" : "team" ), bindTeam ) );
std::string nokey = CG_EscapeHTMLText( CG_KeyBinding( va( "%svote no", team == TEAM_NONE ? "" : "team" ), bindTeam ) );

std::string s = Str::Format( "%sVOTE(%i): %s\n"
" Called by: \"%s\"\n"
Expand Down
8 changes: 7 additions & 1 deletion src/cgame/cg_rocket_progressbar.cpp
Expand Up @@ -57,7 +57,7 @@ static float CG_Rocket_GetOverallLoadProgress()
static float CG_Rocket_GetBuildTimerProgress()
{
static int misc = 0;
static int max;
static int max = 0;
playerState_t *ps = &cg.snap->ps;
weapon_t weapon = BG_GetPlayerWeapon( ps );

Expand All @@ -73,6 +73,12 @@ static float CG_Rocket_GetBuildTimerProgress()
max = ps->stats[ STAT_MISC ];
}

// Avoid division by zero.
if ( max == 0 )
{
return 0;
}

misc = ps->stats[ STAT_MISC ];

return ( float ) misc / ( float ) max;
Expand Down
8 changes: 4 additions & 4 deletions src/cgame/cg_tutorial.cpp
Expand Up @@ -64,18 +64,18 @@ static const size_t numBindings = ARRAY_LEN( bindings );

/*
=================
CG_GetBindings
CG_RefreshBindings
=================
*/
static void CG_GetBindings( team_t team )
static void CG_RefreshBindings()
{
std::vector<std::string> binds;

for (unsigned i = 0; i < numBindings; i++) {
binds.push_back(bindings[i].command);
}

std::vector<std::vector<Keyboard::Key>> keys = trap_Key_GetKeysForBinds(team, binds);
std::vector<std::vector<Keyboard::Key>> keys = trap_Key_GetKeysForBinds(CG_CurrentBindTeam(), binds);

for (unsigned i = 0; i < numBindings; i++) {
bindings[i].keys = keys[i];
Expand Down Expand Up @@ -573,7 +573,7 @@ const char *CG_TutorialText()

if ( refreshBindings == 0 )
{
CG_GetBindings( (team_t) ps->persistant[ PERS_TEAM ] );
CG_RefreshBindings();
}

refreshBindings = ( refreshBindings + 1 ) % BINDING_REFRESH_INTERVAL;
Expand Down
6 changes: 6 additions & 0 deletions src/cgame/cg_weapons.cpp
Expand Up @@ -2654,6 +2654,12 @@ void CG_HandleFireWeapon( centity_t *cent, weaponMode_t weaponMode )
}
}

if ( ( weaponNum == WP_ABUILD || weaponNum == WP_ABUILD2 ) && weaponMode == WPM_SECONDARY
&& ( cg.snap->ps.stats[ STAT_BUILDABLE ] & SB_BUILDABLE_MASK ) > BA_NONE )
{
return; // no sound for canceling buildable placement
}

// play a sound
for ( c = 0; c < 4; c++ )
{
Expand Down
2 changes: 2 additions & 0 deletions src/cgame/rocket/rocket_keys.cpp
Expand Up @@ -311,6 +311,8 @@ void Rocket_MouseMove( int x, int y )
/*
================
CG_KeyBinding
The team argument corresponds to Keyboard::BindTeam, not team_t
================
*/
std::string CG_KeyBinding( const char* bind, int team )
Expand Down
6 changes: 3 additions & 3 deletions src/shared/bg_public.h
Expand Up @@ -29,6 +29,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// bg_public.h -- definitions shared by both the server game and client game modules
//==================================================================

#include "engine/qcommon/q_shared.h"

//Unvanquished balance header
#include "bg_gameplay.h"

Expand Down Expand Up @@ -99,9 +101,7 @@ enum
CS_MAX = CS_LOCATIONS + MAX_LOCATIONS
};

#if CS_MAX > MAX_CONFIGSTRINGS
#error exceeded configstrings: CS_MAX > MAX_CONFIGSTRINGS
#endif
static_assert(CS_MAX <= MAX_CONFIGSTRINGS, "exceeded configstrings");

enum gender_t
{
Expand Down

0 comments on commit 84cd6a1

Please sign in to comment.