diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cgame/cg_consolecmds.c | 1 | ||||
-rw-r--r-- | src/game/bg_misc.c | 337 | ||||
-rw-r--r-- | src/game/bg_public.h | 28 | ||||
-rw-r--r-- | src/game/g_client.c | 6 | ||||
-rw-r--r-- | src/game/g_cmds.c | 100 |
5 files changed, 409 insertions, 63 deletions
diff --git a/src/cgame/cg_consolecmds.c b/src/cgame/cg_consolecmds.c index 13e68628..7df6f751 100644 --- a/src/cgame/cg_consolecmds.c +++ b/src/cgame/cg_consolecmds.c @@ -295,6 +295,7 @@ void CG_InitConsoleCommands( void ) { trap_AddCommand ("class"); trap_AddCommand ("build"); trap_AddCommand ("buy"); + trap_AddCommand ("sell"); trap_AddCommand ("itemact"); trap_AddCommand ("itemdeact"); trap_AddCommand ("itemtoggle"); diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c index 58fe1d07..5884055e 100644 --- a/src/game/bg_misc.c +++ b/src/game/bg_misc.c @@ -937,7 +937,7 @@ Only in CTF games int bg_numItems = sizeof(bg_itemlist) / sizeof(bg_itemlist[0]) - 1; -/////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// buildableAttributes_t bg_buildableList[ ] = { @@ -1415,7 +1415,7 @@ int BG_FindUniqueTestForBuildable( int bclass ) return qfalse; } -/////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// classAttributes_t bg_classList[ ] = { @@ -1856,41 +1856,104 @@ int BG_FindEvolveTimeForClass( int pclass ) return 5000; } -/////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// weaponAttributes_t bg_weapons[ ] = { { WP_MACHINEGUN, - SLOT_WEAPON + 100, + SLOT_WEAPON, + "rifle", + "Rifle", + 30, + 3, + 3 }, { WP_FLAMER, - SLOT_WEAPON + 100, + SLOT_WEAPON, + "flamer", + "Flame Thrower", + 400, + 0, + 0 }, { WP_CHAINGUN, - SLOT_WEAPON + 100, + SLOT_WEAPON, + "chaingun", + "Chaingun", + 300, + 0, + 0 }, { WP_HBUILD, - SLOT_WEAPON + 100, + SLOT_WEAPON, + "ckit", + "Construction Kit", + 0, + 0, + 0 }, { WP_ABUILD, - SLOT_WEAPON + 100, + SLOT_WEAPON, + "dbuild", + "", + 0, + 0, + 0 }, { WP_SCANNER, - SLOT_WEAPON + 100, + SLOT_WEAPON, + "scanner", + "Scanner", + 0, + 0, + 0 } }; +int bg_numWeapons = sizeof( bg_weapons ) / sizeof( bg_weapons[ 0 ] ); + +/* +============== +BG_FindPriceForWeapon +============== +*/ +int BG_FindPriceForWeapon( int weapon ) +{ + int i; + + for( i = 0; i < bg_numWeapons; i++ ) + { + if( bg_weapons[ i ].weaponNum == weapon ) + { + return bg_weapons[ i ].price; + } + } + + return 100; +} + +/* +============== +BG_FindSlotsForWeapon +============== +*/ int BG_FindSlotsForWeapon( int weapon ) { int i; - for( i = WP_NONE + 1; i < WP_NUM_WEAPONS; i++ ) + for( i = 0; i < bg_numWeapons; i++ ) { if( bg_weapons[ i ].weaponNum == weapon ) { @@ -1901,61 +1964,204 @@ int BG_FindSlotsForWeapon( int weapon ) return SLOT_WEAPON; } -/////////////////////////////////////////////////////////////////////////////////////////// +/* +============== +BG_FindNameForWeapon +============== +*/ +char *BG_FindNameForWeapon( int weapon ) +{ + int i; + + for( i = 0; i < bg_numWeapons; i++ ) + { + if( bg_weapons[ i ].weaponNum == weapon ) + return bg_weapons[ i ].weaponName; + } + + //wimp out + return ""; +} + +/* +============== +BG_FindWeaponNumForName +============== +*/ +int BG_FindWeaponNumForName( char *name ) +{ + int i; + + for( i = 0; i < bg_numWeapons; i++ ) + { + if( !Q_stricmp( bg_weapons[ i ].weaponName, name ) ) + return bg_weapons[ i ].weaponNum; + } + + //wimp out + return WP_NONE; +} + +/* +============== +BG_FindHumanNameForWeapon +============== +*/ +char *BG_FindHumanNameForWeapon( int weapon ) +{ + int i; + + for( i = 0; i < bg_numWeapons; i++ ) + { + if( bg_weapons[ i ].weaponNum == weapon ) + return bg_weapons[ i ].weaponHumanName; + } + + //wimp out + return ""; +} + +/* +============== +BG_FindAmmoForWeapon +============== +*/ +void BG_FindAmmoForWeapon( int weapon, int *quan, int *clips, int *maxClips ) +{ + int i; + + for( i = 0; i < bg_numWeapons; i++ ) + { + if( bg_weapons[ i ].weaponNum == weapon ) + { + if( quan != NULL ) + *quan = bg_weapons[ i ].quan; + if( clips != NULL ) + *clips = bg_weapons[ i ].clips; + if( maxClips != NULL ) + *maxClips = bg_weapons[ i ].maxClips; + + //no need to keep going + break; + } + } +} + +//////////////////////////////////////////////////////////////////////////////// upgradeAttributes_t bg_upgrades[ ] = { { UP_TORCH, - SLOT_NONE + 100, + SLOT_NONE, + "torch", + "Torch" }, { UP_NVG, - SLOT_HEAD + 100, + SLOT_HEAD, + "nvg", + "nvg" }, { UP_CHESTARMOUR, - SLOT_TORSO + 100, + SLOT_TORSO, + "carmour", + "Chest Armour" }, { UP_LIMBARMOUR, - SLOT_ARMS|SLOT_LEGS + 100, + SLOT_ARMS|SLOT_LEGS, + "larmour", + "Limb Armour" }, { UP_HELMET, - SLOT_HEAD + 100, + SLOT_HEAD, + "helmet", + "Helmet" }, { UP_ANTITOXIN, - SLOT_NONE + 100, + SLOT_NONE, + "atoxin", + "Anti-toxin" }, { UP_BATTPACK, - SLOT_BACKPACK + 100, + SLOT_BACKPACK, + "battpack", + "Battery Pack" }, { UP_JETPACK, - SLOT_BACKPACK + 100, + SLOT_BACKPACK, + "jetpack", + "Jet Pack" }, { UP_THREATHELMET, - SLOT_HEAD + 100, + SLOT_HEAD, + "thelmet", + "Threat Helmet" }, { UP_BATTLESUIT, - SLOT_HEAD|SLOT_TORSO|SLOT_ARMS|SLOT_LEGS + 100, + SLOT_HEAD|SLOT_TORSO|SLOT_ARMS|SLOT_LEGS, + "bsuit", + "Battlesuit" }, { UP_IMPANTKIT, - SLOT_HEAD|SLOT_TORSO|SLOT_ARMS|SLOT_LEGS + 100, + SLOT_HEAD|SLOT_TORSO|SLOT_ARMS|SLOT_LEGS, + "ikit", + "Implant Kit" } }; +int bg_numUpgrades = sizeof( bg_upgrades ) / sizeof( bg_upgrades[ 0 ] ); + +/* +============== +BG_FindPriceForUpgrade +============== +*/ +int BG_FindPriceForUpgrade( int upgrade ) +{ + int i; + + for( i = 0; i < bg_numUpgrades; i++ ) + { + if( bg_upgrades[ i ].upgradeNum == upgrade ) + { + return bg_upgrades[ i ].price; + } + } + + return 100; +} + +/* +============== +BG_FindSlotsForUpgrade +============== +*/ int BG_FindSlotsForUpgrade( int upgrade ) { int i; - for( i = UP_NONE + 1; i < UP_NUM_UPGRADES; i++ ) + for( i = 0; i < bg_numUpgrades; i++ ) { if( bg_upgrades[ i ].upgradeNum == upgrade ) { @@ -1966,7 +2172,64 @@ int BG_FindSlotsForUpgrade( int upgrade ) return SLOT_NONE; } -/////////////////////////////////////////////////////////////////////////////////////////// +/* +============== +BG_FindNameForUpgrade +============== +*/ +char *BG_FindNameForUpgrade( int upgrade ) +{ + int i; + + for( i = 0; i < bg_numUpgrades; i++ ) + { + if( bg_upgrades[ i ].upgradeNum == upgrade ) + return bg_upgrades[ i ].upgradeName; + } + + //wimp out + return ""; +} + +/* +============== +BG_FindUpgradeNumForName +============== +*/ +int BG_FindUpgradeNumForName( char *name ) +{ + int i; + + for( i = 0; i < bg_numUpgrades; i++ ) + { + if( !Q_stricmp( bg_upgrades[ i ].upgradeName, name ) ) + return bg_upgrades[ i ].upgradeNum; + } + + //wimp out + return UP_NONE; +} + +/* +============== +BG_FindHumanNameForUpgrade +============== +*/ +char *BG_FindHumanNameForUpgrade( int upgrade ) +{ + int i; + + for( i = 0; i < bg_numUpgrades; i++ ) + { + if( bg_upgrades[ i ].upgradeNum == upgrade ) + return bg_upgrades[ i ].upgradeHumanName; + } + + //wimp out + return ""; +} + +//////////////////////////////////////////////////////////////////////////////// /* ============== @@ -2715,7 +2978,26 @@ void BG_packWeapon( int weapon, int stats[ ] ) stats[ STAT_WEAPONS ] = weaponList & 0x0000FFFF; stats[ STAT_WEAPONS2 ] = ( weaponList & 0xFFFF0000 ) >> 16; + + if( stats[ STAT_SLOTS ] & BG_FindSlotsForWeapon( weapon ) ) + Com_Printf( S_COLOR_YELLOW "WARNING: Held items conflict with weapon %d\n", weapon ); + + stats[ STAT_SLOTS ] |= BG_FindSlotsForWeapon( weapon ); +} + +//TA: remove weapons from the array +void BG_removeWeapon( int weapon, int stats[ ] ) +{ + int weaponList, i; + + weaponList = ( stats[ STAT_WEAPONS ] & 0x0000FFFF ) | ( ( stats[ STAT_WEAPONS2 ] << 16 ) & 0xFFFF0000 ); + + weaponList &= ~( 1 << weapon ); + + stats[ STAT_WEAPONS ] = weaponList & 0x0000FFFF; + stats[ STAT_WEAPONS2 ] = ( weaponList & 0xFFFF0000 ) >> 16; + stats[ STAT_SLOTS ] &= ~BG_FindSlotsForWeapon( weapon ); } //TA: check whether array contains weapon @@ -2732,12 +3014,19 @@ qboolean BG_gotWeapon( int weapon, int stats[ ] ) void BG_packItem( int item, int stats[ ] ) { stats[ STAT_ITEMS ] |= ( 1 << item ); + + if( stats[ STAT_SLOTS ] & BG_FindSlotsForUpgrade( item ) ) + Com_Printf( S_COLOR_YELLOW "WARNING: Held items conflict with upgrade %d\n", item ); + + stats[ STAT_SLOTS ] |= BG_FindSlotsForUpgrade( item ); } //TA: remove items from array void BG_removeItem( int item, int stats[ ] ) { stats[ STAT_ITEMS ] &= ~( 1 << item ); + + stats[ STAT_SLOTS ] &= ~BG_FindSlotsForUpgrade( item ); } //TA: check if item is in array diff --git a/src/game/bg_public.h b/src/game/bg_public.h index b79f1c0d..cd01d87f 100644 --- a/src/game/bg_public.h +++ b/src/game/bg_public.h @@ -809,7 +809,16 @@ typedef struct { int weaponNum; + int price; + int slots; + + char *weaponName; + char *weaponHumanName; + + int quan; + int clips; + int maxClips; } weaponAttributes_t; //TA: upgrade record @@ -817,7 +826,12 @@ typedef struct { int upgradeNum; + int price; + int slots; + + char *upgradeName; + char *upgradeHumanName; } upgradeAttributes_t; // included in both the game dll and the client @@ -864,6 +878,20 @@ int BG_FindSteptimeForClass( int pclass ); qboolean BG_ClassHasAbility( int pclass, int ability ); qboolean BG_ClassCanEvolveFromTo( int fclass, int tclass ); int BG_FindEvolveTimeForClass( int pclass ); + +int BG_FindPriceForWeapon( int weapon ); +int BG_FindSlotsForWeapon( int weapon ); +char *BG_FindNameForWeapon( int weapon ); +int BG_FindWeaponNumForName( char *name ); +char *BG_FindHumanNameForWeapon( int weapon ); +void BG_FindAmmoForWeapon( int weapon, int *quan, int *clips, int *maxClips ); + +int BG_FindPriceForUpgrade( int upgrade ); +int BG_FindSlotsForUpgrade( int upgrade ); +char *BG_FindNameForUpgrade( int upgrade ); +int BG_FindUpgradeNumForName( char *name ); +char *BG_FindHumanNameForUpgrade( int upgrade ); + #define ITEM_INDEX(x) ((x)-bg_itemlist) qboolean BG_CanItemBeGrabbed( int gametype, const entityState_t *ent, const playerState_t *ps ); diff --git a/src/game/g_client.c b/src/game/g_client.c index 15a42ba5..e81a3ab2 100644 --- a/src/game/g_client.c +++ b/src/game/g_client.c @@ -1305,6 +1305,7 @@ void ClientSpawn( gentity_t *ent, gentity_t *spawn ) { client->ps.stats[ STAT_WEAPONS ] = 0; client->ps.stats[ STAT_WEAPONS2 ] = 0; + client->ps.stats[ STAT_SLOTS ] = 0; client->ps.eFlags = flags; client->ps.clientNum = index; @@ -1350,11 +1351,6 @@ void ClientSpawn( gentity_t *ent, gentity_t *spawn ) { default: BG_packWeapon( WP_MACHINEGUN, client->ps.stats ); BG_packAmmoArray( WP_MACHINEGUN, client->ps.ammo, client->ps.powerups, 100, 0, 0 ); - - BG_packWeapon( WP_GAUNTLET, client->ps.stats ); - BG_packAmmoArray( WP_GAUNTLET, client->ps.ammo, client->ps.powerups, 0, 0, 0 ); - - BG_packAmmoArray( WP_GRAPPLING_HOOK, client->ps.ammo, client->ps.powerups, 0, 0, 0 ); } ent->client->ps.stats[ STAT_PCLASS ] = ent->client->pers.pclass; diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index b97dcefb..5372f037 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -1820,6 +1820,8 @@ void Cmd_Buy_f( gentity_t *ent ) int i; gentity_t *mcuEntity; qboolean nearMCU = qfalse; + int weapon, upgrade; + int quan, clips, maxClips; trap_Argv( 1, s, sizeof( s ) ); @@ -1842,57 +1844,85 @@ void Cmd_Buy_f( gentity_t *ent ) if( ent->client->pers.pteam != PTE_HUMANS ) return; + weapon = BG_FindWeaponNumForName( s ); + upgrade = BG_FindUpgradeNumForName( s ); - if( !Q_stricmp( s, "rifle" ) ) + if( weapon != WP_NONE ) { - BG_packWeapon( WP_MACHINEGUN, ent->client->ps.stats ); - BG_packAmmoArray( WP_MACHINEGUN, ent->client->ps.ammo, ent->client->ps.powerups, CS_MG, 3, 3 ); - ent->client->ps.weapon = WP_MACHINEGUN; + BG_packWeapon( weapon, ent->client->ps.stats ); + BG_FindAmmoForWeapon( weapon, &quan, &clips, &maxClips ); + BG_packAmmoArray( weapon, ent->client->ps.ammo, ent->client->ps.powerups, + quan, clips, maxClips ); + ent->client->ps.weapon = weapon; } - else if( !Q_stricmp( s, "chaingun" ) ) + else if( upgrade != UP_NONE ) { - BG_packWeapon( WP_CHAINGUN, ent->client->ps.stats ); - BG_packAmmoArray( WP_CHAINGUN, ent->client->ps.ammo, ent->client->ps.powerups, CS_CG, 0, 0 ); - ent->client->ps.weapon = WP_CHAINGUN; + BG_packItem( upgrade, ent->client->ps.stats ); } - else if( !Q_stricmp( s, "scanner" ) ) - { - BG_packWeapon( WP_SCANNER, ent->client->ps.stats ); - BG_packAmmoArray( WP_SCANNER, ent->client->ps.ammo, ent->client->ps.powerups, 0, 0, 0 ); - ent->client->ps.weapon = WP_SCANNER; - } - else if( !Q_stricmp( s, "flamer" ) ) + else { - BG_packWeapon( WP_FLAMER, ent->client->ps.stats ); - BG_packAmmoArray( WP_FLAMER, ent->client->ps.ammo, ent->client->ps.powerups, CS_FLAMER, 0, 0 ); - ent->client->ps.weapon = WP_FLAMER; + trap_SendServerCommand( ent-g_entities, va("print \"Unknown item\n\"" ) ); } - else if( !Q_stricmp( s, "ckit" ) ) + + //subtract from funds +} + + +/* +================= +Cmd_Sell_f +================= +*/ +void Cmd_Sell_f( gentity_t *ent ) +{ + char s[ MAX_TOKEN_CHARS ]; + vec3_t distance; + int i; + gentity_t *mcuEntity; + qboolean nearMCU = qfalse; + int weapon, upgrade; + int quan, clips, maxClips; + + trap_Argv( 1, s, sizeof( s ) ); + + for ( i = 1, mcuEntity = g_entities + i; i < level.num_entities; i++, mcuEntity++ ) { - BG_packWeapon( WP_HBUILD, ent->client->ps.stats ); - BG_packAmmoArray( WP_HBUILD, ent->client->ps.ammo, ent->client->ps.powerups, 0, 0, 0 ); - ent->client->ps.weapon = WP_HBUILD; + if( !Q_stricmp( mcuEntity->classname, "team_human_mcu" ) ) + { + VectorSubtract( ent->s.pos.trBase, mcuEntity->s.origin, distance ); + if( VectorLength( distance ) <= 100 ) + nearMCU = qtrue; + } } - else if( !Q_stricmp( s, "ggrenade" ) ) + + if( !nearMCU ) { - BG_packWeapon( WP_GGRENADE, ent->client->ps.stats ); - BG_packAmmoArray( WP_GGRENADE, ent->client->ps.ammo, ent->client->ps.powerups, 1, 0, 0 ); - ent->client->ps.weapon = WP_GGRENADE; + trap_SendServerCommand( ent-g_entities, va("print \"You must be near an MCU\n\"" ) ); + return; } - else if( !Q_stricmp( s, "carmour" ) ) + + if( ent->client->pers.pteam != PTE_HUMANS ) + return; + + weapon = BG_FindWeaponNumForName( s ); + upgrade = BG_FindUpgradeNumForName( s ); + + if( weapon != WP_NONE ) { - BG_packItem( UP_CHESTARMOUR, ent->client->ps.stats ); + if( BG_gotWeapon( weapon, ent->client->ps.stats ) ) + BG_removeWeapon( weapon, ent->client->ps.stats ); } - else if( !Q_stricmp( s, "nvg" ) ) + else if( upgrade != UP_NONE ) { - BG_packItem( UP_NVG, ent->client->ps.stats ); + if( BG_gotItem( weapon, ent->client->ps.stats ) ) + BG_removeItem( upgrade, ent->client->ps.stats ); } - else if( !Q_stricmp( s, "torch" ) ) + else { - BG_packItem( UP_TORCH, ent->client->ps.stats ); + trap_SendServerCommand( ent-g_entities, va("print \"Unknown item\n\"" ) ); } - - //subtract from funds + + //add to funds } @@ -2126,6 +2156,8 @@ void ClientCommand( int clientNum ) { Cmd_Build_f( ent ); else if (Q_stricmp (cmd, "buy") == 0) Cmd_Buy_f( ent ); + else if (Q_stricmp (cmd, "sell") == 0) + Cmd_Sell_f( ent ); else if (Q_stricmp (cmd, "itemact") == 0) Cmd_ActivateItem_f( ent ); else if (Q_stricmp (cmd, "itemdeact") == 0) |