Permalink
Browse files

Make Dragoon barbs regenerate faster near a booster and on creep.

  • Loading branch information...
caldazar-at authored and Viech committed Nov 1, 2015
1 parent 7f1612e commit 3837d1170e082e85fab65143923bef68dc889ab7
@@ -26,3 +26,5 @@ ballDmg 110
ballSpeed 1000.0
ballRadius 75
ballRegen 12500
ballRegenCreep 8000
ballRegenBooster 4000
@@ -2174,6 +2174,129 @@ class PredictedMineEfficiencyElement : public HudElement
std::unordered_map<int, std::string> pluralSuffix;
};

class BarbsHudElement : public HudElement
{
public:
BarbsHudElement ( const Rocket::Core::String& tag ) :
HudElement ( tag, ELEMENT_ALIENS ),
numBarbs( 0 ),
maxBarbs( BG_Weapon( WP_ALEVEL3_UPG )->maxAmmo ),
regenerationInterval ( 0 ),
t0 ( 0 ),
offset ( 0 ) {}

void OnAttributeChange( const Rocket::Core::AttributeNameList& changed_attributes )
{
HudElement::OnAttributeChange( changed_attributes );
if ( changed_attributes.find( "src" ) != changed_attributes.end() )
{
if ( maxBarbs > 0 )
{
Rocket::Core::String src = GetAttribute<Rocket::Core::String>( "src", "" );
Rocket::Core::String base( va("<img class='barbs' src='%s' />", src.CString() ) );
Rocket::Core::String rml;

for ( int i = 0; i < maxBarbs; i++ )
{
rml += base;
}
SetInnerRML( rml );
}
else
{
SetInnerRML( "" );
}
}
}

void DoOnUpdate()
{
int newNumBarbs = cg.snap->ps.ammo;
int interval = BG_GetBarbRegenerationInterval( cg.snap->ps );

if ( newNumBarbs < maxBarbs )
{
// start regenerating barb now
if ( newNumBarbs > numBarbs || ( newNumBarbs < numBarbs && numBarbs == maxBarbs ) )
{
t0 = cg.time;
// sin(-pi/2) is minimal
offset = -M_PI_2;
}
// change regeneration speed
else if ( interval != regenerationInterval )
{
float sinOld = GetSin();
float cosOld = GetCos();

// avoid sudden jumps in opacity
t0 = cg.time;
if ( cosOld >= 0.0 )
{
offset = asin( sinOld );
}
else
{
offset = M_PI - asin( sinOld );
}
regenerationInterval = interval;

assert( fabs(GetSin() - sinOld ) < 0.001);
assert( GetCos() * cosOld > 0 );
}
}
numBarbs = newNumBarbs;

for ( int i = 0; i < GetNumChildren(); i++ )
{
Element *barb = GetChild(i);
if (i < numBarbs ) // draw existing barbs
{
barb->SetProperty( "opacity", "1.0" );
barb->SetProperty( "color", "white" );
}
else if (i == numBarbs ) // draw regenerating barb
{
float opacity = GetSin() / 3 + 0.5;
barb->SetProperty( "opacity", va( "%f", opacity ) );
barb->SetProperty( "color", "grey" );
}
else // hide remaining (nonexistent) barbs
{
barb->SetProperty( "opacity", "0.0" );
}
}
}

private:

float GetSin()
{
return sin( GetParam() );
}

float GetCos()
{
return cos( GetParam() );
}

float GetParam()
{
float t = (cg.time - t0) / 1000.0;
// frequency in Hz; Interval is in ms
float f = 4 * 1000.0 / regenerationInterval;
return offset + t * 2 * M_PI * f;
}

int numBarbs;
int maxBarbs;
int regenerationInterval;

// t0 and offset are used to make sure that there are no sudden jumps in opacity.
int t0;
float offset;
};

void CG_Rocket_DrawPlayerHealth()
{
static int lastHealth = 0;
@@ -2277,28 +2400,6 @@ void CG_Rocket_DrawPlayerHealthCross()

}

void CG_Rocket_DrawAlienBarbs()
{
int numBarbs = cg.snap->ps.ammo;
char base[ MAX_STRING_CHARS ];
char rml[ MAX_STRING_CHARS ] = { 0 };

if ( !numBarbs )
{
Rocket_SetInnerRML( "", 0 );
return;
}

Com_sprintf( base, sizeof( base ), "<img class='barbs' src='%s' />", CG_Rocket_GetAttribute( "src" ) );

for ( ; numBarbs > 0; numBarbs-- )
{
Q_strcat( rml, sizeof( rml ), base );
}

Rocket_SetInnerRML( rml, 0 );
}

