summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cgame/cg_ents.c44
-rw-r--r--src/cgame/cg_local.h2
-rw-r--r--src/game/bg_misc.c105
-rw-r--r--src/game/bg_public.h3
-rw-r--r--src/game/g_weapon.c17
-rw-r--r--src/qcommon/q_shared.h2
6 files changed, 130 insertions, 43 deletions
diff --git a/src/cgame/cg_ents.c b/src/cgame/cg_ents.c
index 1cdcfde7..f2c4d8a0 100644
--- a/src/cgame/cg_ents.c
+++ b/src/cgame/cg_ents.c
@@ -809,41 +809,25 @@ static void CG_Lev2ZapChain( centity_t *cent )
{
int i;
entityState_t *es;
- centity_t *source = NULL, *target = NULL;
+ centity_t *source = NULL, *target = NULL, *attacker = NULL;
+ int targets[ LEVEL2_AREAZAP_MAX_TARGETS + 1 ];
es = &cent->currentState;
- //FIXME: find a better way to send zap targets
- for( i = 0; i <= 2; i++ )
- {
- switch( i )
- {
- case 0:
- if( es->time <= 0 )
- continue;
-
- source = &cg_entities[ es->misc ];
- target = &cg_entities[ es->time ];
- break;
-
- case 1:
- if( es->time2 <= 0 )
- continue;
-
- source = &cg_entities[ es->time ];
- target = &cg_entities[ es->time2 ];
- break;
+ BG_UnpackZapTargets( es, targets, LEVEL2_AREAZAP_MAX_TARGETS + 1 );
+ attacker = &cg_entities[ targets[ 0 ] ];
- case 2:
- if( es->constantLight <= 0 )
- continue;
-
- source = &cg_entities[ es->time ];
- target = &cg_entities[ es->constantLight ];
- break;
+ for( i = 1; i < LEVEL2_AREAZAP_MAX_TARGETS + 1; i++ )
+ {
+ if( i == 1 )
+ source = attacker;
+ else
+ source = &cg_entities[ targets[ 1 ] ];
- }
+ if( targets[ i ] == ENTITYNUM_NONE )
+ continue;
+ target = &cg_entities[ targets[ i ] ];
if( !CG_IsTrailSystemValid( &cent->level2ZapTS[ i ] ) )
cent->level2ZapTS[ i ] = CG_SpawnNewTrailSystem( cgs.media.level2ZapTS );
@@ -1061,7 +1045,7 @@ static void CG_CEntityPVSLeave( centity_t *cent )
switch( es->eType )
{
case ET_LEV2_ZAP_CHAIN:
- for( i = 0; i <= 2; i++ )
+ for( i = 0; i <= LEVEL2_AREAZAP_MAX_TARGETS; i++ )
{
if( CG_IsTrailSystemValid( &cent->level2ZapTS[ i ] ) )
CG_DestroyTrailSystem( &cent->level2ZapTS[ i ] );
diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h
index 89e86935..be2d8cbd 100644
--- a/src/cgame/cg_local.h
+++ b/src/cgame/cg_local.h
@@ -674,7 +674,7 @@ typedef struct centity_s
particleSystem_t *entityPS;
qboolean entityPSMissing;
- trailSystem_t *level2ZapTS[ 3 ];
+ trailSystem_t *level2ZapTS[ LEVEL2_AREAZAP_MAX_TARGETS ];
int level2ZapTime;
trailSystem_t *muzzleTS; //used for the tesla and reactor
diff --git a/src/game/bg_misc.c b/src/game/bg_misc.c
index 8ce10291..d969fea1 100644
--- a/src/game/bg_misc.c
+++ b/src/game/bg_misc.c
@@ -3464,6 +3464,111 @@ int atoi_neg( char *token, qboolean allowNegative )
/*
===============
+BG_PackZapTargets
+
+pack up to 12 entityNums into an entityState_t
+===============
+*/
+void BG_PackZapTargets( entityState_t *es, int *entityNums, int count )
+{
+ int i;
+ es->misc = es->time = es->time2 = es->constantLight = 0;
+ for( i = 0; i < MAX_GENTITYNUM_PACK; i++ )
+ {
+ int entityNum = ENTITYNUM_NONE;
+ if( i < count )
+ entityNum = entityNums[i];
+ if( entityNum & ~(GENTITYNUM_MASK) )
+ {
+ Com_Printf("Warning: BG_PackZapTargets: entityNums[%d] (%d) doesn't fit in %d bits, using ENTITYNUM_NONE",
+ i, entityNums[i], GENTITYNUM_BITS);
+ entityNum = ENTITYNUM_NONE;
+ }
+ 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);
+ }
+ }
+}
+
+/*
+===============
+BG_UnpackZapTargets
+
+unpacks the 12 entityNums in an entityState_t
+===============
+*/
+void BG_UnpackZapTargets( entityState_t *es, int *entityNums, int count )
+{
+ int i;
+ for( i = 0; i < count; i++ )
+ {
+ switch( i )
+ {
+ case 0:
+ entityNums[i] = es->misc & GENTITYNUM_MASK;
+ break;
+ case 1:
+ entityNums[i] = es->time & GENTITYNUM_MASK;
+ break;
+ case 2:
+ entityNums[i] = (es->time >> GENTITYNUM_BITS) & GENTITYNUM_MASK;
+ break;
+ case 3:
+ entityNums[i] = (es->time >> (GENTITYNUM_BITS * 2)) & GENTITYNUM_MASK;
+ break;
+ case 4:
+ entityNums[i] = es->time2 & GENTITYNUM_MASK;
+ break;
+ case 5:
+ entityNums[i] = (es->time2 >> GENTITYNUM_BITS) & GENTITYNUM_MASK;
+ break;
+ case 6:
+ entityNums[i] = (es->time2 >> (GENTITYNUM_BITS * 2)) & GENTITYNUM_MASK;
+ break;
+ case 7:
+ entityNums[i] = es->constantLight & GENTITYNUM_MASK;
+ break;
+ case 8:
+ entityNums[i] = (es->constantLight >> GENTITYNUM_BITS) & GENTITYNUM_MASK;
+ break;
+ case 9:
+ entityNums[i] = (es->constantLight >> (GENTITYNUM_BITS * 2)) & GENTITYNUM_MASK;
+ break;
+ }
+ }
+}
+
+/*
+===============
BG_ParseCSVEquipmentList
===============
*/
diff --git a/src/game/bg_public.h b/src/game/bg_public.h
index 57803a24..2ec0435d 100644
--- a/src/game/bg_public.h
+++ b/src/game/bg_public.h
@@ -1114,6 +1114,9 @@ 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 *entityNums, int count );
+void BG_UnpackZapTargets( entityState_t *es, int *entityNums, int count );
+
const buildableAttributes_t *BG_BuildableByName( const char *name );
const buildableAttributes_t *BG_BuildableByEntityName( const char *name );
const buildableAttributes_t *BG_Buildable( buildable_t buildable );
diff --git a/src/game/g_weapon.c b/src/game/g_weapon.c
index 1c58e212..a9849572 100644
--- a/src/game/g_weapon.c
+++ b/src/game/g_weapon.c
@@ -1149,7 +1149,7 @@ static gentity_t *G_FindNewZapTarget( gentity_t *ent )
}
}
- return NULL;
+ return &g_entities[ ENTITYNUM_NONE ];
}
/*
@@ -1161,27 +1161,20 @@ static void G_UpdateZapEffect( zap_t *zap )
{
int j;
gentity_t *effect = zap->effectChannel;
+ int targets[MAX_ZAP_TARGETS + 1];
effect->s.eType = ET_LEV2_ZAP_CHAIN;
effect->classname = "lev2zapchain";
G_SetOrigin( effect, zap->creator->s.origin );
- effect->s.misc = zap->creator->s.number;
-
- effect->s.time = effect->s.time2 = effect->s.constantLight = -1;
+ targets[ 0 ] = zap->creator->s.number;
for( j = 0; j < zap->numTargets; j++ )
{
int number = zap->targets[ j ]->s.number;
-
- switch( j )
- {
- case 0: effect->s.time = number; break;
- case 1: effect->s.time2 = number; break;
- case 2: effect->s.constantLight = number; break;
- default: break;
- }
+ targets[ j + 1 ] = number;
}
+ BG_PackZapTargets( &effect->s, targets, zap->numTargets );
trap_LinkEntity( effect );
}
diff --git a/src/qcommon/q_shared.h b/src/qcommon/q_shared.h
index c24fe292..5b5daee8 100644
--- a/src/qcommon/q_shared.h
+++ b/src/qcommon/q_shared.h
@@ -1006,6 +1006,8 @@ 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