summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorTim Angus <tim@ngus.net>2006-01-18 01:54:21 +0000
committerTim Angus <tim@ngus.net>2006-01-18 01:54:21 +0000
commitb5a24aab3dbb3d65950843c19ab2fa9934064281 (patch)
treefef77c5cc94e3376442747136421f07f9bea74b0 /src/game
parent5cf09669133da12cf82ee3168e57a781e47b9e92 (diff)
* Added BG_FindUsableForUpgrade
* Added BG_UpgradeClassAvailable * Added generalised BG_*IsAllowed functions * Added some binding traps to cgame * Added tutorial mode (cg_tutorial)
Diffstat (limited to 'src/game')
-rw-r--r--src/game/bg_misc.c169
-rw-r--r--src/game/bg_public.h8
-rw-r--r--src/game/g_active.c15
-rw-r--r--src/game/g_cmds.c22
-rw-r--r--src/game/g_local.h5
-rw-r--r--src/game/g_main.c107
6 files changed, 190 insertions, 136 deletions
diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c
index cf2649ee..f04d562f 100644
--- a/src/game/bg_misc.c
+++ b/src/game/bg_misc.c
@@ -3989,6 +3989,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Light Armour", //char *upgradeHumanName;
"icons/iconu_larmour",
qtrue, //qboolean purchasable
+ qfalse, //qboolean usable
WUT_HUMANS //WUTeam_t team;
},
{
@@ -4000,6 +4001,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Helmet", //char *upgradeHumanName;
"icons/iconu_helmet",
qtrue, //qboolean purchasable
+ qfalse, //qboolean usable
WUT_HUMANS //WUTeam_t team;
},
{
@@ -4011,6 +4013,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Medkit", //char *upgradeHumanName;
"icons/iconu_atoxin",
qfalse, //qboolean purchasable
+ qtrue, //qboolean usable
WUT_HUMANS //WUTeam_t team;
},
{
@@ -4022,6 +4025,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Battery Pack", //char *upgradeHumanName;
"icons/iconu_battpack",
qtrue, //qboolean purchasable
+ qfalse, //qboolean usable
WUT_HUMANS //WUTeam_t team;
},
{
@@ -4033,6 +4037,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Jet Pack", //char *upgradeHumanName;
"icons/iconu_jetpack",
qtrue, //qboolean purchasable
+ qtrue, //qboolean usable
WUT_HUMANS //WUTeam_t team;
},
{
@@ -4044,6 +4049,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Battlesuit", //char *upgradeHumanName;
"icons/iconu_bsuit",
qtrue, //qboolean purchasable
+ qfalse, //qboolean usable
WUT_HUMANS //WUTeam_t team;
},
{
@@ -4055,6 +4061,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Grenade", //char *upgradeHumanName;
0,
qtrue, //qboolean purchasable
+ qtrue, //qboolean usable
WUT_HUMANS //WUTeam_t team;
},
{
@@ -4066,6 +4073,7 @@ upgradeAttributes_t bg_upgrades[ ] =
"Ammunition", //char *upgradeHumanName;
0,
qtrue, //qboolean purchasable
+ qfalse, //qboolean usable
WUT_HUMANS //WUTeam_t team;
}
};
@@ -4231,6 +4239,24 @@ qboolean BG_FindPurchasableForUpgrade( int upgrade )
/*
==============
+BG_FindUsableForUpgrade
+==============
+*/
+qboolean BG_FindUsableForUpgrade( int upgrade )
+{
+ int i;
+
+ for( i = 0; i < bg_numUpgrades; i++ )
+ {
+ if( bg_upgrades[ i ].upgradeNum == upgrade )
+ return bg_upgrades[ i ].usable;
+ }
+
+ return qfalse;
+}
+
+/*
+==============
BG_FindTeamForUpgrade
==============
*/
@@ -5254,3 +5280,146 @@ void BG_ParseCSVBuildableList( const char *string, buildable_t *buildables, int
buildables[ i ] = BA_NONE;
}
+
+/*
+============
+BG_UpgradeClassAvailable
+============
+*/
+qboolean BG_UpgradeClassAvailable( playerState_t *ps )
+{
+ int i;
+ char buffer[ MAX_STRING_CHARS ];
+ stage_t currentStage;
+
+ trap_Cvar_VariableStringBuffer( "g_alienStage", buffer, MAX_STRING_CHARS );
+ currentStage = atoi( buffer );
+
+ for( i = PCL_NONE + 1; i < PCL_NUM_CLASSES; i++ )
+ {
+ if( BG_ClassCanEvolveFromTo( ps->stats[ STAT_PCLASS ], i,
+ ps->persistant[ PERS_CREDIT ], 0 ) >= 0 &&
+ BG_FindStagesForClass( i, currentStage ) &&
+ BG_ClassIsAllowed( i ) )
+ {
+ return qtrue;
+ }
+ }
+
+ return qfalse;
+}
+
+typedef struct gameElements_s
+{
+ buildable_t buildables[ BA_NUM_BUILDABLES ];
+ pClass_t classes[ PCL_NUM_CLASSES ];
+ weapon_t weapons[ WP_NUM_WEAPONS ];
+ upgrade_t upgrades[ UP_NUM_UPGRADES ];
+} gameElements_t;
+
+static gameElements_t bg_disabledGameElements;
+
+/*
+============
+BG_InitAllowedGameElements
+============
+*/
+void BG_InitAllowedGameElements( void )
+{
+ char cvar[ MAX_CVAR_VALUE_STRING ];
+
+ trap_Cvar_VariableStringBuffer( "g_disabledEquipment",
+ cvar, MAX_CVAR_VALUE_STRING );
+
+ BG_ParseCSVEquipmentList( cvar,
+ bg_disabledGameElements.weapons, WP_NUM_WEAPONS,
+ bg_disabledGameElements.upgrades, UP_NUM_UPGRADES );
+
+ trap_Cvar_VariableStringBuffer( "g_disabledClasses",
+ cvar, MAX_CVAR_VALUE_STRING );
+
+ BG_ParseCSVClassList( cvar,
+ bg_disabledGameElements.classes, PCL_NUM_CLASSES );
+
+ trap_Cvar_VariableStringBuffer( "g_disabledBuildables",
+ cvar, MAX_CVAR_VALUE_STRING );
+
+ BG_ParseCSVBuildableList( cvar,
+ bg_disabledGameElements.buildables, BA_NUM_BUILDABLES );
+}
+
+/*
+============
+BG_WeaponIsAllowed
+============
+*/
+qboolean BG_WeaponIsAllowed( weapon_t weapon )
+{
+ int i;
+
+ for( i = 0; i < WP_NUM_WEAPONS &&
+ bg_disabledGameElements.weapons[ i ] != WP_NONE; i++ )
+ {
+ if( bg_disabledGameElements.weapons[ i ] == weapon )
+ return qfalse;
+ }
+
+ return qtrue;
+}
+
+/*
+============
+BG_UpgradeIsAllowed
+============
+*/
+qboolean BG_UpgradeIsAllowed( upgrade_t upgrade )
+{
+ int i;
+
+ for( i = 0; i < UP_NUM_UPGRADES &&
+ bg_disabledGameElements.upgrades[ i ] != UP_NONE; i++ )
+ {
+ if( bg_disabledGameElements.upgrades[ i ] == upgrade )
+ return qfalse;
+ }
+
+ return qtrue;
+}
+
+/*
+============
+BG_ClassIsAllowed
+============
+*/
+qboolean BG_ClassIsAllowed( pClass_t class )
+{
+ int i;
+
+ for( i = 0; i < PCL_NUM_CLASSES &&
+ bg_disabledGameElements.classes[ i ] != PCL_NONE; i++ )
+ {
+ if( bg_disabledGameElements.classes[ i ] == class )
+ return qfalse;
+ }
+
+ return qtrue;
+}
+
+/*
+============
+BG_BuildableIsAllowed
+============
+*/
+qboolean BG_BuildableIsAllowed( buildable_t buildable )
+{
+ int i;
+
+ for( i = 0; i < BA_NUM_BUILDABLES &&
+ bg_disabledGameElements.buildables[ i ] != BA_NONE; i++ )
+ {
+ if( bg_disabledGameElements.buildables[ i ] == buildable )
+ return qfalse;
+ }
+
+ return qtrue;
+}
diff --git a/src/game/bg_public.h b/src/game/bg_public.h
index 38e7b3ee..b7e1411e 100644
--- a/src/game/bg_public.h
+++ b/src/game/bg_public.h
@@ -1078,6 +1078,7 @@ typedef struct
char *icon;
qboolean purchasable;
+ qboolean usable;
WUTeam_t team;
} upgradeAttributes_t;
@@ -1207,6 +1208,7 @@ int BG_FindUpgradeNumForName( char *name );
char *BG_FindHumanNameForUpgrade( int upgrade );
char *BG_FindIconForUpgrade( int upgrade );
qboolean BG_FindPurchasableForUpgrade( int upgrade );
+qboolean BG_FindUsableForUpgrade( int upgrade );
WUTeam_t BG_FindTeamForUpgrade( int upgrade );
// content masks
@@ -1276,3 +1278,9 @@ void BG_ParseCSVEquipmentList( const char *string, weapon_t *weapons, int weapon
upgrade_t *upgrades, int upgradesSize );
void BG_ParseCSVClassList( const char *string, pClass_t *classes, int classesSize );
void BG_ParseCSVBuildableList( const char *string, buildable_t *buildables, int buildablesSize );
+void BG_InitAllowedGameElements( void );
+qboolean BG_WeaponIsAllowed( weapon_t weapon );
+qboolean BG_UpgradeIsAllowed( upgrade_t upgrade );
+qboolean BG_ClassIsAllowed( pClass_t class );
+qboolean BG_BuildableIsAllowed( buildable_t buildable );
+qboolean BG_UpgradeClassAvailable( playerState_t *ps );
diff --git a/src/game/g_active.c b/src/game/g_active.c
index 86bfbdc5..9c8f8a1c 100644
--- a/src/game/g_active.c
+++ b/src/game/g_active.c
@@ -1292,8 +1292,6 @@ void ClientThink_real( gentity_t *ent )
vec3_t range = { USE_OBJECT_RANGE, USE_OBJECT_RANGE, USE_OBJECT_RANGE };
vec3_t mins, maxs;
int i, num;
- int j;
- qboolean upgrade = qfalse;
//TA: look for object infront of player
AngleVectors( client->ps.viewangles, view, NULL, NULL );
@@ -1325,18 +1323,7 @@ void ClientThink_real( gentity_t *ent )
if( i == num && client->ps.stats[ STAT_PTEAM ] == PTE_ALIENS )
{
- for( j = PCL_NONE + 1; j < PCL_NUM_CLASSES; j++ )
- {
- if( BG_ClassCanEvolveFromTo( client->ps.stats[ STAT_PCLASS ], j,
- client->ps.persistant[ PERS_CREDIT ], 0 ) >= 0 &&
- BG_FindStagesForClass( j, g_alienStage.integer ) && G_ClassIsAllowed( j ) )
- {
- upgrade = qtrue;
- break;
- }
- }
-
- if( upgrade )
+ if( BG_UpgradeClassAvailable( &client->ps ) )
{
//no nearby objects and alien - show class menu
G_TriggerMenu( ent->client->ps.clientNum, MN_A_INFEST );
diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c
index b53d4bd2..f091ff48 100644
--- a/src/game/g_cmds.c
+++ b/src/game/g_cmds.c
@@ -1121,14 +1121,14 @@ void Cmd_Class_f( gentity_t *ent )
clientNum = ent->client - level.clients;
trap_Argv( 1, s, sizeof( s ) );
- if( G_ClassIsAllowed( PCL_ALIEN_BUILDER0 ) )
+ if( BG_ClassIsAllowed( PCL_ALIEN_BUILDER0 ) )
allowedClasses[ numClasses++ ] = PCL_ALIEN_BUILDER0;
- if( G_ClassIsAllowed( PCL_ALIEN_BUILDER0_UPG ) &&
+ if( BG_ClassIsAllowed( PCL_ALIEN_BUILDER0_UPG ) &&
BG_FindStagesForClass( PCL_ALIEN_BUILDER0_UPG, g_alienStage.integer ) )
allowedClasses[ numClasses++ ] = PCL_ALIEN_BUILDER0_UPG;
- if( G_ClassIsAllowed( PCL_ALIEN_LEVEL0 ) )
+ if( BG_ClassIsAllowed( PCL_ALIEN_LEVEL0 ) )
allowedClasses[ numClasses++ ] = PCL_ALIEN_LEVEL0;
if( ent->client->pers.teamSelection == PTE_ALIENS &&
@@ -1216,7 +1216,7 @@ void Cmd_Class_f( gentity_t *ent )
//...check we can evolve to that class
if( numLevels >= 0 &&
BG_FindStagesForClass( ent->client->pers.classSelection, g_alienStage.integer ) &&
- G_ClassIsAllowed( ent->client->pers.classSelection ) )
+ BG_ClassIsAllowed( ent->client->pers.classSelection ) )
{
ent->client->pers.evolveHealthFraction = (float)ent->client->ps.stats[ STAT_HEALTH ] /
(float)BG_FindHealthForClass( currentClass );
@@ -1261,7 +1261,7 @@ void Cmd_Class_f( gentity_t *ent )
{
if( allowedClasses[ i ] == ent->client->pers.classSelection &&
BG_FindStagesForClass( ent->client->pers.classSelection, g_alienStage.integer ) &&
- G_ClassIsAllowed( ent->client->pers.classSelection ) )
+ BG_ClassIsAllowed( ent->client->pers.classSelection ) )
{
G_PushSpawnQueue( &level.alienSpawnQueue, clientNum );
return;
@@ -1291,11 +1291,11 @@ void Cmd_Class_f( gentity_t *ent )
ent->client->ps.stats[ STAT_PCLASS ] = PCL_HUMAN;
//set the item to spawn with
- if( !Q_stricmp( s, BG_FindNameForWeapon( WP_MACHINEGUN ) ) && G_WeaponIsAllowed( WP_MACHINEGUN ) )
+ if( !Q_stricmp( s, BG_FindNameForWeapon( WP_MACHINEGUN ) ) && BG_WeaponIsAllowed( WP_MACHINEGUN ) )
ent->client->pers.humanItemSelection = WP_MACHINEGUN;
- else if( !Q_stricmp( s, BG_FindNameForWeapon( WP_HBUILD ) ) && G_WeaponIsAllowed( WP_HBUILD ) )
+ else if( !Q_stricmp( s, BG_FindNameForWeapon( WP_HBUILD ) ) && BG_WeaponIsAllowed( WP_HBUILD ) )
ent->client->pers.humanItemSelection = WP_HBUILD;
- else if( !Q_stricmp( s, BG_FindNameForWeapon( WP_HBUILD2 ) ) && G_WeaponIsAllowed( WP_HBUILD2 ) &&
+ else if( !Q_stricmp( s, BG_FindNameForWeapon( WP_HBUILD2 ) ) && BG_WeaponIsAllowed( WP_HBUILD2 ) &&
BG_FindStagesForWeapon( WP_HBUILD2, g_humanStage.integer ) )
ent->client->pers.humanItemSelection = WP_HBUILD2;
else
@@ -1569,7 +1569,7 @@ void Cmd_Buy_f( gentity_t *ent )
}
//are we /allowed/ to buy this?
- if( !BG_FindStagesForWeapon( weapon, g_humanStage.integer ) || !G_WeaponIsAllowed( weapon ) )
+ if( !BG_FindStagesForWeapon( weapon, g_humanStage.integer ) || !BG_WeaponIsAllowed( weapon ) )
{
G_SendCommandFromServer( ent-g_entities, va( "print \"You can't buy this item\n\"" ) );
return;
@@ -1632,7 +1632,7 @@ void Cmd_Buy_f( gentity_t *ent )
}
//are we /allowed/ to buy this?
- if( !BG_FindStagesForUpgrade( upgrade, g_humanStage.integer ) || !G_UpgradeIsAllowed( upgrade ) )
+ if( !BG_FindStagesForUpgrade( upgrade, g_humanStage.integer ) || !BG_UpgradeIsAllowed( upgrade ) )
{
G_SendCommandFromServer( ent-g_entities, va( "print \"You can't buy this item\n\"" ) );
return;
@@ -1844,7 +1844,7 @@ void Cmd_Build_f( gentity_t *ent )
( ( 1 << ent->client->ps.weapon ) & BG_FindBuildWeaponForBuildable( buildable ) ) &&
!( ent->client->ps.stats[ STAT_STATE ] & SS_INFESTING ) &&
!( ent->client->ps.stats[ STAT_STATE ] & SS_HOVELING ) &&
- G_BuildableIsAllowed( buildable ) &&
+ BG_BuildableIsAllowed( buildable ) &&
( ( team == PTE_ALIENS && BG_FindStagesForBuildable( buildable, g_alienStage.integer ) ) ||
( team == PTE_HUMANS && BG_FindStagesForBuildable( buildable, g_humanStage.integer ) ) ) )
{
diff --git a/src/game/g_local.h b/src/game/g_local.h
index 4431edaf..1648f116 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -886,11 +886,6 @@ void SendScoreboardMessageToAllClients( void );
void QDECL G_Printf( const char *fmt, ... );
void QDECL G_Error( const char *fmt, ... );
-qboolean G_WeaponIsAllowed( weapon_t weapon );
-qboolean G_UpgradeIsAllowed( upgrade_t upgrade );
-qboolean G_ClassIsAllowed( pClass_t class );
-qboolean G_BuildableIsAllowed( buildable_t buildable );
-
//
// g_client.c
//
diff --git a/src/game/g_main.c b/src/game/g_main.c
index e77b5b76..d3e5b13e 100644
--- a/src/game/g_main.c
+++ b/src/game/g_main.c
@@ -426,111 +426,6 @@ void G_UpdateCvars( void )
G_RemapTeamShaders( );
}
-
-typedef struct gameElements_s
-{
- buildable_t buildables[ BA_NUM_BUILDABLES ];
- pClass_t classes[ PCL_NUM_CLASSES ];
- weapon_t weapons[ WP_NUM_WEAPONS ];
- upgrade_t upgrades[ UP_NUM_UPGRADES ];
-} gameElements_t;
-
-static gameElements_t disabledGameElements;
-
-/*
-============
-G_InitAllowedGameElements
-============
-*/
-static void G_InitAllowedGameElements( void )
-{
- BG_ParseCSVEquipmentList( g_disabledEquipment.string,
- disabledGameElements.weapons, WP_NUM_WEAPONS,
- disabledGameElements.upgrades, UP_NUM_UPGRADES );
-
- BG_ParseCSVClassList( g_disabledClasses.string,
- disabledGameElements.classes, PCL_NUM_CLASSES );
-
- BG_ParseCSVBuildableList( g_disabledBuildables.string,
- disabledGameElements.buildables, BA_NUM_BUILDABLES );
-}
-
-/*
-============
-G_WeaponIsAllowed
-============
-*/
-qboolean G_WeaponIsAllowed( weapon_t weapon )
-{
- int i;
-
- for( i = 0; i < WP_NUM_WEAPONS &&
- disabledGameElements.weapons[ i ] != WP_NONE; i++ )
- {
- if( disabledGameElements.weapons[ i ] == weapon )
- return qfalse;
- }
-
- return qtrue;
-}
-
-/*
-============
-G_UpgradeIsAllowed
-============
-*/
-qboolean G_UpgradeIsAllowed( upgrade_t upgrade )
-{
- int i;
-
- for( i = 0; i < UP_NUM_UPGRADES &&
- disabledGameElements.upgrades[ i ] != UP_NONE; i++ )
- {
- if( disabledGameElements.upgrades[ i ] == upgrade )
- return qfalse;
- }
-
- return qtrue;
-}
-
-/*
-============
-G_ClassIsAllowed
-============
-*/
-qboolean G_ClassIsAllowed( pClass_t class )
-{
- int i;
-
- for( i = 0; i < PCL_NUM_CLASSES &&
- disabledGameElements.classes[ i ] != PCL_NONE; i++ )
- {
- if( disabledGameElements.classes[ i ] == class )
- return qfalse;
- }
-
- return qtrue;
-}
-
-/*
-============
-G_BuildableIsAllowed
-============
-*/
-qboolean G_BuildableIsAllowed( buildable_t buildable )
-{
- int i;
-
- for( i = 0; i < BA_NUM_BUILDABLES &&
- disabledGameElements.buildables[ i ] != BA_NONE; i++ )
- {
- if( disabledGameElements.buildables[ i ] == buildable )
- return qfalse;
- }
-
- return qtrue;
-}
-
/*
============
G_InitGame
@@ -610,7 +505,7 @@ void G_InitGame( int levelTime, int randomSeed, int restart )
G_SpawnEntitiesFromString( );
// the map might disable some things
- G_InitAllowedGameElements( );
+ BG_InitAllowedGameElements( );
// general initialization
G_FindTeams( );