/*
============
CG_DrawStack
@@ -3441,7 +3542,6 @@ typedef struct
static const elementRenderCmd_t elementRenderCmdList[] =
{
{ "ammo_stack", &CG_DrawPlayerAmmoStack, ELEMENT_HUMANS },
{ "barbs", &CG_Rocket_DrawAlienBarbs, ELEMENT_ALIENS },
{ "chattype", &CG_Rocket_DrawChatType, ELEMENT_ALL },
{ "clip_stack", &CG_DrawPlayerClipsStack, ELEMENT_HUMANS },
{ "clock", &CG_Rocket_DrawClock, ELEMENT_ALL },
@@ -3534,4 +3634,5 @@ void CG_Rocket_RegisterElements()
REGISTER_ELEMENT( "beacon_name", BeaconNameElement )
REGISTER_ELEMENT( "beacon_owner", BeaconOwnerElement )
REGISTER_ELEMENT( "predictedMineEfficiency", PredictedMineEfficiencyElement )
REGISTER_ELEMENT( "barbs", BarbsHudElement )
}
@@ -1049,14 +1049,18 @@ void ClientTimerActions( gentity_t *ent, int msec )
{
if ( client->ps.ammo < BG_Weapon( WP_ALEVEL3_UPG )->maxAmmo )
{
if ( ent->timestamp + LEVEL3_BOUNCEBALL_REGEN < level.time )
float interval = BG_GetBarbRegenerationInterval(ent->client->ps);
ent->barbRegeneration += ( level.time - ent->timestamp ) / interval;
if ( ent->barbRegeneration >= 1 )
{
ent->barbRegeneration -= 1;
client->ps.ammo++;
ent->timestamp = level.time;
}
ent->timestamp = level.time;
}
else
{
ent->barbRegeneration = 0;
ent->timestamp = level.time;
}
}
@@ -1593,7 +1597,7 @@ static int FindAlienHealthSource( gentity_t *self )
{
int ret = 0, closeTeammates = 0;
float distance, minBoosterDistance = FLT_MAX;
bool needsHealing;
bool needsHealing;
gentity_t *ent;

if ( !self || !self->client )
@@ -348,6 +348,7 @@ struct gentity_s
int healthSourceTime; // last time an alien had contact to a health source
int animTime; // last animation change
int time1000; // timer evaluated every second
float barbRegeneration; // goon barb regeneration is complete if this value is >= 1

bool deconMarkHack; // TODO: Remove.
int attackTimer, attackLastEvent; // self being attacked
@@ -91,6 +91,8 @@ extern int LEVEL3_BOUNCEBALL_DMG;
extern float LEVEL3_BOUNCEBALL_SPEED;
extern int LEVEL3_BOUNCEBALL_RADIUS;
extern int LEVEL3_BOUNCEBALL_REGEN;
extern int LEVEL3_BOUNCEBALL_REGEN_BOOSTER;
extern int LEVEL3_BOUNCEBALL_REGEN_CREEP;

extern int LEVEL4_CLAW_DMG;
extern float LEVEL4_CLAW_RANGE;
@@ -481,6 +481,29 @@ bool BG_AlienCanEvolve( int from, int credits )
return false;
}

/*
===============
BG_GetBarbRegenerationInterval
===============
*/
int BG_GetBarbRegenerationInterval(const playerState_t& ps)
{
if ( ps.stats[ STAT_STATE ] & SS_HEALING_8X )
{
// regeneration interval near booster
return LEVEL3_BOUNCEBALL_REGEN_BOOSTER;
}
else if ( ps.stats[ STAT_STATE ] & SS_HEALING_4X )
{
// regeneration interval on creep
return LEVEL3_BOUNCEBALL_REGEN_CREEP;
}
else
{
return LEVEL3_BOUNCEBALL_REGEN;
}
}

/*
===============
BG_InitClassAttributes
@@ -110,6 +110,8 @@ int LEVEL3_BOUNCEBALL_DMG;
float LEVEL3_BOUNCEBALL_SPEED;
int LEVEL3_BOUNCEBALL_RADIUS;
int LEVEL3_BOUNCEBALL_REGEN;
int LEVEL3_BOUNCEBALL_REGEN_BOOSTER;
int LEVEL3_BOUNCEBALL_REGEN_CREEP;

int LEVEL4_CLAW_DMG;
float LEVEL4_CLAW_RANGE;
@@ -271,6 +273,8 @@ static configVar_t bg_configVars[] =
{"w_level3upg_ballDmg", INTEGER, false, &LEVEL3_BOUNCEBALL_DMG},
{"w_level3upg_ballRadius", INTEGER, false, &LEVEL3_BOUNCEBALL_RADIUS},
{"w_level3upg_ballRegen", INTEGER, false, &LEVEL3_BOUNCEBALL_REGEN},
{"w_level3upg_ballRegenBooster", INTEGER, false, &LEVEL3_BOUNCEBALL_REGEN_BOOSTER},
{"w_level3upg_ballRegenCreep", INTEGER, false, &LEVEL3_BOUNCEBALL_REGEN_CREEP},
{"w_level3upg_ballSpeed", FLOAT, false, &LEVEL3_BOUNCEBALL_SPEED},
{"w_level3upg_clawRange", FLOAT, false, &LEVEL3_CLAW_UPG_RANGE},
{"w_level3upg_pounceDuration", INTEGER, false, &LEVEL3_POUNCE_TIME_UPG},
@@ -1402,6 +1402,8 @@ bool BG_ClassHasAbility( int pClass, int ability );
int BG_ClassCanEvolveFromTo(int from, int to, int credits);
bool BG_AlienCanEvolve(int from, int credits);

int BG_GetBarbRegenerationInterval(const playerState_t& ps);

weapon_t BG_WeaponNumberByName( const char *name );
const weaponAttributes_t *BG_WeaponByName( const char *name );
const weaponAttributes_t *BG_Weapon( int weapon );

0 comments on commit 3837d11

Please sign in to comment.