Example #1
0
void drawBlobHealthShieldInfo()
{
	float healthPercent;
	float healthBar, shieldBar, oxygenBar;
	int fade;
	int y, bossX;
	String s;
	GLColor c;
	Texture *t;
	
	static GLColor darkRed = GLColor::red.darker();
	static GLColor darkYellow = GLColor::yellow.darker();
	static GLColor darkCyan = GLColor::cyan.darker();
	static GLColor darkGreen = GLColor::green.darker();
	
	y = 20;
	
	bool flashBar = ((((int)graphics->getAnimTimer()) % 100) < 50);
	bool showDanger;
	
	for (Unit *unit = (Unit*)entityManager->blobList.getFirstElement() ; unit != NULL ; unit = (Unit*)unit->next)
	{
		if ((unit->health <= -100) || (unit->definition->type == BLOB_MIA) || (!unit->showHealthData))
		{
			continue;
		}
		
		switch (unit->definition->type)
		{
			case BLOB_MIA:
			case BLOB_ASSIMILATING:
			case BLOB_SOLDIER:
				continue;
				break;
					
			default:
				break;
		}
		
		showDanger = false;
		
		fade = 35;
		
		if (unit->maxShield > 0)
		{
			fade = 40;
		}
		
		if (unit->oxygen < MAX_OXYGEN_IND)
		{
			fade = 45;
		}
		
		graphics->fade(0.5, 30, y - 5, 210, fade);
		
		s.setText("str_%s", unit->getName());
		
		if ((t = textureManager->getTexture(s.getText())) == NULL)
		{
			t = graphics->getGLString("%s", unit->getName());
			textureManager->addTexture(s.getText(), t);
		}
		
		glColor3f(1.0, 1.0, 1.0);
		graphics->blit(t, 35, y, false);
		
		healthPercent = unit->getHealthPercent();
		
		healthBar = 200;
		shieldBar = 200;
		oxygenBar = 200;
		
		healthBar /= unit->maxHealth;
		shieldBar /= unit->maxShield;
		oxygenBar /= MAX_OXYGEN;
		
		healthBar *= unit->health;
		shieldBar *= unit->shield;
		oxygenBar *= unit->oxygen;
		
		y += 16;
		
		if (healthPercent >= 75)
		{
			c = darkGreen;
		}
		else if (healthPercent >= 25)
		{
			c = darkYellow;
		}
		else
		{
			c = darkRed;
		}
		
		graphics->drawRect(35, y, 200, 8, c, true);
		
		if (unit == player)
		{
			glColor4f(1.0, 1.0, 1.0, (!game->autoLockTarget) ? 1.0 : 0.15);
			graphics->blit(textureManager->getTexture("textures/game/noTarget.png"), 120, y - 18, false);
		}
		else
		{
			glColor4f(1.0, 1.0, 1.0, 1.0);
		
			if (unit->currentCrumb != NULL)
			{
				graphics->blit(textureManager->getTexture("gfx/game/crumbFollowing.png"), 120, y - 18, false);
			}
		
			if (unit->crumbLost)
			{
				graphics->blit(textureManager->getTexture("gfx/game/crumbLost.png"), 136, y - 18, false);
			}
		}
		
		if ((unit->health > 0) && (healthPercent < 25))
		{
			if (flashBar)
			{
				graphics->drawRect(35, y, (int)healthBar, 8, c, true);
			}
			
			showDanger = true;
		}
		else if (unit->health > 0)
		{
			graphics->drawRect(35, y, (int)healthBar, 8, c, true);
		}
		
		if ((unit->flags & EF_WRAPPED) || (unit->flags & EF_ONFIRE) || (unit->flags & EF_FROZEN))
		{
			showDanger = true;
		}
		
		if (showDanger)
		{
			glColor4f(1.0, 1.0, 1.0, (flashBar) ? 1.0 : 0.5);
			graphics->blit(textureManager->getTexture("textures/game/danger.png"), 185, y - 18, false);
		}
		
		y += 10;
		
		if (unit->maxShield > 0)
		{
			graphics->drawRect(35, y, 200, 4, darkCyan, true);
			
			if (unit->shield > 0)
			{
				graphics->drawRect(35, y, (int)shieldBar, 4, GLColor::cyan, true);
			}
		}
		
		y += 6;
		
		if (unit->oxygen < MAX_OXYGEN)
		{
			graphics->drawRect(35, y, 200, 4, darkYellow, true);
			
			if (unit->oxygen > 0)
			{
				graphics->drawRect(35, y, (int)oxygenBar, 4, GLColor::yellow, true);
			}
		}
		else if (unit->oxygen != MAX_OXYGEN_IND)
		{
			graphics->drawRect(35, y, 200, 4, GLColor::yellow, true);
		}
		
		if ((unit != player) && (unit->flags & EF_VANISHED))
		{
			graphics->fade(0.75, 30, y - 37, 210, fade);
		}
		
		y += 20;
	}
	
	y = 20;
	
	for (Boss *boss = (Boss*)entityManager->bossList.getFirstElement() ; boss != NULL ; boss = (Boss*)boss->next)
	{
		if ((boss->health <= 0) || (!boss->showHealthData))
		{
			continue;
		}
		
		bossX = graphics->screen->w - 240;
		
		graphics->fade(0.5, bossX, y - 5, 210, 40);
		
		s.setText("str_%s", boss->getName());
		
		if ((t = textureManager->getTexture(s.getText())) == NULL)
		{
			t = graphics->getGLString("%s", boss->getName());
			textureManager->addTexture(s.getText(), t);
		}
		
		glColor3f(1.0, 1.0, 1.0);
		graphics->blit(t, bossX + 5, y, false);
		
		healthPercent = boss->getHealthPercent();
		
		healthBar = 200;
		shieldBar = 200;
		
		healthBar /= boss->maxHealth;
		shieldBar /= boss->maxShield;
		
		healthBar *= boss->health;
		shieldBar *= boss->shield;
		
		y += 16;
		
		if (healthPercent >= 75)
		{
			c = darkGreen;
		}
		else if (healthPercent >= 25)
		{
			c = darkYellow;
		}
		else
		{
			c = darkRed;
		}
		
		graphics->drawRect(bossX + 5, y, 200, 8, c, true);
		
		if (boss->health > 0)
		{
			graphics->drawRect(bossX + 5, y, (int)healthBar, 8, c, true);
		}
		
		y += 10;
		
		if (boss->maxShield > 0)
		{
			graphics->drawRect(bossX + 5, y, 200, 4, darkCyan, true);
			
			if (boss->shield > 0)
			{
				graphics->drawRect(bossX + 5, y, (int)shieldBar, 4, GLColor::cyan, true);
			}
		}
		
		y += 26;
	}
}
Example #2
0
void doExplosion(Vector position, int size, Entity *owner)
{
	audio->playSound(SND_GRENADE_EXPLODE, CH_EXPLODE, camera->getSoundDistance(position));
	
	addExplosionParticles(size, position);
	addExplosionMark(position, size * 2);
	
	if (game->cutsceneType != CUTSCENE_NONE)
	{
		return;
	}
	
	float distance;
	
	for (Unit *unit = (Unit*)entityManager->enemyList.getFirstElement() ; unit != NULL ; unit = (Unit*)unit->next)
	{
		if (!unit->canBeDamaged())
		{
			continue;
		}
		
		distance = Math::getDistance(unit->position, position);
		
		if (distance > (size * 4))
		{
			continue;
		}
		
		explosionHarmUnit(unit, size, (int)distance, position, owner);
	}
	
	for (Unit *unit = (Unit*)entityManager->blobList.getFirstElement() ; unit != NULL ; unit = (Unit*)unit->next)
	{
		if (!unit->canBeDamaged())
		{
			continue;
		}
		
		distance = Math::getDistance(unit->position, position);
		
		if (distance > (size * 4))
		{
			continue;
		}
		
		explosionHarmUnit(unit, size, (int)distance, position, owner);
	}
	
	float damage;
	
	for (Entity *entity = (Entity*)entityManager->structureList.getFirstElement() ; entity != NULL ; entity = (Entity*)entity->next)
	{
		if (!(entity->flags & EF_IMMORTAL))
		{
			distance = Math::getDistance(entity->position, position);
			
			damage = (size * 4);
			
			if (distance > (size * 4))
			{
				continue;
			}
			
			if (distance > (damage / 10))
			{
				for (int i = (size * 4) ; i < distance ; i++)
				{
					damage *= 0.95;
				}
			}
			
			if (damage < 1)
			{
				continue;
			}
			
			entity->health -= damage;
			
			debug(("Structure (%s) took %.2f damage from explosion\n", (entity->name != "" ? entity->getName() : "unnamed"), damage));
		}
	}
	
	Entity *oldSelf;
	
	for (Boss *boss = (Boss*)entityManager->bossList.getFirstElement() ; boss != NULL ; boss = (Boss*)boss->next)
	{
		if (boss == owner)
		{
			continue;
		}
		
		if (boss->flags & (EF_IMMORTAL|EF_VANISHED))
		{
			continue;
		}
		
		distance = Math::getDistance(boss->position, position);
		
		damage = (size * 4);
		
		if (distance > (size * 4))
		{
			continue;
		}
		
		if (distance > (damage / 10))
		{
			for (int i = (size * 4) ; i < distance ; i++)
			{
				damage *= 0.95;
			}
		}
		
		if (damage < 1)
		{
			continue;
		}
		
		oldSelf = self;
		self = boss;
		boss->reactToDamage(owner, damage);
		self = oldSelf;
		
		debug(("%s took %.2f damage from explosion\n", boss->getName(), damage));
	}
}