summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Millwood <thebenmachine@gmail.com>2009-10-03 13:00:00 +0000
committerTim Angus <tim@ngus.net>2013-01-03 00:16:23 +0000
commite385cb197162269da855bba6c9fdce1b418b35bf (patch)
tree154ad5530b1d256071a0069328055730a7f8fffb /src
parent69b6bfc354c10e26debec2a6c468ab7cc41f886f (diff)
Make next queue time calculation more consistent
Diffstat (limited to 'src')
-rw-r--r--src/game/g_buildable.c40
-rw-r--r--src/game/g_local.h1
-rw-r--r--src/game/g_main.c24
3 files changed, 45 insertions, 20 deletions
diff --git a/src/game/g_buildable.c b/src/game/g_buildable.c
index 5d40cd15..99f27960 100644
--- a/src/game/g_buildable.c
+++ b/src/game/g_buildable.c
@@ -2627,23 +2627,35 @@ void G_QueueBuildPoints( gentity_t *self )
if( powerEntity )
{
+ int nqt;
switch( powerEntity->s.modelindex )
{
case BA_H_REACTOR:
- if( !level.humanBuildPointQueue )
- level.humanNextQueueTime = level.time + g_humanBuildQueueTime.integer;
+ nqt = G_NextQueueTime( level.humanBuildPointQueue,
+ g_humanBuildPoints.integer,
+ g_humanBuildQueueTime.integer );
+ if( !level.humanBuildPointQueue ||
+ level.time + nqt < level.humanNextQueueTime )
+ level.humanNextQueueTime = level.time + nqt;
level.humanBuildPointQueue +=
BG_Buildable( self->s.modelindex )->buildPoints;
break;
case BA_H_REPEATER:
- if( powerEntity->usesZone && level.powerZones[powerEntity->zone].active )
+ if( powerEntity->usesZone &&
+ level.powerZones[ powerEntity->zone ].active )
{
- zone_t *zone = &level.powerZones[powerEntity->zone];
+ zone_t *zone = &level.powerZones[ powerEntity->zone ];
+
+ nqt = G_NextQueueTime( zone->queuedBuildPoints,
+ zone->totalBuildPoints,
+ g_humanRepeaterBuildQueueTime.integer );
+
+ if( !zone->queuedBuildPoints ||
+ level.time + nqt < zone->nextQueueTime )
+ zone->nextQueueTime = level.time + nqt;
- if( !zone->queuedBuildPoints )
- zone->nextQueueTime = level.time + g_humanRepeaterBuildQueueTime.integer;
zone->queuedBuildPoints +=
BG_Buildable( self->s.modelindex )->buildPoints;
}
@@ -2666,6 +2678,22 @@ void G_QueueBuildPoints( gentity_t *self )
/*
============
+G_NextQueueTime
+============
+*/
+int G_NextQueueTime( int queuedBP, int totalBP, int queueBaseRate )
+{
+ float fractionQueued;
+
+ if( totalBP == 0 )
+ return 0;
+
+ fractionQueued = queuedBP / (float)totalBP;
+ return ( 1.0f - fractionQueued ) * queueBaseRate;
+}
+
+/*
+============
G_BuildableTouchTriggers
Find all trigger entities that a buildable touches.
diff --git a/src/game/g_local.h b/src/game/g_local.h
index 57406735..8e1a31d1 100644
--- a/src/game/g_local.h
+++ b/src/game/g_local.h
@@ -763,6 +763,7 @@ int G_LayoutList( const char *map, char *list, int len );
void G_LayoutSelect( void );
void G_LayoutLoad( void );
void G_BaseSelfDestruct( team_t team );
+int G_NextQueueTime( int queuedBP, int totalBP, int queueBaseRate );
void G_QueueBuildPoints( gentity_t *self );
int G_GetBuildPoints( const vec3_t pos, team_t team, int dist );
qboolean G_FindPower( gentity_t *self );
diff --git a/src/game/g_main.c b/src/game/g_main.c
index 2e2040ef..eab09ad8 100644
--- a/src/game/g_main.c
+++ b/src/game/g_main.c
@@ -1078,16 +1078,18 @@ void G_CalculateBuildPoints( void )
level.alienNextQueueTime < level.time )
{
level.alienBuildPointQueue--;
- level.alienNextQueueTime += (int)( g_alienBuildQueueTime.integer *
- ( 1.0f - ( (float)level.alienBuildPointQueue / level.alienBuildPoints ) ) );
+ level.alienNextQueueTime += G_NextQueueTime( level.alienBuildPointQueue,
+ g_alienBuildPoints.integer,
+ g_alienBuildQueueTime.integer );
}
while( level.humanBuildPointQueue > 0 &&
level.humanNextQueueTime < level.time )
{
level.humanBuildPointQueue--;
- level.humanNextQueueTime += (int)( g_humanBuildQueueTime.integer *
- ( 1.0f - ( (float)level.humanBuildPointQueue / level.humanBuildPoints ) ) );
+ level.humanNextQueueTime += G_NextQueueTime( level.humanBuildPointQueue,
+ g_humanBuildPoints.integer,
+ g_humanBuildQueueTime.integer );
}
// Sudden Death checks
@@ -1220,20 +1222,14 @@ void G_CalculateBuildPoints( void )
while( zone->queuedBuildPoints > 0 &&
zone->nextQueueTime < level.time )
{
- float queued;
-
- zone->queuedBuildPoints--;
- queued = zone->queuedBuildPoints / (float)zone->totalBuildPoints;
-
- // It is possible for queued BP to be great than total BP,
- // in which case, treat it as if the leftover BP is positive
- zone->nextQueueTime += abs( g_humanRepeaterBuildQueueTime.integer *
- ( 1 - queued ) );
+ zone->nextQueueTime += G_NextQueueTime( zone->queuedBuildPoints,
+ zone->totalBuildPoints,
+ g_humanRepeaterBuildQueueTime.integer );
}
}
else
{
- zone->totalBuildPoints = zone->queuedBuildPoints = 0;
+ zone->totalBuildPoints = zone->queuedBuildPoints = 0;
}
}
}