diff options
author | Tim Angus <tim@ngus.net> | 2002-03-25 08:22:28 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2002-03-25 08:22:28 +0000 |
commit | 01bc051a77b93e00bb574f24972dcb6299e51d39 (patch) | |
tree | 0cfbb85cca7ed55762afebcbbc40303bc2c03e9d | |
parent | d757d93062f131d4670cc50f99a228865194a0f2 (diff) |
Ammo upgrade packages
-rw-r--r-- | src/game/bg_misc.c | 78 | ||||
-rw-r--r-- | src/game/bg_public.h | 8 | ||||
-rw-r--r-- | src/game/g_cmds.c | 61 |
3 files changed, 133 insertions, 14 deletions
diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c index 6a3da36d..a241f3dc 100644 --- a/src/game/bg_misc.c +++ b/src/game/bg_misc.c @@ -2737,6 +2737,9 @@ upgradeAttributes_t bg_upgrades[ ] = "torch", //char *upgradeName; "Torch", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2747,6 +2750,9 @@ upgradeAttributes_t bg_upgrades[ ] = "nvg", //char *upgradeName; "NVG", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2757,6 +2763,9 @@ upgradeAttributes_t bg_upgrades[ ] = "carmour", //char *upgradeName; "Chest Armour", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2767,6 +2776,9 @@ upgradeAttributes_t bg_upgrades[ ] = "larmour", //char *upgradeName; "Limb Armour", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2777,6 +2789,9 @@ upgradeAttributes_t bg_upgrades[ ] = "helmet", //char *upgradeName; "Helmet", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2787,6 +2802,9 @@ upgradeAttributes_t bg_upgrades[ ] = "atoxin", //char *upgradeName; "Anti-toxin", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2797,6 +2815,9 @@ upgradeAttributes_t bg_upgrades[ ] = "battpack", //char *upgradeName; "Battery Pack", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2807,6 +2828,9 @@ upgradeAttributes_t bg_upgrades[ ] = "jetpack", //char *upgradeName; "Jet Pack", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; WUT_HUMANS //WUTeam_t team; }, { @@ -2817,6 +2841,22 @@ upgradeAttributes_t bg_upgrades[ ] = "bsuit", //char *upgradeName; "Battlesuit", //char *upgradeHumanName; "icons/iconw_gauntlet", + WP_NONE, //weapon_t weaponAmmo; + 0, //int ammo; + 0, //int clips; + WUT_HUMANS //WUTeam_t team; + }, + { + UP_MGCLIP, //int upgradeNum; + 10, //int price; + ( 1 << S1 )|( 1 << S2 )|( 1 << S3 ), //int stages + SLOT_NONE, //int slots; + "mgclip", //char *upgradeName; + "1 Rifle Clip", //char *upgradeHumanName; + "icons/iconw_gauntlet", + WP_MACHINEGUN, //weapon_t weaponAmmo; + 0, //int ammo; + 1, //int clips; WUT_HUMANS //WUTeam_t team; } }; @@ -2964,6 +3004,44 @@ char *BG_FindIconForUpgrade( int upgrade ) /* ============== +BG_FindWeaponAmmoForUpgrade +============== +*/ +weapon_t BG_FindWeaponAmmoForUpgrade( int upgrade ) +{ + int i; + + for( i = 0; i < bg_numUpgrades; i++ ) + { + if( bg_upgrades[ i ].upgradeNum == upgrade ) + return bg_upgrades[ i ].weaponAmmo; + } +} + +/* +============== +BG_FindAmmoForUpgrade +============== +*/ +void BG_FindAmmoForUpgrade( int upgrade, int *ammo, int *clips ) +{ + int i; + + for( i = 0; i < bg_numUpgrades; i++ ) + { + if( bg_upgrades[ i ].upgradeNum == upgrade ) + { + if( ammo != NULL ) + *ammo = bg_upgrades[ i ].ammo; + + if( clips != NULL ) + *clips = bg_upgrades[ i ].clips; + } + } +} + +/* +============== BG_FindTeamForUpgrade ============== */ diff --git a/src/game/bg_public.h b/src/game/bg_public.h index 08ab9cea..553cea05 100644 --- a/src/game/bg_public.h +++ b/src/game/bg_public.h @@ -364,6 +364,8 @@ typedef enum UP_BATTPACK, UP_JETPACK, UP_BATTLESUIT, + + UP_MGCLIP, UP_NUM_UPGRADES } upgrade_t; @@ -970,6 +972,10 @@ typedef struct char *icon; + weapon_t weaponAmmo; + int ammo; + int clips; + WUTeam_t team; } upgradeAttributes_t; @@ -1051,6 +1057,8 @@ char *BG_FindNameForUpgrade( int upgrade ); int BG_FindUpgradeNumForName( char *name ); char *BG_FindHumanNameForUpgrade( int upgrade ); char *BG_FindIconForUpgrade( int upgrade ); +weapon_t BG_FindWeaponAmmoForBuildable( int upgrade ); +void BG_FindAmmoForUpgrade( int upgrade, int *ammo, int *clips ); WUTeam_t BG_FindTeamForUpgrade( int upgrade ); // g_dmflags->integer flags diff --git a/src/game/g_cmds.c b/src/game/g_cmds.c index c8e26489..9cadf288 100644 --- a/src/game/g_cmds.c +++ b/src/game/g_cmds.c @@ -1939,6 +1939,9 @@ void Cmd_Buy_f( gentity_t *ent ) } else if( upgrade != UP_NONE ) { + int maxAmmo, newAmmo, newClips; + weapon_t weaponAmmo; + //already got this? if( BG_gotItem( upgrade, ent->client->ps.stats ) ) { @@ -1974,8 +1977,41 @@ void Cmd_Buy_f( gentity_t *ent ) return; } - //add to inventory - BG_packItem( upgrade, ent->client->ps.stats ); + BG_FindAmmoForUpgrade( upgrade, &newAmmo, &newClips ); + + if( newAmmo || newClips ) + { + //get current ammo for the weapon in question + weaponAmmo = BG_FindWeaponAmmoForUpgrade( upgrade ); + BG_unpackAmmoArray( weaponAmmo, ent->client->ps.ammo, ent->client->ps.powerups, + &quan, &clips, &maxClips ); + + BG_FindAmmoForWeapon( weaponAmmo, &maxAmmo, NULL, NULL ); + + //this ammo package would exceed max ammo + if( clips + newClips > maxClips ) + { + //FIXME: different dialog? + G_AddPredictableEvent( ent, EV_MENU, MN_H_NOSLOTS ); + return; + } + else + clips += newClips; + + if( quan + newAmmo > maxAmmo ) + quan = maxAmmo; + else + quan += newAmmo; + + //updata ammo count + BG_packAmmoArray( weaponAmmo, ent->client->ps.ammo, ent->client->ps.powerups, + quan, clips, maxClips ); + } + else + { + //add to inventory + BG_packItem( upgrade, ent->client->ps.stats ); + } //subtract from funds ent->client->ps.persistant[ PERS_CREDIT ] -= BG_FindPriceForUpgrade( upgrade ); @@ -2385,18 +2421,15 @@ void Cmd_Spawnbody_f( gentity_t *ent ) G_FreeEntity( dummy ); } -/*void Cmd_Test_f( gentity_t *ent ) +void Cmd_Test_f( gentity_t *ent ) { - char s[ MAX_TOKEN_CHARS ]; - int a, b, c; + int ammo, clips, maxclips; + playerState_t *ps = &ent->client->ps; - trap_Argv( 1, s, sizeof( s ) ); - a = atoi( s ); - trap_Argv( 2, s, sizeof( s ) ); - b = atoi( s ); - - G_Printf( "%d\n", BG_ClassCanEvolveFromTo( a, b, 10000, 0 ) ); -}*/ + BG_unpackAmmoArray( WP_MACHINEGUN, ps->ammo, ps->powerups, &ammo, &clips, &maxclips ); + G_Printf( "%d %d\n", ammo, clips ); + BG_packAmmoArray( WP_MACHINEGUN, ps->ammo, ps->powerups, 0, 1, maxclips ); +} /* ================= @@ -2531,8 +2564,8 @@ void ClientCommand( int clientNum ) { Cmd_Stats_f( ent ); else if (Q_stricmp (cmd, "spawnbody") == 0) Cmd_Spawnbody_f( ent ); -/* else if (Q_stricmp (cmd, "test") == 0) - Cmd_Test_f( ent );*/ + else if (Q_stricmp (cmd, "test") == 0) + Cmd_Test_f( ent ); else trap_SendServerCommand( clientNum, va("print \"unknown cmd %s\n\"", cmd ) ); } |