diff options
author | Tim Angus <tim@ngus.net> | 2009-10-03 12:47:32 +0000 |
---|---|---|
committer | Tim Angus <tim@ngus.net> | 2013-01-03 00:16:14 +0000 |
commit | 741ddb89552f73f13e6adba4503742bcc0065a61 (patch) | |
tree | b6a659c5f087e58a59d938d9b909e04a6cda3e4a /src | |
parent | c4fe8300adef0b3d63152c419f9411f14eb41831 (diff) |
* Replace BG_(Un)PackZapTargets with more generic and less muddled BG_(Un)PackEntityNumbers
Diffstat (limited to 'src')
-rw-r--r-- | src/cgame/cg_ents.c | 26 | ||||
-rw-r--r-- | src/game/bg_misc.c | 141 | ||||
-rw-r--r-- | src/game/bg_public.h | 4 | ||||
-rw-r--r-- | src/game/g_local.h | 4 | ||||
-rw-r--r-- | src/game/g_weapon.c | 30 | ||||
-rw-r--r-- | src/qcommon/q_shared.h | 1 |
6 files changed, 97 insertions, 109 deletions
diff --git a/src/cgame/cg_ents.c b/src/cgame/cg_ents.c index 8f872f31..eed57686 100644 --- a/src/cgame/cg_ents.c +++ b/src/cgame/cg_ents.c @@ -809,25 +809,29 @@ static void CG_Lev2ZapChain( centity_t *cent ) { int i; entityState_t *es; - centity_t *source = NULL, *target = NULL, *attacker = NULL; - int targets[ LEVEL2_AREAZAP_MAX_TARGETS ], creator; + centity_t *source = NULL, *target = NULL; + int entityNums[ LEVEL2_AREAZAP_MAX_TARGETS + 1 ]; + int count; es = ¢->currentState; - BG_UnpackZapTargets( es, &creator, targets, LEVEL2_AREAZAP_MAX_TARGETS + 1 ); - attacker = &cg_entities[ creator ]; + count = BG_UnpackEntityNumbers( es, entityNums, LEVEL2_AREAZAP_MAX_TARGETS + 1 ); - for( i = 0; i < LEVEL2_AREAZAP_MAX_TARGETS; i++ ) + for( i = 1; i < count; i++ ) { - if( i == 0 ) - source = attacker; + if( i == 1 ) + { + // First entity is the attacker + source = &cg_entities[ entityNums[ 0 ] ]; + } else - source = &cg_entities[ targets[ 0 ] ]; + { + // Subsequent zaps come from the first target + source = &cg_entities[ entityNums[ 1 ] ]; + } - if( targets[ i ] == ENTITYNUM_NONE ) - continue; + target = &cg_entities[ entityNums[ i ] ]; - target = &cg_entities[ targets[ i ] ]; if( !CG_IsTrailSystemValid( ¢->level2ZapTS[ i ] ) ) cent->level2ZapTS[ i ] = CG_SpawnNewTrailSystem( cgs.media.level2ZapTS ); diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c index 3d802878..a8f5579b 100644 --- a/src/game/bg_misc.c +++ b/src/game/bg_misc.c @@ -3461,118 +3461,101 @@ int atoi_neg( char *token, qboolean allowNegative ) return value; } +#define MAX_NUM_PACKED_ENTITY_NUMS 10 + /* =============== -BG_PackZapTargets +BG_PackEntityNumbers -pack up to 12 targets into an entityState_t +Pack entity numbers into an entityState_t =============== */ -//FIXME: magic - 1 and count makes no sense -void BG_PackZapTargets( entityState_t *es, int creator, const int *targets, int count ) +void BG_PackEntityNumbers( entityState_t *es, const int *entityNums, int count ) { int i; + + if( count > MAX_NUM_PACKED_ENTITY_NUMS ) + { + count = MAX_NUM_PACKED_ENTITY_NUMS; + Com_Printf( S_COLOR_YELLOW "WARNING: A maximum of %d entity numbers can be " + "packed, but BG_PackEntityNumbers was passed %d entities", + MAX_NUM_PACKED_ENTITY_NUMS, count ); + } + es->misc = es->time = es->time2 = es->constantLight = 0; - for( i = 0; i < MAX_GENTITYNUM_PACK; i++ ) + + for( i = 0; i < MAX_NUM_PACKED_ENTITY_NUMS; i++ ) { - int entityNum = ENTITYNUM_NONE; + int entityNum; + if( i < count ) - { - if( i == 0 ) - entityNum = creator; - else - entityNum = targets[ i - 1 ]; - } + entityNum = entityNums[ i ]; + else + entityNum = ENTITYNUM_NONE; - if( entityNum & ~(GENTITYNUM_MASK) ) + if( entityNum & ~GENTITYNUM_MASK ) { - Com_Printf("Warning: BG_PackZapTargets: targets[%d] (%d) doesn't fit in %d bits, using ENTITYNUM_NONE\n", - i, targets[i], GENTITYNUM_BITS); - entityNum = ENTITYNUM_NONE; + Com_Error( ERR_FATAL, "BG_PackEntityNumbers passed an entity number (%d) which " + "exceeds %d bits", entityNum, GENTITYNUM_BITS ); } switch( i ) { - case 0: - es->misc |= entityNum; - break; - case 1: - es->time |= entityNum; - break; - case 2: - es->time |= entityNum << GENTITYNUM_BITS; - break; - case 3: - es->time |= entityNum << (GENTITYNUM_BITS * 2); - break; - case 4: - es->time2 |= entityNum; - break; - case 5: - es->time2 |= entityNum << GENTITYNUM_BITS; - break; - case 6: - es->time2 |= entityNum << (GENTITYNUM_BITS * 2); - break; - case 7: - es->constantLight |= entityNum; - break; - case 8: - es->constantLight |= entityNum << GENTITYNUM_BITS; - break; - case 9: - es->constantLight |= entityNum << (GENTITYNUM_BITS * 2); + case 0: es->misc |= entityNum; break; + case 1: es->time |= entityNum; break; + case 2: es->time |= entityNum << GENTITYNUM_BITS; break; + case 3: es->time |= entityNum << (GENTITYNUM_BITS * 2); break; + case 4: es->time2 |= entityNum; break; + case 5: es->time2 |= entityNum << GENTITYNUM_BITS; break; + case 6: es->time2 |= entityNum << (GENTITYNUM_BITS * 2); break; + case 7: es->constantLight |= entityNum; break; + case 8: es->constantLight |= entityNum << GENTITYNUM_BITS; break; + case 9: es->constantLight |= entityNum << (GENTITYNUM_BITS * 2); break; + default: Com_Error( ERR_FATAL, "Entity index %d not handled", i ); break; } } } /* =============== -BG_UnpackZapTargets +BG_UnpackEntityNumbers -unpacks the 12 targets in an entityState_t +Unpack entity numbers from an entityState_t =============== */ -void BG_UnpackZapTargets( entityState_t *es, int *creator, int *targets, int count ) +int BG_UnpackEntityNumbers( entityState_t *es, int *entityNums, int count ) { int i; + + if( count > MAX_NUM_PACKED_ENTITY_NUMS ) + count = MAX_NUM_PACKED_ENTITY_NUMS; + for( i = 0; i < count; i++ ) { + int *entityNum = &entityNums[ i ]; + switch( i ) { - case 0: - if(creator) - *creator = es->misc & GENTITYNUM_MASK; - break; - case 1: - targets[ i - 1 ] = es->time & GENTITYNUM_MASK; - break; - case 2: - targets[ i - 1 ] = (es->time >> GENTITYNUM_BITS) & GENTITYNUM_MASK; - break; - case 3: - targets[ i - 1 ] = (es->time >> (GENTITYNUM_BITS * 2)) & GENTITYNUM_MASK; - break; - case 4: - targets[ i - 1 ] = es->time2 & GENTITYNUM_MASK; - break; - case 5: - targets[ i - 1 ] = (es->time2 >> GENTITYNUM_BITS) & GENTITYNUM_MASK; - break; - case 6: - targets[ i - 1 ] = (es->time2 >> (GENTITYNUM_BITS * 2)) & GENTITYNUM_MASK; - break; - case 7: - targets[ i - 1 ] = es->constantLight & GENTITYNUM_MASK; - break; - case 8: - targets[ i - 1 ] = (es->constantLight >> GENTITYNUM_BITS) & GENTITYNUM_MASK; - break; - case 9: - targets[ i - 1 ] = (es->constantLight >> (GENTITYNUM_BITS * 2)) & GENTITYNUM_MASK; - break; + case 0: *entityNum = es->misc; break; + case 1: *entityNum = es->time; break; + case 2: *entityNum = (es->time >> GENTITYNUM_BITS); break; + case 3: *entityNum = (es->time >> (GENTITYNUM_BITS * 2)); break; + case 4: *entityNum = es->time2; break; + case 5: *entityNum = (es->time2 >> GENTITYNUM_BITS); break; + case 6: *entityNum = (es->time2 >> (GENTITYNUM_BITS * 2)); break; + case 7: *entityNum = es->constantLight; break; + case 8: *entityNum = (es->constantLight >> GENTITYNUM_BITS); break; + case 9: *entityNum = (es->constantLight >> (GENTITYNUM_BITS * 2)); break; + default: Com_Error( ERR_FATAL, "Entity index %d not handled", i ); break; } + + *entityNum &= GENTITYNUM_MASK; + + if( *entityNum == ENTITYNUM_NONE ) + break; } + + return i; } /* diff --git a/src/game/bg_public.h b/src/game/bg_public.h index d978127a..6a4bc1c8 100644 --- a/src/game/bg_public.h +++ b/src/game/bg_public.h @@ -1117,8 +1117,8 @@ int BG_PlayerPoisonCloudTime( playerState_t *ps ); weapon_t BG_GetPlayerWeapon( playerState_t *ps ); qboolean BG_HasEnergyWeapon( playerState_t *ps ); -void BG_PackZapTargets( entityState_t *es, int creator, const int *entityNums, int count ); -void BG_UnpackZapTargets( entityState_t *es, int *creator, int *entityNums, int count ); +void BG_PackEntityNumbers( entityState_t *es, const int *entityNums, int count ); +int BG_UnpackEntityNumbers( entityState_t *es, int *entityNums, int count ); const buildableAttributes_t *BG_BuildableByName( const char *name ); const buildableAttributes_t *BG_BuildableByEntityName( const char *name ); diff --git a/src/game/g_local.h b/src/game/g_local.h index d9eca24a..08a13ca9 100644 --- a/src/game/g_local.h +++ b/src/game/g_local.h @@ -864,14 +864,12 @@ void ShineTorch( gentity_t *self ); // g_weapon.c // -#define MAX_ZAP_TARGETS LEVEL2_AREAZAP_MAX_TARGETS - typedef struct zap_s { qboolean used; gentity_t *creator; - gentity_t *targets[ MAX_ZAP_TARGETS ]; + gentity_t *targets[ LEVEL2_AREAZAP_MAX_TARGETS ]; int numTargets; int timeToLive; diff --git a/src/game/g_weapon.c b/src/game/g_weapon.c index 72bd730c..123679da 100644 --- a/src/game/g_weapon.c +++ b/src/game/g_weapon.c @@ -1156,21 +1156,22 @@ G_UpdateZapEffect */ static void G_UpdateZapEffect( zap_t *zap ) { - int j; + int i; gentity_t *effect = zap->effectChannel; - int targets[MAX_ZAP_TARGETS]; + int entityNums[ LEVEL2_AREAZAP_MAX_TARGETS + 1 ]; effect->s.eType = ET_LEV2_ZAP_CHAIN; effect->classname = "lev2zapchain"; G_SetOrigin( effect, zap->creator->s.origin ); - for( j = 0; j < zap->numTargets; j++ ) + entityNums[ 0 ] = zap->creator->s.number; + + for( i = 0; i < zap->numTargets; i++ ) { - int number = zap->targets[ j ]->s.number; - targets[ j ] = number; + entityNums[ i + 1 ] = zap->targets[ i ]->s.number; } - BG_PackZapTargets( &effect->s, zap->creator->s.number, targets, zap->numTargets); + BG_PackEntityNumbers( &effect->s, entityNums, zap->numTargets + 1 ); trap_LinkEntity( effect ); } @@ -1190,26 +1191,29 @@ static void G_CreateNewZap( gentity_t *creator, gentity_t *target ) if( !zap->used ) { + G_Damage( target, creator, creator, forward, target->s.origin, + LEVEL2_AREAZAP_DMG, DAMAGE_NO_KNOCKBACK | DAMAGE_NO_LOCDAMAGE, + MOD_LEVEL2_ZAP ); + zap->used = qtrue; zap->timeToLive = LEVEL2_AREAZAP_TIME; - zap->damageUsed = 0; zap->creator = creator; zap->targets[ 0 ] = target; zap->numTargets = 1; - G_Damage( target, creator , zap->creator, forward, target->s.origin, - LEVEL2_AREAZAP_DMG, DAMAGE_NO_KNOCKBACK | DAMAGE_NO_LOCDAMAGE, MOD_LEVEL2_ZAP ); - for( j = 1; j < MAX_ZAP_TARGETS; j++ ) + + for( j = 1; j < LEVEL2_AREAZAP_MAX_TARGETS; j++ ) { - zap->targets[ j ] = G_FindNewZapTarget( zap->targets[ 0 ] ); + zap->targets[ j ] = G_FindNewZapTarget( target ); if( zap->targets[ j ] ) { zap->numTargets++; - G_Damage( zap->targets[ j ], zap->targets[ 0 ] , zap->creator, forward, target->s.origin, - LEVEL2_AREAZAP_DMG, DAMAGE_NO_KNOCKBACK | DAMAGE_NO_LOCDAMAGE, MOD_LEVEL2_ZAP ); + G_Damage( zap->targets[ j ], target, zap->creator, forward, + target->s.origin, LEVEL2_AREAZAP_DMG, + DAMAGE_NO_KNOCKBACK | DAMAGE_NO_LOCDAMAGE, MOD_LEVEL2_ZAP ); } } diff --git a/src/qcommon/q_shared.h b/src/qcommon/q_shared.h index 81c53e4f..18b8c6d7 100644 --- a/src/qcommon/q_shared.h +++ b/src/qcommon/q_shared.h @@ -1011,7 +1011,6 @@ typedef enum { #define GENTITYNUM_BITS 10 // don't need to send any more #define MAX_GENTITIES (1<<GENTITYNUM_BITS) #define GENTITYNUM_MASK (MAX_GENTITIES - 1) -#define MAX_GENTITYNUM_PACK 10 // entitynums are communicated with GENTITY_BITS, so any reserved // values that are going to be communcated over the net need to |